1VI(1P)                     POSIX Programmer's Manual                    VI(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       vi — screen-oriented (visual) display editor
13

SYNOPSIS

15       vi [-rR] [-c command] [-t tagstring] [-w size] [file...]
16

DESCRIPTION

18       This utility shall be provided on systems that both  support  the  User
19       Portability  Utilities  option  and define the POSIX2_CHAR_TERM symbol.
20       On other systems it is optional.
21
22       The vi (visual) utility is a screen-oriented text editor. Only the open
23       and  visual  modes of the editor are described in POSIX.1‐2008; see the
24       line editor ex for additional editing capabilities  used  in  vi.   The
25       user  can  switch  back and forth between vi and ex and execute ex com‐
26       mands from within vi.
27
28       This reference page uses the term edit buffer to describe  the  current
29       working  text.  No specific implementation is implied by this term. All
30       editing changes are performed on the edit buffer, and no changes to  it
31       shall affect any file until an editor command writes the file.
32
33       When  using  vi,  the terminal screen acts as a window into the editing
34       buffer. Changes made to the editing buffer shall be  reflected  in  the
35       screen display; the position of the cursor on the screen shall indicate
36       the position within the editing buffer.
37
38       Certain terminals do not have all the capabilities necessary to support
39       the  complete vi definition. When these commands cannot be supported on
40       such terminals, this condition shall not produce an error message  such
41       as  ``not an editor command'' or report a syntax error. The implementa‐
42       tion may either accept the commands and produce results on  the  screen
43       that are the result of an unsuccessful attempt to meet the requirements
44       of this volume of POSIX.1‐2017 or report an error describing the termi‐
45       nal-related deficiency.
46

OPTIONS

48       The  vi  utility  shall  conform  to  the  Base  Definitions  volume of
49       POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines, except that  '+'
50       may be recognized as an option delimiter as well as '-'.
51
52       The following options shall be supported:
53
54       -c command
55                 See the ex command description of the -c option.
56
57       -r        See the ex command description of the -r option.
58
59       -R        See the ex command description of the -R option.
60
61       -t tagstring
62                 See the ex command description of the -t option.
63
64       -w size   See the ex command description of the -w option.
65

OPERANDS

67       See the OPERANDS section of the ex command for a description of the op‐
68       erands supported by the vi command.
69

STDIN

71       If standard input is not a terminal device, the results are  undefined.
72       The  standard input consists of a series of commands and input text, as
73       described in the EXTENDED DESCRIPTION section.
74
75       If a read from the standard input returns an error, or  if  the  editor
76       detects  an  end-of-file condition from the standard input, it shall be
77       equivalent to a SIGHUP asynchronous event.
78

INPUT FILES

80       See the INPUT FILES section of the ex command for a description of  the
81       input files supported by the vi command.
82

ENVIRONMENT VARIABLES

84       See  the  ENVIRONMENT VARIABLES section of the ex command for the envi‐
85       ronment variables that affect the execution of the vi command.
86

ASYNCHRONOUS EVENTS

88       See the ASYNCHRONOUS EVENTS section of  the  ex  for  the  asynchronous
89       events that affect the execution of the vi command.
90

STDOUT

92       If standard output is not a terminal device, undefined results occur.
93
94       Standard output may be used for writing prompts to the user, for infor‐
95       mational messages, and for writing lines from the file.
96

STDERR

98       If standard output is not a terminal device, undefined results occur.
99
100       The standard error shall be used only for diagnostic messages.
101

OUTPUT FILES

103       See the OUTPUT FILES section of the ex command for a description of the
104       output files supported by the vi command.
105

EXTENDED DESCRIPTION

107       If  the terminal does not have the capabilities necessary to support an
108       unspecified portion of the vi definition, implementations  shall  start
109       initially  in ex mode or open mode. Otherwise, after initialization, vi
110       shall be in command mode; text input mode can be entered by one of sev‐
111       eral  commands used to insert or change text. In text input mode, <ESC>
112       can be used to  return  to  command  mode;  other  uses  of  <ESC>  are
113       described later in this section; see Terminate Command or Input Mode.
114
115   Initialization in ex and vi
116       See Initialization in ex and vi for a description of ex and vi initial‐
117       ization for the vi utility.
118
119   Command Descriptions in vi
120       The following symbols are used in  this  reference  page  to  represent
121       arguments to commands.
122
123       buffer  See  the description of buffer in the EXTENDED DESCRIPTION sec‐
124               tion of the ex utility; see Command Descriptions in ex.
125
126               In open and visual mode, when a  command  synopsis  shows  both
127               [buffer]  and  [count]  preceding the command name, they can be
128               specified in either order.
129
130       count   A positive integer used as an optional argument  to  most  com‐
131               mands,  either  to give a repeat count or as a size. This argu‐
132               ment is optional and shall default to 1 unless otherwise speci‐
133               fied.
134
135               The  Synopsis  lines  for  the  vi  commands <control>‐G, <con‐
136               trol>‐L, <control>‐R, <control>‐], %, &, ^, D, m, M, Q,  u,  U,
137               and  ZZ  do not have count as an optional argument. Regardless,
138               it shall not be an error to specify a count to these  commands,
139               and any specified count shall be ignored.
140
141       motion  An  optional trailing argument used by the !, <, >, c, d, and y
142               commands, which is used to indicate the  region  of  text  that
143               shall  be affected by the command. The motion can be either one
144               of the command characters repeated or one of several  other  vi
145               commands  (listed in the following table). Each of the applica‐
146               ble commands specifies the region of text matched by  repeating
147               the  command; each command that can be used as a motion command
148               specifies the region of text it affects.
149
150               Commands that take motion arguments operate on either lines  or
151               characters,  depending  on the circumstances. When operating on
152               lines, all lines that fall partially or wholly within the  text
153               region  specified for the command shall be affected. When oper‐
154               ating on characters, only the exact characters in the specified
155               text  region  shall  be affected. Each motion command specifies
156               this individually.
157
158               When commands that may be  motion  commands  are  not  used  as
159               motion  commands,  they  shall  set the current position to the
160               current line and column as specified.
161
162               The following commands shall be valid cursor motion commands:
163
164
165                   <apostrophe>       (    -    j    H
166                   <carriage-return>  )    $    k    L
167                   <comma>            [[   %    l    M
168                   <control>-H        ]]   _    n    N
169                   <control>-N        {    ;    t    T
170                   <control>-P        }    ?    w    W
171                   <grave-accent>     ^    b    B
172                   <newline>          +    e    E
173                   <space>            |    f    F
174                   <zero>             /    h    G
175
176               Any count that is specified to a command that has an associated
177               motion  command  shall  be  applied to the motion command. If a
178               count is applied to both the command and its associated  motion
179               command, the effect shall be multiplicative.
180
181       The  following symbols are used in this section to specify locations in
182       the edit buffer:
183
184       current character
185               The character that is currently indicated by the cursor.
186
187       end of a line
188               The point located between the last non-<newline> (if  any)  and
189               the  terminating  <newline>  of a line. For an empty line, this
190               location coincides with the beginning of the line.
191
192       end of the edit buffer
193               The location corresponding to the end of the last line  in  the
194               edit buffer.
195
196       The  following  symbols  are  used  in  this section to specify command
197       actions:
198
199       bigword In the POSIX locale, vi shall recognize four kinds of bigwords:
200
201                1. A maximal sequence of non-<blank> characters  preceded  and
202                   followed by <blank> characters or the beginning or end of a
203                   line or the edit buffer
204
205                2. One or more sequential blank lines
206
207                3. The first character in the edit buffer
208
209                4. The last non-<newline> in the edit buffer
210
211       word    In the POSIX locale, vi shall recognize five kinds of words:
212
213                1. A maximal sequence of  letters,  digits,  and  underscores,
214                   delimited at both ends by:
215
216                   --  Characters other than letters, digits, or underscores
217
218                   --  The beginning or end of a line
219
220                   --  The beginning or end of the edit buffer
221
222                2. A  maximal  sequence of characters other than letters, dig‐
223                   its, underscores, or <blank> characters, delimited at  both
224                   ends by:
225
226                   --  A letter, digit, underscore
227
228                   --  <blank> characters
229
230                   --  The beginning or end of a line
231
232                   --  The beginning or end of the edit buffer
233
234                3. One or more sequential blank lines
235
236                4. The first character in the edit buffer
237
238                5. The last non-<newline> in the edit buffer
239
240       section boundary
241               A section boundary is one of the following:
242
243                1. A line whose first character is a <form-feed>
244
245                2. A line whose first character is an open curly brace ('{')
246
247                3. A line whose first character is a <period> and whose second
248                   and third characters match a two-character pair in the sec‐
249                   tions edit option (see ex)
250
251                4. A  line  whose first character is a <period> and whose only
252                   other character matches the first character of a  two-char‐
253                   acter  pair  in  the sections edit option, where the second
254                   character of the two-character pair is a <space>
255
256                5. The first line of the edit buffer
257
258                6. The last line of the edit buffer if the last  line  of  the
259                   edit  buffer is empty or if it is a ]] or } command; other‐
260                   wise, the last non-<newline> of the last line of  the  edit
261                   buffer
262
263       paragraph boundary
264               A paragraph boundary is one of the following:
265
266                1. A section boundary
267
268                2. A line whose first character is a <period> and whose second
269                   and third characters match  a  two-character  pair  in  the
270                   paragraphs edit option (see ex)
271
272                3. A  line  whose first character is a <period> and whose only
273                   other character matches the first character of a  two-char‐
274                   acter  pair in the paragraphs edit option, where the second
275                   character of the two-character pair is a <space>
276
277                4. One or more sequential blank lines
278
279       remembered search direction
280               See the description of remembered search direction in ex.
281
282       sentence boundary
283               A sentence boundary is one of the following:
284
285                1. A paragraph boundary
286
287                2. The first non-<blank> that occurs after a paragraph  bound‐
288                   ary
289
290                3. The  first  non-<blank> that occurs after a <period> ('.'),
291                   <exclamation-mark> ('!'), or  <question-mark>  ('?'),  fol‐
292                   lowed  by  two <space> characters or the end of a line; any
293                   number  of  closing  parenthesis  (')'),  closing  brackets
294                   (']'),  double-quote  ('"'), or single-quote (<apostrophe>)
295                   characters can appear between the punctuation mark and  the
296                   two <space> characters or end-of-line
297
298       In  the remainder of the description of the vi utility, the term ``buf‐
299       fer line'' refers to a line in the edit buffer and the  term  ``display
300       line''  refers  to the line or lines on the display screen used to dis‐
301       play one buffer line. The term ``current line'' refers  to  a  specific
302       ``buffer line''.
303
304       If  there are display lines on the screen for which there are no corre‐
305       sponding buffer lines because they correspond to lines  that  would  be
306       after  the end of the file, they shall be displayed as a single <tilde>
307       ('~') character, plus the terminating <newline>.
308
309       The last line of the screen shall be used to report errors  or  display
310       informational  messages. It shall also be used to display the input for
311       ``line-oriented commands'' (/, ?, :, and !).  When a line-oriented com‐
312       mand  is  executed,  the editor shall enter text input mode on the last
313       line on the screen, using the respective command characters  as  prompt
314       characters. (In the case of the !  command, the associated motion shall
315       be entered by the user before the editor enters text input  mode.)  The
316       line  entered  by  the  user  shall  be  terminated  by  a <newline>, a
317       non-<control>‐V-escaped <carriage-return>, or unescaped <ESC>.   It  is
318       unspecified  if  more characters than require a display width minus one
319       column number of screen columns can be entered.
320
321       If any command is executed that overwrites  a  portion  of  the  screen
322       other  than the last line of the screen (for example, the ex suspend or
323       !  commands), other than the  ex  shell  command,  the  user  shall  be
324       prompted  for  a  character before the screen is refreshed and the edit
325       session continued.
326
327       <tab> characters shall take up the number of columns on the screen  set
328       by  the  tabstop  edit option (see ex), unless there are less than that
329       number of columns before the display margin that will  cause  the  dis‐
330       played  line  to  be  folded; in this case, they shall only take up the
331       number of columns up to that boundary.
332
333       The cursor shall be placed on the current line and relative to the cur‐
334       rent  column  as  specified  by each command described in the following
335       sections.
336
337       In open mode, if the current line is not  already  displayed,  then  it
338       shall be displayed.
339
340       In  visual  mode,  if the current line is not displayed, then the lines
341       that are displayed shall be expanded, scrolled, or redrawn to cause  an
342       unspecified  portion of the current line to be displayed. If the screen
343       is redrawn, no more than the number of display lines specified  by  the
344       value  of the window edit option shall be displayed (unless the current
345       line cannot be completely displayed in  the  number  of  display  lines
346       specified  by  the  window  edit  option) and the current line shall be
347       positioned as close to the center of the displayed  lines  as  possible
348       (within  the  constraints  imposed by the distance of the line from the
349       beginning or end of the edit buffer). If the current line is before the
350       first  line  in  the display and the screen is scrolled, an unspecified
351       portion of the current line shall be placed on the first  line  of  the
352       display.  If the current line is after the last line in the display and
353       the screen is scrolled, an unspecified  portion  of  the  current  line
354       shall be placed on the last line of the display.
355
356       In  visual mode, if a line from the edit buffer (other than the current
357       line) does not entirely fit into the lines at the bottom of the display
358       that  are  available for its presentation, the editor may choose not to
359       display any portion of the line. The lines of the display that  do  not
360       contain text from the edit buffer for this reason shall each consist of
361       a single '@' character.
362
363       In visual mode, the editor may choose for unspecified  reasons  to  not
364       update lines in the display to correspond to the underlying edit buffer
365       text. The lines of the display that do not correctly correspond to text
366       from  the  edit  buffer  for  this reason shall consist of a single '@'
367       character (plus the terminating <newline>), and the <control>‐R command
368       shall  cause the editor to update the screen to correctly represent the
369       edit buffer.
370
371       Open and visual mode commands that set the current column set it  to  a
372       column  position  in  the  display, and not a character position in the
373       line. In this case, however, the column position in the  display  shall
374       be  calculated  for  an infinite width display; for example, the column
375       related to a character that is part of a line that has been folded onto
376       additional  screen  lines  will  be offset from the display line column
377       where the buffer line begins, not from the beginning  of  a  particular
378       display line.
379
380       The  display  cursor column in the display is based on the value of the
381       current column, as follows, with each rule applied in turn:
382
383        1. If the current column is after the last display line column used by
384           the  displayed  line, the display cursor column shall be set to the
385           last display line column occupied by the last non-<newline> in  the
386           current  line; otherwise, the display cursor column shall be set to
387           the current column.
388
389        2. If the character of which some portion is displayed in the  display
390           line  column  specified  by the display cursor column requires more
391           than a single display line column:
392
393            a. If in text input mode,  the  display  cursor  column  shall  be
394               adjusted  to the first display line column in which any portion
395               of that character is displayed.
396
397            b. Otherwise, the display cursor column shall be adjusted  to  the
398               last display line column in which any portion of that character
399               is displayed.
400
401       The current column shall not be changed by  these  adjustments  to  the
402       display cursor column.
403
404       If an error occurs during the parsing or execution of a vi command:
405
406        *  The  terminal  shall  be alerted. Execution of the vi command shall
407           stop, and the cursor (for example, the  current  line  and  column)
408           shall not be further modified.
409
410        *  Unless otherwise specified by the following command sections, it is
411           unspecified whether an informational message shall be displayed.
412
413        *  Any partially entered vi command shall be discarded.
414
415        *  If the vi command resulted from a  map  expansion,  all  characters
416           from  that  map  expansion  shall be discarded, except as otherwise
417           specified by the map command (see ex).
418
419        *  If the vi command resulted from the execution of a buffer, no  fur‐
420           ther  commands  caused by the execution of the buffer shall be exe‐
421           cuted.
422
423   Page Backwards
424       Synopsis:
425
426                     [count] <control>-B
427
428       If in open mode, the <control>‐B command shall  behave  identically  to
429       the  z command. Otherwise, if the current line is the first line of the
430       edit buffer, it shall be an error.
431
432       If the window edit option is less than 3, display a  screen  where  the
433       last line of the display shall be some portion of:
434
435
436           (current first line) -1
437
438       otherwise,  display  a screen where the first line of the display shall
439       be some portion of:
440
441
442           (current first line) - count x ((window edit option) -2)
443
444       If this calculation would result in a line that  is  before  the  first
445       line  of  the  edit buffer, the first line of the display shall display
446       some portion of the first line of the edit buffer.
447
448       Current line: If no lines from  the  previous  display  remain  on  the
449       screen,  set to the last line of the display; otherwise, set to (line -
450       the number of new lines displayed on this screen).
451
452       Current column: Set to non-<blank>.
453
454   Scroll Forward
455       Synopsis:
456
457                     [count] <control>-D
458
459       If the current line is the last line of the edit buffer, it shall be an
460       error.
461
462       If  no  count is specified, count shall default to the count associated
463       with the previous <control>‐D or <control>‐U command. If there  was  no
464       previous <control>‐D or <control>‐U command, count shall default to the
465       value of the scroll edit option.
466
467       If in open mode, write lines starting with the line after  the  current
468       line, until count lines or the last line of the file have been written.
469
470       Current  line: If the current line + count is past the last line of the
471       edit buffer, set to the last line of the edit buffer; otherwise, set to
472       the current line + count.
473
474       Current column: Set to non-<blank>.
475
476   Scroll Forward by Line
477       Synopsis:
478
479                     [count] <control>-E
480
481       Display the line count lines after the last line currently displayed.
482
483       If the last line of the edit buffer is displayed, it shall be an error.
484       If there is no line count lines after  the  last  line  currently  dis‐
485       played,  the last line of the display shall display some portion of the
486       last line of the edit buffer.
487
488       Current line: Unchanged if the previous current character is displayed;
489       otherwise, set to the first line displayed.
490
491       Current column: Unchanged.
492
493   Page Forward
494       Synopsis:
495
496                     [count] <control>-F
497
498       If  in  open  mode, the <control>‐F command shall behave identically to
499       the z command. Otherwise, if the current line is the last line  of  the
500       edit buffer, it shall be an error.
501
502       If  the  window  edit option is less than 3, display a screen where the
503       first line of the display shall be some portion of:
504
505
506           (current last line) +1
507
508       otherwise, display a screen where the first line of the  display  shall
509       be some portion of:
510
511
512           (current first line) + count x ((window edit option) -2)
513
514       If  this calculation would result in a line that is after the last line
515       of the edit buffer, the last line of the  display  shall  display  some
516       portion of the last line of the edit buffer.
517
518       Current  line:  If  no  lines  from  the previous display remain on the
519       screen, set to the first line of the display; otherwise, set to (line +
520       the number of new lines displayed on this screen).
521
522       Current column: Set to non-<blank>.
523
524   Display Information
525       Synopsis:
526
527                     <control>-G
528
529       This command shall be equivalent to the ex file command.
530
531   Move Cursor Backwards
532       Synopsis:
533
534                     [count] <control>-H
535                     [count] h
536                     the current erase character (see stty)
537
538       If  there are no characters before the current character on the current
539       line, it shall be an error. If there are less than count previous char‐
540       acters  on  the  current line, count shall be adjusted to the number of
541       previous characters on the line.
542
543       If used as a motion command:
544
545        1. The text region shall be from the  character  before  the  starting
546           cursor  up to and including the countth character before the start‐
547           ing cursor.
548
549        2. Any text copied to a buffer shall be in character mode.
550
551       If not used as a motion command:
552
553       Current line: Unchanged.
554
555       Current column: Set to (column - the  number  of  columns  occupied  by
556       count characters ending with the previous current column).
557
558   Move Down
559       Synopsis:
560
561                     [count] <newline>
562                     [count] <control>-J
563                     [count] <control>-M
564                     [count] <control>-N
565                     [count] j
566                     [count] <carriage-return>
567                     [count] +
568
569       If  there  are less than count lines after the current line in the edit
570       buffer, it shall be an error.
571
572       If used as a motion command:
573
574        1. The text region shall include the starting line and the next  count
575           - 1 lines.
576
577        2. Any text copied to a buffer shall be in line mode.
578
579       If not used as a motion command:
580
581       Current line: Set to current line+ count.
582
583       Current  column:  Set  to  non-<blank> for the <carriage-return>, <con‐
584       trol>‐M, and + commands; otherwise, unchanged.
585
586   Clear and Redisplay
587       Synopsis:
588
589                     <control>-L
590
591       If in open mode, clear the screen and redisplay the current line.  Oth‐
592       erwise, clear and redisplay the screen.
593
594       Current line: Unchanged.
595
596       Current column: Unchanged.
597
598   Move Up
599       Synopsis:
600
601                     [count] <control>-P
602                     [count] k
603                     [count] -
604
605       If  there are less than count lines before the current line in the edit
606       buffer, it shall be an error.
607
608       If used as a motion command:
609
610        1. The text region shall include the starting line  and  the  previous
611           count lines.
612
613        2. Any text copied to a buffer shall be in line mode.
614
615       If not used as a motion command:
616
617       Current line: Set to current line - count.
618
619       Current  column:  Set  to  non-<blank>  for  the  - command; otherwise,
620       unchanged.
621
622   Redraw Screen
623       Synopsis:
624
625                     <control>-R
626
627       If any lines have been deleted from the display screen and  flagged  as
628       deleted  on  the  terminal using the @ convention (see the beginning of
629       the EXTENDED DESCRIPTION section), they shall be redisplayed  to  match
630       the contents of the edit buffer.
631
632       It  is unspecified whether lines flagged with @ because they do not fit
633       on the terminal display shall be affected.
634
635       Current line: Unchanged.
636
637       Current column: Unchanged.
638
639   Scroll Backward
640       Synopsis:
641
642                     [count] <control>-U
643
644       If the current line is the first line of the edit buffer, it  shall  be
645       an error.
646
647       If  no  count is specified, count shall default to the count associated
648       with the previous <control>‐D or <control>‐U command. If there  was  no
649       previous <control>‐D or <control>‐U command, count shall default to the
650       value of the scroll edit option.
651
652       Current line: If count is greater than the current line, set to 1; oth‐
653       erwise, set to the current line - count.
654
655       Current column: Set to non-<blank>.
656
657   Scroll Backward by Line
658       Synopsis:
659
660                     [count] <control>-Y
661
662       Display the line count lines before the first line currently displayed.
663
664       If  the  current line is the first line of the edit buffer, it shall be
665       an error. If this calculation would result in a line that is before the
666       first line of the edit buffer, the first line of the display shall dis‐
667       play some portion of the first line of the edit buffer.
668
669       Current line: Unchanged if the previous current character is displayed;
670       otherwise, set to the first line displayed.
671
672       Current column: Unchanged.
673
674   Edit the Alternate File
675       Synopsis:
676
677                     <control>-^
678
679       This  command  shall  be  equivalent  to  the ex edit command, with the
680       alternate pathname as its argument.
681
682   Terminate Command or Input Mode
683       Synopsis:
684
685                     <ESC>
686
687       If a partial vi command (as defined by at least one, non-count  charac‐
688       ter) has been entered, discard the count and the command character(s).
689
690       Otherwise,  if  no  command characters have been entered, and the <ESC>
691       was the result of a map expansion, the terminal shall  be  alerted  and
692       the <ESC> character shall be discarded, but it shall not be an error.
693
694       Otherwise, it shall be an error.
695
696       Current line: Unchanged.
697
698       Current column: Unchanged.
699
700   Search for tagstring
701       Synopsis:
702
703                     <control>-]
704
705       If  the  current  character  is  not  a word or <blank>, it shall be an
706       error.
707
708       This command shall be equivalent to the ex tag command, with the  argu‐
709       ment to that command defined as follows.
710
711       If the current character is a <blank>:
712
713        1. Skip  all  <blank> characters after the cursor up to the end of the
714           line.
715
716        2. If the end of the line is reached, it shall be an error.
717
718       Then, the argument to the ex tag command shall be the current character
719       and  all  subsequent  characters, up to the first non-word character or
720       the end of the line.
721
722   Move Cursor Forward
723       Synopsis:
724
725                     [count] <space>
726                     [count] l  (ell)
727
728       If there are less than count non-<newline> characters after the  cursor
729       on the current line, count shall be adjusted to the number of non-<new‐
730       line> characters after the cursor on the line.
731
732       If used as a motion command:
733
734        1. If the current or countth character after the cursor  is  the  last
735           non-<newline>  in  the  line, the text region shall be comprised of
736           the current character up to and including the last non-<newline> in
737           the  line.  Otherwise,  the  text  region shall be from the current
738           character up to, but not including, the countth character after the
739           cursor.
740
741        2. Any text copied to a buffer shall be in character mode.
742
743       If not used as a motion command:
744
745       If there are no non-<newline> characters after the current character on
746       the current line, it shall be an error.
747
748       Current line: Unchanged.
749
750       Current column: Set to the last column that displays any portion of the
751       countth character after the current character.
752
753   Replace Text with Results from Shell Command
754       Synopsis:
755
756                     [count] ! motion shell-commands <newline>
757
758       If the motion command is the !  command repeated:
759
760        1. If  the edit buffer is empty and no count was supplied, the command
761           shall be the equivalent of the ex :read !  command, with  the  text
762           input, and no text shall be copied to any buffer.
763
764        2. Otherwise:
765
766            a. If there are less than count -1 lines after the current line in
767               the edit buffer, it shall be an error.
768
769            b. The text region shall be  from  the  current  line  up  to  and
770               including the next count -1 lines.
771
772       Otherwise, the text region shall be the lines in which any character of
773       the text region specified by the motion command appear.
774
775       Any text copied to a buffer shall be in line mode.
776
777       This command shall be equivalent to the ex !  command for the specified
778       lines.
779
780   Move Cursor to End-of-Line
781       Synopsis:
782
783                     [count] $
784
785       It  shall be an error if there are less than (count -1) lines after the
786       current line in the edit buffer.
787
788       If used as a motion command:
789
790        1. If count is 1:
791
792            a. It shall be an error if the line is empty.
793
794            b. Otherwise, the text region shall consist of all characters from
795               the  starting  cursor  to  the  last non-<newline> in the line,
796               inclusive, and any text copied to a buffer shall be in  charac‐
797               ter mode.
798
799        2. Otherwise,  if  the  starting  cursor  position is at or before the
800           first non-<blank> in the line, the text region shall consist of the
801           current and the next count -1 lines, and any text saved to a buffer
802           shall be in line mode.
803
804        3. Otherwise, the text region shall consist of all characters from the
805           starting cursor to the last non-<newline> in the line that is count
806           -1 lines forward from the current line, and any text  copied  to  a
807           buffer shall be in character mode.
808
809       If not used as a motion command:
810
811       Current line: Set to the current line + count-1.
812
813       Current column: The current column is set to the last display line col‐
814       umn of the last non-<newline> in the line, or column position 1 if  the
815       line is empty.
816
817       The  current  column  shall  be adjusted to be on the last display line
818       column of the last non-<newline> of the current line as subsequent com‐
819       mands change the current line, until a command changes the current col‐
820       umn.
821
822   Move to Matching Character
823       Synopsis:
824
825                     %
826
827       If the character at the current position is not a parenthesis, bracket,
828       or  curly  brace,  search forward in the line to the first one of those
829       characters. If no such character is found, it shall be an error.
830
831       The matching character shall be  the  parenthesis,  bracket,  or  curly
832       brace  matching the parenthesis, bracket, or curly brace, respectively,
833       that was at the current position or that was found on the current line.
834
835       Matching shall be determined as follows, for an open parenthesis:
836
837        1. Set a counter to 1.
838
839        2. Search forwards until a parenthesis is found or the end of the edit
840           buffer is reached.
841
842        3. If the end of the edit buffer is reached, it shall be an error.
843
844        4. If an open parenthesis is found, increment the counter by 1.
845
846        5. If a close parenthesis is found, decrement the counter by 1.
847
848        6. If the counter is zero, the current character is the matching char‐
849           acter.
850
851       Matching for a close parenthesis shall be equivalent, except  that  the
852       search shall be backwards, from the starting character to the beginning
853       of the buffer, a close parenthesis shall increment the  counter  by  1,
854       and an open parenthesis shall decrement the counter by 1.
855
856       Matching for brackets and curly braces shall be equivalent, except that
857       searching shall be done for open and close brackets or open  and  close
858       curly braces. It is implementation-defined whether other characters are
859       searched for and matched as well.
860
861       If used as a motion command:
862
863        1. If the matching cursor was after the starting cursor  in  the  edit
864           buffer, and the starting cursor position was at or before the first
865           non-<blank> non-<newline> in the starting line,  and  the  matching
866           cursor  position was at or after the last non-<blank> non-<newline>
867           in the matching line, the text region shall consist of the  current
868           line to the matching line, inclusive, and any text copied to a buf‐
869           fer shall be in line mode.
870
871        2. If the matching cursor was before the starting cursor in  the  edit
872           buffer,  and  the starting cursor position was at or after the last
873           non-<blank> non-<newline> in the starting line,  and  the  matching
874           cursor  position  was  at or before the first non-<blank> non-<new‐
875           line> in the matching line, the text region shall  consist  of  the
876           current  line  to the matching line, inclusive, and any text copied
877           to a buffer shall be in line mode.
878
879        3. Otherwise, the text region shall consist of the starting  character
880           to the matching character, inclusive, and any text copied to a buf‐
881           fer shall be in character mode.
882
883       If not used as a motion command:
884
885       Current line: Set to the line where the matching character is located.
886
887       Current column: Set to the last column where any portion of the  match‐
888       ing character is displayed.
889
890   Repeat Substitution
891       Synopsis:
892
893                     &
894
895       Repeat the previous substitution command. This command shall be equiva‐
896       lent to the ex & command with the current line as  its  addresses,  and
897       without options, count, or flags.
898
899   Return to Previous Context at Beginning of Line
900       Synopsis:
901
902                     ' character
903
904       It  shall  be an error if there is no line in the edit buffer marked by
905       character.
906
907       If used as a motion command:
908
909        1. If the starting cursor is after the marked cursor, then  the  loca‐
910           tions of the starting cursor and the marked cursor in the edit buf‐
911           fer shall be logically swapped.
912
913        2. The text region shall consist  of  the  starting  line  up  to  and
914           including the marked line, and any text copied to a buffer shall be
915           in line mode.
916
917       If not used as a motion command:
918
919       Current line: Set to the line referenced by the mark.
920
921       Current column: Set to non-<blank>.
922
923   Return to Previous Context
924       Synopsis:
925
926                     ` character
927
928       It shall be an error if the marked line is no longer in the  edit  buf‐
929       fer.  If  the  marked  line no longer contains a character in the saved
930       numbered character position, it shall be as if the marked  position  is
931       the first non-<blank>.
932
933       If used as a motion command:
934
935        1. It shall be an error if the marked cursor references the same char‐
936           acter in the edit buffer as the starting cursor.
937
938        2. If the starting cursor is after the marked cursor, then  the  loca‐
939           tions of the starting cursor and the marked cursor in the edit buf‐
940           fer shall be logically swapped.
941
942        3. If the starting line is empty or  the  starting  cursor  is  at  or
943           before  the  first  non-<blank> non-<newline> of the starting line,
944           and the marked cursor line is empty or the marked cursor references
945           the  first  character  of  the  marked cursor line, the text region
946           shall consist of all lines containing characters from the  starting
947           cursor  to  the  line before the marked cursor line, inclusive, and
948           any text copied to a buffer shall be in line mode.
949
950        4. Otherwise, if the marked cursor line is empty or the marked  cursor
951           references a character at or before the first non-<blank> non-<new‐
952           line> of the marked cursor line, the region of text shall  be  from
953           the  starting  cursor  to the last non-<newline> of the line before
954           the marked cursor line, inclusive, and any text copied to a  buffer
955           shall be in character mode.
956
957        5. Otherwise,  the  region  of  text shall be from the starting cursor
958           (inclusive), to the marked cursor (exclusive), and any text  copied
959           to a buffer shall be in character mode.
960
961       If not used as a motion command:
962
963       Current line: Set to the line referenced by the mark.
964
965       Current  column:  Set  to  the  last column in which any portion of the
966       character referenced by the mark is displayed.
967
968   Return to Previous Section
969       Synopsis:
970
971                     [count] [[
972
973       Move the cursor backward through the edit buffer to the first character
974       of the previous section boundary, count times.
975
976       If used as a motion command:
977
978        1. If  the  starting cursor was at the first character of the starting
979           line or the starting line was empty, and the first character of the
980           boundary  was  the  first  character of the boundary line, the text
981           region shall consist of the current line up to  and  including  the
982           line where the countth next boundary starts, and any text copied to
983           a buffer shall be in line mode.
984
985        2. If the boundary was the last line of the edit buffer  or  the  last
986           non-<newline>  of the last line of the edit buffer, the text region
987           shall consist of the last character in the edit buffer  up  to  and
988           including  the  starting  character, and any text saved to a buffer
989           shall be in character mode.
990
991        3. Otherwise, the text region shall consist of the starting  character
992           up  to  but  not  including the first character in the countth next
993           boundary, and any text copied to a buffer  shall  be  in  character
994           mode.
995
996       If not used as a motion command:
997
998       Current  line:  Set  to the line where the countth next boundary in the
999       edit buffer starts.
1000
1001       Current column: Set to the last column in  which  any  portion  of  the
1002       first  character  of  the countth next boundary is displayed, or column
1003       position 1 if the line is empty.
1004
1005   Move to Next Section
1006       Synopsis:
1007
1008                     [count] ]]
1009
1010       Move the cursor forward through the edit buffer to the first  character
1011       of the next section boundary, count times.
1012
1013       If used as a motion command:
1014
1015        1. If  the  starting cursor was at the first character of the starting
1016           line or the starting line was empty, and the first character of the
1017           boundary  was  the  first  character of the boundary line, the text
1018           region shall consist of the current line up to  and  including  the
1019           line  where  the  countth  previous  boundary  starts, and any text
1020           copied to a buffer shall be in line mode.
1021
1022        2. If the boundary was the first line of the  edit  buffer,  the  text
1023           region  shall  consist of the first character in the edit buffer up
1024           to but not including the starting character, and any text copied to
1025           a buffer shall be in character mode.
1026
1027        3. Otherwise,  the text region shall consist of the first character in
1028           the countth previous section boundary up to but not  including  the
1029           starting  character,  and  any  text copied to a buffer shall be in
1030           character mode.
1031
1032       If not used as a motion command:
1033
1034       Current line: Set to the line where the countth  previous  boundary  in
1035       the edit buffer starts.
1036
1037       Current  column:  Set  to  the  last column in which any portion of the
1038       first character of the countth previous boundary is displayed, or  col‐
1039       umn position 1 if the line is empty.
1040
1041   Move to First Non-<blank> Position on Current Line
1042       Synopsis:
1043
1044                     ^
1045
1046       If used as a motion command:
1047
1048        1. If  the line has no non-<blank> non-<newline> characters, or if the
1049           cursor is at the first non-<blank> non-<newline> of  the  line,  it
1050           shall be an error.
1051
1052        2. If  the cursor is before the first non-<blank> non-<newline> of the
1053           line, the text region shall be comprised of the current  character,
1054           up  to,  but  not including, the first non-<blank> non-<newline> of
1055           the line.
1056
1057        3. If the cursor is after the first non-<blank> non-<newline>  of  the
1058           line, the text region shall be from the character before the start‐
1059           ing cursor up to and including the first non-<blank>  non-<newline>
1060           of the line.
1061
1062        4. Any text copied to a buffer shall be in character mode.
1063
1064       If not used as a motion command:
1065
1066       Current line: Unchanged.
1067
1068       Current column: Set to non-<blank>.
1069
1070   Current and Line Above
1071       Synopsis:
1072
1073                     [count] _
1074
1075       If  there  are  less  than count -1 lines after the current line in the
1076       edit buffer, it shall be an error.
1077
1078       If used as a motion command:
1079
1080        1. If count is less than 2, the text region shall be the current line.
1081
1082        2. Otherwise, the text region shall include the starting line and  the
1083           next count -1 lines.
1084
1085        3. Any text copied to a buffer shall be in line mode.
1086
1087       If not used as a motion command:
1088
1089       Current line: Set to current line + count -1.
1090
1091       Current column: Set to non-<blank>.
1092
1093   Move Back to Beginning of Sentence
1094       Synopsis:
1095
1096                     [count] (
1097
1098       Move  backward  to  the  beginning of a sentence. This command shall be
1099       equivalent to the [[ command, with the exception that  sentence  bound‐
1100       aries shall be used instead of section boundaries.
1101
1102   Move Forward to Beginning of Sentence
1103       Synopsis:
1104
1105                     [count] )
1106
1107       Move  forward  to  the  beginning  of a sentence. This command shall be
1108       equivalent to the ]] command, with the exception that  sentence  bound‐
1109       aries shall be used instead of section boundaries.
1110
1111   Move Back to Preceding Paragraph
1112       Synopsis:
1113
1114                     [count] {
1115
1116       Move  back  to  the  beginning of the preceding paragraph. This command
1117       shall be equivalent to the [[ command, with the  exception  that  para‐
1118       graph boundaries shall be used instead of section boundaries.
1119
1120   Move Forward to Next Paragraph
1121       Synopsis:
1122
1123                     [count] }
1124
1125       Move forward to the beginning of the next paragraph. This command shall
1126       be equivalent to the ]] command,  with  the  exception  that  paragraph
1127       boundaries shall be used instead of section boundaries.
1128
1129   Move to Specific Column Position
1130       Synopsis:
1131
1132                     [count] |
1133
1134       For  the purposes of this command, lines that are too long for the cur‐
1135       rent display and that have been folded shall be  treated  as  having  a
1136       single, 1-based, number of columns.
1137
1138       If  there are less than count columns in which characters from the cur‐
1139       rent line are displayed on the screen, count shall be  adjusted  to  be
1140       the  last  column  in which any portion of the line is displayed on the
1141       screen.
1142
1143       If used as a motion command:
1144
1145        1. If the line is empty, or the cursor character is the  same  as  the
1146           character on the countth column of the line, it shall be an error.
1147
1148        2. If  the  cursor  is before the countth column of the line, the text
1149           region shall be comprised of the current character, up to  but  not
1150           including the character on the countth column of the line.
1151
1152        3. If  the  cursor  is  after the countth column of the line, the text
1153           region shall be from the character before the starting cursor up to
1154           and including the character on the countth column of the line.
1155
1156        4. Any text copied to a buffer shall be in character mode.
1157
1158       If not used as a motion command:
1159
1160       Current line: Unchanged.
1161
1162       Current  column:  Set  to  the  last column in which any portion of the
1163       character that is displayed in the count column of  the  line  is  dis‐
1164       played.
1165
1166   Reverse Find Character
1167       Synopsis:
1168
1169                     [count] ,
1170
1171       If the last F, f, T, or t command was F, f, T, or t, this command shall
1172       be equivalent to an f, F, t, or T command, respectively, with the spec‐
1173       ified count and the same search character.
1174
1175       If there was no previous F, f, T, or t command, it shall be an error.
1176
1177   Repeat
1178       Synopsis:
1179
1180                     [count] .
1181
1182       Repeat  the  last !, <, >, A, C, D, I, J, O, P, R, S, X, Y, a, c, d, i,
1183       o, p, r, s, x, y, or ~ command. It shall be an error if none  of  these
1184       commands  have  been executed. Commands (other than commands that enter
1185       text input mode) executed as a result  of  map  expansions,  shall  not
1186       change the value of the last repeatable command.
1187
1188       Repeated  commands  with  associated  motion  commands shall repeat the
1189       motion command as well; however, any specified count shall replace  the
1190       count(s)  that were originally specified to the repeated command or its
1191       associated motion command.
1192
1193       If the motion component of the repeated command is f, F, t, or  T,  the
1194       repeated  command shall not set the remembered search character for the
1195       ; and , commands.
1196
1197       If the repeated command is p or P, and the buffer associated with  that
1198       command  was a numeric buffer named with a number less than 9, the buf‐
1199       fer associated with the repeated command shall be set to be the  buffer
1200       named by the name of the previous buffer logically incremented by 1.
1201
1202       If the repeated character is a text input command, the input text asso‐
1203       ciated with that command is repeated literally:
1204
1205        *  Input characters are neither macro or abbreviation-expanded.
1206
1207        *  Input characters are not interpreted in any special  way  with  the
1208           exception that <newline>, <carriage-return>, and <control>‐T behave
1209           as described in Input Mode Commands in vi.
1210
1211       Current line: Set as described for the repeated command.
1212
1213       Current column: Set as described for the repeated command.
1214
1215   Find Regular Expression
1216       Synopsis:
1217
1218                     /
1219
1220       If the input line contains no non-<newline>  characters,  it  shall  be
1221       equivalent  to  a  line  containing  only  the  last regular expression
1222       encountered. The enhanced  regular  expressions  supported  by  vi  are
1223       described in Regular Expressions in ex.
1224
1225       Otherwise, the line shall be interpreted as one or more regular expres‐
1226       sions, optionally followed by an address offset or a vi z command.
1227
1228       If the regular expression is not the last  regular  expression  on  the
1229       line,  or  if  a  line  offset  or  z command is specified, the regular
1230       expression shall be terminated by an  unescaped  '/'  character,  which
1231       shall  not  be  used as part of the regular expression.  If the regular
1232       expression is not the first regular expression on the line, it shall be
1233       preceded  by  zero  or  more <blank> characters, a <semicolon>, zero or
1234       more <blank> characters, and a leading '/' character, which  shall  not
1235       be  interpreted as part of the regular expression. It shall be an error
1236       to precede any regular expression with any characters other than these.
1237
1238       Each search shall begin from the character after the first character of
1239       the  last  match  (or, if it is the first search, after the cursor). If
1240       the wrapscan edit option is set, the search shall continue to the char‐
1241       acter  before  the  starting cursor character; otherwise, to the end of
1242       the edit buffer. It shall be an error if any search  fails  to  find  a
1243       match, and an informational message to this effect shall be displayed.
1244
1245       An  optional  address  offset  (see  Addressing in ex) can be specified
1246       after the last regular expression by including a trailing '/' character
1247       after  the  regular  expression and specifying the address offset. This
1248       offset will be from the line containing the match for the last  regular
1249       expression  specified.  It  shall  be an error if the line offset would
1250       indicate a line address less than 1 or greater than the  last  line  in
1251       the edit buffer. An address offset of zero shall be supported. It shall
1252       be an error to follow the address offset with any other characters than
1253       <blank> characters.
1254
1255       If not used as a motion command, an optional z command (see Redraw Win‐
1256       dow) can be specified after the last regular expression by including  a
1257       trailing  '/'  character  after  the  regular  expression, zero or more
1258       <blank> characters, a 'z', zero or more <blank> characters, an optional
1259       new  window  edit  option value, zero or more <blank> characters, and a
1260       location character. The effect shall be as if the z  command  was  exe‐
1261       cuted after the / command. It shall be an error to follow the z command
1262       with any other characters than <blank> characters.
1263
1264       The remembered search direction shall be set to forward.
1265
1266       If used as a motion command:
1267
1268        1. It shall be an error if the last match references the same  charac‐
1269           ter in the edit buffer as the starting cursor.
1270
1271        2. If  any  address  offset  is  specified,  the  last  match shall be
1272           adjusted by the specified offset as described previously.
1273
1274        3. If the starting cursor is after the last match, then the  locations
1275           of  the starting cursor and the last match in the edit buffer shall
1276           be logically swapped.
1277
1278        4. If any address offset is specified, the text region  shall  consist
1279           of  all lines containing characters from the starting cursor to the
1280           last match line, inclusive, and any text copied to a  buffer  shall
1281           be in line mode.
1282
1283        5. Otherwise,  if the starting line is empty or the starting cursor is
1284           at or before the first non-<blank> non-<newline>  of  the  starting
1285           line,  and the last match line is empty or the last match starts at
1286           the first character of the last match line, the text  region  shall
1287           consist of all lines containing characters from the starting cursor
1288           to the line before the last match line,  inclusive,  and  any  text
1289           copied to a buffer shall be in line mode.
1290
1291        6. Otherwise, if the last match line is empty or the last match begins
1292           at a character at or before the first non-<blank> non-<newline>  of
1293           the  last  match line, the region of text shall be from the current
1294           cursor to the last non-<newline> of the line before the last  match
1295           line,  inclusive, and any text copied to a buffer shall be in char‐
1296           acter mode.
1297
1298        7. Otherwise, the region of text shall  be  from  the  current  cursor
1299           (inclusive),  to the first character of the last match (exclusive),
1300           and any text copied to a buffer shall be in character mode.
1301
1302       If not used as a motion command:
1303
1304       Current line: If a match is found, set to the last  matched  line  plus
1305       the address offset, if any; otherwise, unchanged.
1306
1307       Current  column:  Set  to  the  last column on which any portion of the
1308       first character in the last matched string is displayed, if a match  is
1309       found; otherwise, unchanged.
1310
1311   Move to First Character in Line
1312       Synopsis:
1313
1314                     0  (zero)
1315
1316       Move  to  the  first  character  on the current line. The character '0'
1317       shall not be interpreted as a command if it is immediately preceded  by
1318       a digit.
1319
1320       If used as a motion command:
1321
1322        1. If  the  cursor  character  is  the first character in the line, it
1323           shall be an error.
1324
1325        2. The text region shall be from the character before the cursor char‐
1326           acter up to and including the first character in the line.
1327
1328        3. Any text copied to a buffer shall be in character mode.
1329
1330       If not used as a motion command:
1331
1332       Current line: Unchanged.
1333
1334       Current column: The last column in which any portion of the first char‐
1335       acter in the line is displayed, or if the line is empty, unchanged.
1336
1337   Execute an ex Command
1338       Synopsis:
1339
1340                     :
1341
1342       Execute one or more ex commands.
1343
1344       If any portion of the screen other than the last line of the screen was
1345       overwritten  by  any ex command (except shell), vi shall display a mes‐
1346       sage indicating that it is waiting for an  input  from  the  user,  and
1347       shall  then  read a character. This action may also be taken for other,
1348       unspecified reasons.
1349
1350       If the next character entered is a ':', another  ex  command  shall  be
1351       accepted and executed. Any other character shall cause the screen to be
1352       refreshed and vi shall return to command mode.
1353
1354       Current line: As specified for the ex command.
1355
1356       Current column: As specified for the ex command.
1357
1358   Repeat Find
1359       Synopsis:
1360
1361                     [count] ;
1362
1363       This command shall be equivalent to the last F, f,  T,  or  t  command,
1364       with  the  specified count, and with the same search character used for
1365       the last F, f, T, or t command. If there was no previous F, f, T, or  t
1366       command, it shall be an error.
1367
1368   Shift Left
1369       Synopsis:
1370
1371                     [count] < motion
1372
1373       If the motion command is the < command repeated:
1374
1375        1. If there are less than count -1 lines after the current line in the
1376           edit buffer, it shall be an error.
1377
1378        2. The text region shall be from the current line, up to and including
1379           the next count -1 lines.
1380
1381       Shift  any  line  in  the text region specified by the count and motion
1382       command one shiftwidth (see the ex shiftwidth option) toward the  start
1383       of  the  line,  as  described  by the ex < command. The unshifted lines
1384       shall be copied to the unnamed buffer in line mode.
1385
1386       Current line: If the motion was from the current cursor position toward
1387       the end of the edit buffer, unchanged. Otherwise, set to the first line
1388       in the edit buffer that is part of the text  region  specified  by  the
1389       motion command.
1390
1391       Current column: Set to non-<blank>.
1392
1393   Shift Right
1394       Synopsis:
1395
1396                     [count] > motion
1397
1398       If the motion command is the > command repeated:
1399
1400        1. If there are less than count -1 lines after the current line in the
1401           edit buffer, it shall be an error.
1402
1403        2. The text region shall be from the current line, up to and including
1404           the next count -1 lines.
1405
1406       Shift  any  line  with  characters  in the text region specified by the
1407       count and motion command one shiftwidth (see the ex shiftwidth  option)
1408       away  from the start of the line, as described by the ex > command. The
1409       unshifted lines shall be copied into the unnamed buffer in line mode.
1410
1411       Current line: If the motion was from the current cursor position toward
1412       the end of the edit buffer, unchanged. Otherwise, set to the first line
1413       in the edit buffer that is part of the text  region  specified  by  the
1414       motion command.
1415
1416       Current column: Set to non-<blank>.
1417
1418   Scan Backwards for Regular Expression
1419       Synopsis:
1420
1421                     ?
1422
1423       Scan  backwards;  the  ?   command shall be equivalent to the / command
1424       (see Find Regular Expression) with the following exceptions:
1425
1426        1. The input prompt shall be a '?'.
1427
1428        2. Each search shall begin from the character before the first charac‐
1429           ter of the last match (or, if it is the first search, the character
1430           before the cursor character).
1431
1432        3. The search direction shall be from the cursor toward the  beginning
1433           of  the  edit  buffer,  and  the  wrapscan edit option shall affect
1434           whether the search wraps to the end of the edit buffer and  contin‐
1435           ues.
1436
1437        4. The remembered search direction shall be set to backward.
1438
1439   Execute
1440       Synopsis:
1441
1442                     @buffer
1443
1444       If  the  buffer  is  specified  as @, the last buffer executed shall be
1445       used. If no previous buffer has been executed, it shall be an error.
1446
1447       Behave as if the contents of the named buffer were entered as  standard
1448       input. After each line of a line-mode buffer, and all but the last line
1449       of a character mode buffer, behave as if a <newline>  were  entered  as
1450       standard input.
1451
1452       If an error occurs during this process, an error message shall be writ‐
1453       ten, and no more characters resulting from the execution of  this  com‐
1454       mand shall be processed.
1455
1456       If  a  count is specified, behave as if that count were entered as user
1457       input before the characters from the @ buffer were entered.
1458
1459       Current line: As specified for the individual commands.
1460
1461       Current column: As specified for the individual commands.
1462
1463   Reverse Case
1464       Synopsis:
1465
1466                     [count] ~
1467
1468       Reverse the case of the current character and the next count -1 charac‐
1469       ters,  such  that lowercase characters that have uppercase counterparts
1470       shall be changed to uppercase characters, and uppercase characters that
1471       have  lowercase  counterparts shall be changed to lowercase characters,
1472       as prescribed by the current  locale.  No  other  characters  shall  be
1473       affected by this command.
1474
1475       If there are less than count -1 characters after the cursor in the edit
1476       buffer, count shall be adjusted to the number of characters  after  the
1477       cursor in the edit buffer minus 1.
1478
1479       For  the  purposes  of  this command, the next character after the last
1480       non-<newline> on the line shall be the next character in the edit  buf‐
1481       fer.
1482
1483       Current line: Set to the line including the (count-1)th character after
1484       the cursor.
1485
1486       Current column: Set to the last column in  which  any  portion  of  the
1487       (count-1)th character after the cursor is displayed.
1488
1489   Append
1490       Synopsis:
1491
1492                     [count] a
1493
1494       Enter  text input mode after the current cursor position. No characters
1495       already in the edit buffer shall be affected by this command.  A  count
1496       shall  cause  the  input text to be appended count -1 more times to the
1497       end of the input.
1498
1499       Current line/column: As specified for  the  text  input  commands  (see
1500       Input Mode Commands in vi).
1501
1502   Append at End-of-Line
1503       Synopsis:
1504
1505                     [count] A
1506
1507       This command shall be equivalent to the vi command:
1508
1509
1510           $ [ count ] a
1511
1512       (see Append).
1513
1514   Move Backward to Preceding Word
1515       Synopsis:
1516
1517                     [count] b
1518
1519       With the exception that words are used as the delimiter instead of big‐
1520       words, this command shall be equivalent to the B command.
1521
1522   Move Backward to Preceding Bigword
1523       Synopsis:
1524
1525                     [count] B
1526
1527       If the edit buffer is empty or the cursor is on the first character  of
1528       the  edit  buffer,  it  shall  be an error. If less than count bigwords
1529       begin between the cursor and the start of the edit buffer, count  shall
1530       be  adjusted to the number of bigword beginnings between the cursor and
1531       the start of the edit buffer.
1532
1533       If used as a motion command:
1534
1535        1. The text region shall be from the first character  of  the  countth
1536           previous bigword beginning up to but not including the cursor char‐
1537           acter.
1538
1539        2. Any text copied to a buffer shall be in character mode.
1540
1541       If not used as a motion command:
1542
1543       Current line: Set to the line containing the current column.
1544
1545       Current column: Set to the last column upon which any part of the first
1546       character of the countth previous bigword is displayed.
1547
1548   Change
1549       Synopsis:
1550
1551                     [buffer][count] c motion
1552
1553       If the motion command is the c command repeated:
1554
1555        1. The buffer text shall be in line mode.
1556
1557        2. If there are less than count -1 lines after the current line in the
1558           edit buffer, it shall be an error.
1559
1560        3. The text region shall be from the current line up to and  including
1561           the next count -1 lines.
1562
1563       Otherwise,  the  buffer text mode and text region shall be as specified
1564       by the motion command.
1565
1566       The replaced text shall be copied into buffer, if specified,  and  into
1567       the unnamed buffer. If the text to be replaced contains characters from
1568       more than a single line, or the  buffer  text  is  in  line  mode,  the
1569       replaced text shall be copied into the numeric buffers as well.
1570
1571       If the buffer text is in line mode:
1572
1573        1. Any  lines  that contain characters in the region shall be deleted,
1574           and the editor shall enter text input mode at the  beginning  of  a
1575           new line which shall replace the first line deleted.
1576
1577        2. If  the  autoindent edit option is set, autoindent characters equal
1578           to the autoindent characters on the first  line  deleted  shall  be
1579           inserted as if entered by the user.
1580
1581       Otherwise,  if  characters from more than one line are in the region of
1582       text:
1583
1584        1. The text shall be deleted.
1585
1586        2. Any text remaining in the last line in the  text  region  shall  be
1587           appended  to the first line in the region, and the last line in the
1588           region shall be deleted.
1589
1590        3. The editor shall enter text input mode after the last character not
1591           deleted  from the first line in the text region, if any; otherwise,
1592           on the first column of the first line in the region.
1593
1594       Otherwise:
1595
1596        1. If the glyph for '$' is smaller than the region,  the  end  of  the
1597           region shall be marked with a '$'.
1598
1599        2. The  editor  shall enter text input mode, overwriting the region of
1600           text.
1601
1602       Current line/column: As specified for  the  text  input  commands  (see
1603       Input Mode Commands in vi).
1604
1605   Change to End-of-Line
1606       Synopsis:
1607
1608                     [buffer][count] C
1609
1610       This command shall be equivalent to the vi command:
1611
1612
1613           [buffer][count] c$
1614
1615       See the c command.
1616
1617   Delete
1618       Synopsis:
1619
1620                     [buffer][count] d motion
1621
1622       If the motion command is the d command repeated:
1623
1624        1. The buffer text shall be in line mode.
1625
1626        2. If there are less than count -1 lines after the current line in the
1627           edit buffer, it shall be an error.
1628
1629        3. The text region shall be from the current line up to and  including
1630           the next count -1 lines.
1631
1632       Otherwise,  the  buffer text mode and text region shall be as specified
1633       by the motion command.
1634
1635       If in open mode, and the current line is deleted, and the line  remains
1636       on  the display, an '@' character shall be displayed as the first glyph
1637       of that line.
1638
1639       Delete the region of text into  buffer,  if  specified,  and  into  the
1640       unnamed buffer. If the text to be deleted contains characters from more
1641       than a single line, or the buffer text is in  line  mode,  the  deleted
1642       text shall be copied into the numeric buffers, as well.
1643
1644       Current  line:  Set  to  the first text region line that appears in the
1645       edit buffer, unless that line has been deleted, in which case it  shall
1646       be  set to the last line in the edit buffer, or line 1 if the edit buf‐
1647       fer is empty.
1648
1649       Current column:
1650
1651        1. If the line is empty, set to column position 1.
1652
1653        2. Otherwise, if the buffer text is in line mode  or  the  motion  was
1654           from the cursor toward the end of the edit buffer:
1655
1656            a. If  a  character from the current line is displayed in the cur‐
1657               rent column, set to the last column that displays  any  portion
1658               of that character.
1659
1660            b. Otherwise,  set  to the last column in which any portion of any
1661               character in the line is displayed.
1662
1663        3. Otherwise, if a character is displayed in the column that began the
1664           text  region,  set  to the last column that displays any portion of
1665           that character.
1666
1667        4. Otherwise, set to the last column in which any portion of any char‐
1668           acter in the line is displayed.
1669
1670   Delete to End-of-Line
1671       Synopsis:
1672
1673                     [buffer] D
1674
1675       Delete  the  text  from  the current position to the end of the current
1676       line; equivalent to the vi command:
1677
1678
1679           [buffer] d$
1680
1681   Move to End-of-Word
1682       Synopsis:
1683
1684                     [count] e
1685
1686       With the exception that words are  used  instead  of  bigwords  as  the
1687       delimiter, this command shall be equivalent to the E command.
1688
1689   Move to End-of-Bigword
1690       Synopsis:
1691
1692                     [count] E
1693
1694       If  the  edit  buffer is empty it shall be an error. If less than count
1695       bigwords end between the cursor and the end of the edit  buffer,  count
1696       shall  be  adjusted to the number of bigword endings between the cursor
1697       and the end of the edit buffer.
1698
1699       If used as a motion command:
1700
1701        1. The text region shall be from the last  character  of  the  countth
1702           next bigword up to and including the cursor character.
1703
1704        2. Any text copied to a buffer shall be in character mode.
1705
1706       If not used as a motion command:
1707
1708       Current line: Set to the line containing the current column.
1709
1710       Current  column: Set to the last column upon which any part of the last
1711       character of the countth next bigword is displayed.
1712
1713   Find Character in Current Line (Forward)
1714       Synopsis:
1715
1716                     [count] f character
1717
1718       It shall be an error if count occurrences of the character do not occur
1719       after the cursor in the line.
1720
1721       If used as a motion command:
1722
1723        1. The text range shall be from the cursor character up to and includ‐
1724           ing the countth occurrence of the  specified  character  after  the
1725           cursor.
1726
1727        2. Any text copied to a buffer shall be in character mode.
1728
1729       If not used as a motion command:
1730
1731       Current line: Unchanged.
1732
1733       Current  column:  Set  to  the  last column in which any portion of the
1734       countth occurrence of the specified character after the cursor  appears
1735       in the line.
1736
1737   Find Character in Current Line (Reverse)
1738       Synopsis:
1739
1740                     [count] F character
1741
1742       It shall be an error if count occurrences of the character do not occur
1743       before the cursor in the line.
1744
1745       If used as a motion command:
1746
1747        1. The text region shall be from the countth occurrence of the  speci‐
1748           fied character before the cursor, up to, but not including the cur‐
1749           sor character.
1750
1751        2. Any text copied to a buffer shall be in character mode.
1752
1753       If not used as a motion command:
1754
1755       Current line: Unchanged.
1756
1757       Current column: Set to the last column in  which  any  portion  of  the
1758       countth occurrence of the specified character before the cursor appears
1759       in the line.
1760
1761   Move to Line
1762       Synopsis:
1763
1764                     [count] G
1765
1766       If count is not specified, it shall default to the  last  line  of  the
1767       edit  buffer.   If count is greater than the last line of the edit buf‐
1768       fer, it shall be an error.
1769
1770       If used as a motion command:
1771
1772        1. The text region shall be from the cursor line up to  and  including
1773           the specified line.
1774
1775        2. Any text copied to a buffer shall be in line mode.
1776
1777       If not used as a motion command:
1778
1779       Current  line:  Set to count if count is specified; otherwise, the last
1780       line.
1781
1782       Current column: Set to non-<blank>.
1783
1784   Move to Top of Screen
1785       Synopsis:
1786
1787                     [count] H
1788
1789       If the beginning of the line count greater than the first line of which
1790       any  portion  appears  on  the  display  does not exist, it shall be an
1791       error.
1792
1793       If used as a motion command:
1794
1795        1. If in open mode, the text region shall be the current line.
1796
1797        2. Otherwise, the text region shall be from the starting  line  up  to
1798           and including (the first line of the display + count -1).
1799
1800        3. Any text copied to a buffer shall be in line mode.
1801
1802       If not used as a motion command:
1803
1804       If  in  open  mode,  this  command  shall  set  the  current  column to
1805       non-<blank> and do nothing else.
1806
1807       Otherwise, it shall set the current line and current column as follows.
1808
1809       Current line: Set to (the first line of the display + count -1).
1810
1811       Current column: Set to non-<blank>.
1812
1813   Insert Before Cursor
1814       Synopsis:
1815
1816                     [count] i
1817
1818       Enter text input mode before the current cursor position. No characters
1819       already  in  the edit buffer shall be affected by this command. A count
1820       shall cause the input text to be appended count -1 more  times  to  the
1821       end of the input.
1822
1823       Current  line/column:  As  specified  for  the text input commands (see
1824       Input Mode Commands in vi).
1825
1826   Insert at Beginning of Line
1827       Synopsis:
1828
1829                     [count] I
1830
1831       This command shall be equivalent to the vi command ^[count]i.
1832
1833   Join
1834       Synopsis:
1835
1836                     [count] J
1837
1838       If the current line is the last line in the edit buffer, it shall be an
1839       error.
1840
1841       This  command  shall  be  equivalent  to  the  ex  join command with no
1842       addresses, and an ex command count value of 1 if count was  not  speci‐
1843       fied or if a count of 1 was specified, and an ex command count value of
1844       count -1 for any other value of count, except that the current line and
1845       column shall be set as follows.
1846
1847       Current line: Unchanged.
1848
1849       Current  column:  The last column in which any portion of the character
1850       following the last character in the initial line is displayed,  or  the
1851       last non-<newline> in the line if no characters were appended.
1852
1853   Move to Bottom of Screen
1854       Synopsis:
1855
1856                     [count] L
1857
1858       If the beginning of the line count less than the last line of which any
1859       portion appears on the display does not exist, it shall be an error.
1860
1861       If used as a motion command:
1862
1863        1. If in open mode, the text region shall be the current line.
1864
1865        2. Otherwise, the text region shall include all lines from the  start‐
1866           ing cursor line to (the last line of the display -(count -1)).
1867
1868        3. Any text copied to a buffer shall be in line mode.
1869
1870       If not used as a motion command:
1871
1872        1. If  in  open  mode,  this  command  shall set the current column to
1873           non-<blank> and do nothing else.
1874
1875        2. Otherwise, it shall set the current line and current column as fol‐
1876           lows.
1877
1878       Current line: Set to (the last line of the display -(count -1)).
1879
1880       Current column: Set to non-<blank>.
1881
1882   Mark Position
1883       Synopsis:
1884
1885                     m letter
1886
1887       This command shall be equivalent to the ex mark command with the speci‐
1888       fied character as an argument.
1889
1890   Move to Middle of Screen
1891       Synopsis:
1892
1893                     M
1894
1895       The middle line of the display shall be calculated as follows:
1896
1897
1898           (the top line of the display) + (((number of lines displayed) +1) /2) -1
1899
1900       If used as a motion command:
1901
1902        1. If in open mode, the text region shall be the current line.
1903
1904        2. Otherwise, the text region shall include all lines from the  start‐
1905           ing cursor line up to and including the middle line of the display.
1906
1907        3. Any text copied to a buffer shall be in line mode.
1908
1909       If not used as a motion command:
1910
1911       If  in  open  mode,  this  command  shall  set  the  current  column to
1912       non-<blank> and do nothing else.
1913
1914       Otherwise, it shall set the current line and current column as follows.
1915
1916       Current line: Set to the middle line of the display.
1917
1918       Current column: Set to non-<blank>.
1919
1920   Repeat Regular Expression Find (Forward)
1921       Synopsis:
1922
1923                     n
1924
1925       If the remembered search direction was forward, the n command shall  be
1926       equivalent  to the vi / command with no characters entered by the user.
1927       Otherwise, it shall be equivalent to the vi ?  command with no  charac‐
1928       ters entered by the user.
1929
1930       If  the  n  command is used as a motion command for the !  command, the
1931       editor shall not enter text input mode on the last line on the  screen,
1932       and  shall behave as if the user entered a single '!'  character as the
1933       text input.
1934
1935   Repeat Regular Expression Find (Reverse)
1936       Synopsis:
1937
1938                     N
1939
1940       Scan for the next match of the last pattern given to / or ?, but in the
1941       reverse direction; this is the reverse of n.
1942
1943       If  the remembered search direction was forward, the N command shall be
1944       equivalent to the vi ?  command with no characters entered by the user.
1945       Otherwise,  it  shall be equivalent to the vi / command with no charac‐
1946       ters entered by the user. If the N command is used as a motion  command
1947       for  the  !  command, the editor shall not enter text input mode on the
1948       last line on the screen, and shall behave as if the user entered a sin‐
1949       gle !  character as the text input.
1950
1951   Insert Empty Line Below
1952       Synopsis:
1953
1954                     o
1955
1956       Enter  text input mode in a new line appended after the current line. A
1957       count shall cause the input text to be appended count -1 more times  to
1958       the  end  of  the  already  added  text,  each  time starting on a new,
1959       appended line.
1960
1961       Current line/column: As specified for  the  text  input  commands  (see
1962       Input Mode Commands in vi).
1963
1964   Insert Empty Line Above
1965       Synopsis:
1966
1967                     O
1968
1969       Enter text input mode in a new line inserted before the current line. A
1970       count shall cause the input text to be appended count -1 more times  to
1971       the  end  of  the  already  added  text,  each  time starting on a new,
1972       appended line.
1973
1974       Current line/column: As specified for  the  text  input  commands  (see
1975       Input Mode Commands in vi).
1976
1977   Put from Buffer Following
1978       Synopsis:
1979
1980                     [buffer] p
1981
1982       If no buffer is specified, the unnamed buffer shall be used.
1983
1984       If  the  buffer  text is in line mode, the text shall be appended below
1985       the current line, and each line of the buffer shall become a  new  line
1986       in  the edit buffer. A count shall cause the buffer text to be appended
1987       count -1 more times to the end of the already  added  text,  each  time
1988       starting on a new, appended line.
1989
1990       If  the  buffer  text  is in character mode, the text shall be appended
1991       into the current line after the cursor, and each  line  of  the  buffer
1992       other  than the first and last shall become a new line in the edit buf‐
1993       fer. A count shall cause the buffer text to be appended count  -1  more
1994       times  to  the  end of the already added text, each time starting after
1995       the last added character.
1996
1997       Current line: If the buffer text is in line mode, set the line to  line
1998       +1; otherwise, unchanged.
1999
2000       Current column: If the buffer text is in line mode:
2001
2002        1. If  there  is a non-<blank> in the first line of the buffer, set to
2003           the last column on which any portion of the  first  non-<blank>  in
2004           the line is displayed.
2005
2006        2. If  there is no non-<blank> in the first line of the buffer, set to
2007           the last column on which any portion of the last  non-<newline>  in
2008           the first line of the buffer is displayed.
2009
2010       If the buffer text is in character mode:
2011
2012        1. If the text in the buffer is from more than a single line, then set
2013           to the last column on which any portion of the first character from
2014           the buffer is displayed.
2015
2016        2. Otherwise,  if  the  buffer  is the unnamed buffer, set to the last
2017           column on which any portion of the last character from  the  buffer
2018           is displayed.
2019
2020        3. Otherwise,  set  to  the  first  column on which any portion of the
2021           first character from the buffer is displayed.
2022
2023   Put from Buffer Before
2024       Synopsis:
2025
2026                     [buffer] P
2027
2028       If no buffer is specified, the unnamed buffer shall be used.
2029
2030       If the buffer text is in line mode, the text shall  be  inserted  above
2031       the  current  line, and each line of the buffer shall become a new line
2032       in the edit buffer. A count shall cause the buffer text to be  appended
2033       count  -1  more  times  to the end of the already added text, each time
2034       starting on a new, appended line.
2035
2036       If the buffer text is in character mode, the  text  shall  be  inserted
2037       into  the  current  line before the cursor, and each line of the buffer
2038       other than the first and last shall become a new line in the edit  buf‐
2039       fer.  A  count shall cause the buffer text to be appended count -1 more
2040       times to the end of the already added text, each  time  starting  after
2041       the last added character.
2042
2043       Current line: Unchanged.
2044
2045       Current column: If the buffer text is in line mode:
2046
2047        1. If  there  is a non-<blank> in the first line of the buffer, set to
2048           the last column on which any portion  of  that  character  is  dis‐
2049           played.
2050
2051        2. If  there is no non-<blank> in the first line of the buffer, set to
2052           the last column on which any portion of the last  non-<newline>  in
2053           the first line of the buffer is displayed.
2054
2055       If the buffer text is in character mode:
2056
2057        1. If the text in the buffer is from more than a single line, then set
2058           to the last column on which any portion of the first character from
2059           the buffer is displayed.
2060
2061        2. Otherwise,  if  the  buffer  is the unnamed buffer, set to the last
2062           column on which any portion of the last character from  the  buffer
2063           is displayed.
2064
2065        3. Otherwise,  set  to  the  first  column on which any portion of the
2066           first character from the buffer is displayed.
2067
2068   Enter ex Mode
2069       Synopsis:
2070
2071                     Q
2072
2073       Leave visual or open mode and enter ex command mode.
2074
2075       Current line: Unchanged.
2076
2077       Current column: Unchanged.
2078
2079   Replace Character
2080       Synopsis:
2081
2082                     [count] r character
2083
2084       Replace the count characters at and after the cursor with the specified
2085       character. If there are less than count non-<newline> characters at and
2086       after the cursor on the line, it shall be an error.
2087
2088       If character is <control>‐V, any next character other  than  the  <new‐
2089       line>  shall  be  stripped of any special meaning and used as a literal
2090       character.
2091
2092       If character is <ESC>, no replacement shall be  made  and  the  current
2093       line and current column shall be unchanged.
2094
2095       If  character  is <carriage-return> or <newline>, count new lines shall
2096       be appended to the current line. All but the last of these lines  shall
2097       be empty.  count characters at and after the cursor shall be discarded,
2098       and any remaining characters after the cursor in the current line shall
2099       be moved to the last of the new lines. If the autoindent edit option is
2100       set, they shall be preceded by the same number of autoindent characters
2101       found on the line from which the command was executed.
2102
2103       Current  line:  Unchanged  unless  the replacement character is a <car‐
2104       riage-return> or <newline>, in which case it shall be  set  to  line  +
2105       count.
2106
2107       Current  column:  Set to the last column position on which a portion of
2108       the last replaced character is displayed, or if the replacement charac‐
2109       ter caused new lines to be created, set to non-<blank>.
2110
2111   Replace Characters
2112       Synopsis:
2113
2114                     R
2115
2116       Enter text input mode at the current cursor position possibly replacing
2117       text on the current line. A count shall cause  the  input  text  to  be
2118       appended count -1 more times to the end of the input.
2119
2120       Current  line/column:  As  specified  for  the text input commands (see
2121       Input Mode Commands in vi).
2122
2123   Substitute Character
2124       Synopsis:
2125
2126                     [buffer][count] s
2127
2128       This command shall be equivalent to the vi command:
2129
2130
2131           [buffer][count] c<space>
2132
2133   Substitute Lines
2134       Synopsis:
2135
2136                     [buffer][count] S
2137
2138       This command shall be equivalent to the vi command:
2139
2140
2141           [buffer][count] c_
2142
2143   Move Cursor to Before Character (Forward)
2144       Synopsis:
2145
2146                     [count] t character
2147
2148       It shall be an error if count occurrences of the character do not occur
2149       after the cursor in the line.
2150
2151       If used as a motion command:
2152
2153        1. The  text  region  shall be from the cursor up to but not including
2154           the countth occurrence of the specified character after the cursor.
2155
2156        2. Any text copied to a buffer shall be in character mode.
2157
2158       If not used as a motion command:
2159
2160       Current line: Unchanged.
2161
2162       Current column: Set to the last column in  which  any  portion  of  the
2163       character  before  the  countth  occurrence  of the specified character
2164       after the cursor appears in the line.
2165
2166   Move Cursor to After Character (Reverse)
2167       Synopsis:
2168
2169                     [count] T character
2170
2171       It shall be an error if count occurrences of the character do not occur
2172       before the cursor in the line.
2173
2174       If used as a motion command:
2175
2176        1. If  the  character before the cursor is the specified character, it
2177           shall be an error.
2178
2179        2. The text region shall be from the character before the cursor up to
2180           but not including the countth occurrence of the specified character
2181           before the cursor.
2182
2183        3. Any text copied to a buffer shall be in character mode.
2184
2185       If not used as a motion command:
2186
2187       Current line: Unchanged.
2188
2189       Current column: Set to the last column in  which  any  portion  of  the
2190       character  after  the  countth  occurrence  of  the specified character
2191       before the cursor appears in the line.
2192
2193   Undo
2194       Synopsis:
2195
2196                     u
2197
2198       This command shall be equivalent to the ex undo command except that the
2199       current line and current column shall be set as follows:
2200
2201       Current line: Set to the first line added or changed if any; otherwise,
2202       move to the line preceding any deleted text if one  exists;  otherwise,
2203       move to line 1.
2204
2205       Current column: If undoing an ex command, set to the first non-<blank>.
2206
2207       Otherwise, if undoing a text input command:
2208
2209        1. If  the  command  was a C, c, O, o, R, S, or s command, the current
2210           column shall be set to the value it held when the text  input  com‐
2211           mand was entered.
2212
2213        2. Otherwise, set to the last column in which any portion of the first
2214           character after the deleted text is displayed, or, if no  non-<new‐
2215           line> characters follow the text deleted from this line, set to the
2216           last column in which any portion of the last non-<newline>  in  the
2217           line is displayed, or 1 if the line is empty.
2218
2219       Otherwise,  if  a  single  line  was  modified  (that  is, not added or
2220       deleted) by the u command:
2221
2222        1. If text was added or changed, set to the last column in  which  any
2223           portion of the first character added or changed is displayed.
2224
2225        2. If text was deleted, set to the last column in which any portion of
2226           the first character after the deleted text is displayed, or, if  no
2227           non-<newline>  characters  follow the deleted text, set to the last
2228           column in which any portion of the last non-<newline> in  the  line
2229           is displayed, or 1 if the line is empty.
2230
2231       Otherwise, set to non-<blank>.
2232
2233   Undo Current Line
2234       Synopsis:
2235
2236                     U
2237
2238       Restore  the  current  line  to  its  state immediately before the most
2239       recent time that it became the current line.
2240
2241       Current line: Unchanged.
2242
2243       Current column: Set to the first column in the line in which  any  por‐
2244       tion of the first character in the line is displayed.
2245
2246   Move to Beginning of Word
2247       Synopsis:
2248
2249                     [count] w
2250
2251       With the exception that words are used as the delimiter instead of big‐
2252       words, this command shall be equivalent to the W command.
2253
2254   Move to Beginning of Bigword
2255       Synopsis:
2256
2257                     [count] W
2258
2259       If the edit buffer is empty, it shall be an error. If  there  are  less
2260       than  count bigwords between the cursor and the end of the edit buffer,
2261       count shall be adjusted to move the cursor to the last bigword  in  the
2262       edit buffer.
2263
2264       If used as a motion command:
2265
2266        1. If  the associated command is c, count is 1, and the cursor is on a
2267           <blank>, the region of text shall be the current character  and  no
2268           further action shall be taken.
2269
2270        2. If  there  are  less than count bigwords between the cursor and the
2271           end of the edit buffer, then the command  shall  succeed,  and  the
2272           region of text shall include the last character of the edit buffer.
2273
2274        3. If  there are <blank> characters or an end-of-line that precede the
2275           countth bigword, and the associated command is  c,  the  region  of
2276           text  shall  be  up  to and including the last character before the
2277           preceding <blank> characters or end-of-line.
2278
2279        4. If there are <blank> characters or an end-of-line that precede  the
2280           bigword,  and  the associated command is d or y, the region of text
2281           shall be up to and including the last <blank> before the  start  of
2282           the bigword or end-of-line.
2283
2284        5. Any text copied to a buffer shall be in character mode.
2285
2286       If not used as a motion command:
2287
2288        1. If the cursor is on the last character of the edit buffer, it shall
2289           be an error.
2290
2291       Current line: Set to the line containing the current column.
2292
2293       Current column: Set to the last column in which any part of  the  first
2294       character of the countth next bigword is displayed.
2295
2296   Delete Character at Cursor
2297       Synopsis:
2298
2299                     [buffer][count] x
2300
2301       Delete  the  count  characters  at and after the current character into
2302       buffer, if specified, and into the unnamed buffer.
2303
2304       If the line is empty, it shall be an error.  If  there  are  less  than
2305       count  non-<newline>  characters at and after the cursor on the current
2306       line, count shall be adjusted to the number of non-<newline> characters
2307       at and after the cursor.
2308
2309       Current line: Unchanged.
2310
2311       Current  column: If the line is empty, set to column position 1. Other‐
2312       wise, if there were count or less non-<newline> characters at and after
2313       the  cursor  on  the current line, set to the last column that displays
2314       any part of the last non-<newline> of the line. Otherwise, unchanged.
2315
2316   Delete Character Before Cursor
2317       Synopsis:
2318
2319                     [buffer][count] X
2320
2321       Delete the count characters before the current character  into  buffer,
2322       if specified, and into the unnamed buffer.
2323
2324       If  there are no characters before the current character on the current
2325       line, it shall be an error. If there are less than count previous char‐
2326       acters  on  the  current line, count shall be adjusted to the number of
2327       previous characters on the line.
2328
2329       Current line: Unchanged.
2330
2331       Current column: Set to (current column - the width of the deleted char‐
2332       acters).
2333
2334   Yank
2335       Synopsis:
2336
2337                     [buffer][count] y motion
2338
2339       Copy  (yank) the region of text into buffer, if specified, and into the
2340       unnamed buffer.
2341
2342       If the motion command is the y command repeated:
2343
2344        1. The buffer shall be in line mode.
2345
2346        2. If there are less than count -1 lines after the current line in the
2347           edit buffer, it shall be an error.
2348
2349        3. The  text region shall be from the current line up to and including
2350           the next count -1 lines.
2351
2352       Otherwise, the buffer text mode and text region shall be  as  specified
2353       by the motion command.
2354
2355       Current line: If the motion was from the current cursor position toward
2356       the end of the edit buffer, unchanged. Otherwise, set to the first line
2357       in  the  edit  buffer  that is part of the text region specified by the
2358       motion command.
2359
2360       Current column:
2361
2362        1. If the motion was from the current cursor position toward  the  end
2363           of the edit buffer, unchanged.
2364
2365        2. Otherwise, if the current line is empty, set to column position 1.
2366
2367        3. Otherwise,  set  to  the  last column that displays any part of the
2368           first character in the file that is part of the text region  speci‐
2369           fied by the motion command.
2370
2371   Yank Current Line
2372       Synopsis:
2373
2374                     [buffer][count] Y
2375
2376       This command shall be equivalent to the vi command:
2377
2378
2379           [buffer][count] y_
2380
2381   Redraw Window
2382       If in open mode, the z command shall have the Synopsis:
2383
2384       Synopsis:
2385
2386                     [count] z
2387
2388       If  count  is not specified, it shall default to the window edit option
2389       -1. The z command shall be equivalent to the ex z command, with a  type
2390       character  of  =  and a count of count -2, except that the current line
2391       and current column shall be set as follows, and the window edit  option
2392       shall  not be affected. If the calculation for the count argument would
2393       result in a negative number, the count argument to  the  ex  z  command
2394       shall  be  zero.  A  blank line shall be written after the last line is
2395       written.
2396
2397       Current line: Unchanged.
2398
2399       Current column: Unchanged.
2400
2401       If not in open mode, the z command shall have the following Synopsis:
2402
2403       Synopsis:
2404
2405                     [line] z [count] character
2406
2407       If line is not specified, it shall default to the current line. If line
2408       is  specified, but is greater than the number of lines in the edit buf‐
2409       fer, it shall default to the number of lines in the edit buffer.
2410
2411       If count is specified, the value of the window edit option shall be set
2412       to  count (as described in the ex window command), and the screen shall
2413       be redrawn.
2414
2415       line shall be placed as specified by the following characters:
2416
2417       <newline>, <carriage-return>
2418             Place the beginning of the line on the first line of the display.
2419
2420       .     Place the beginning of the line in the center of the display. The
2421             middle  line  of the display shall be calculated as described for
2422             the M command.
2423
2424       -     Place an unspecified portion of the line on the last line of  the
2425             display.
2426
2427       +     If  line was specified, equivalent to the <newline> case. If line
2428             was not specified, display a screen where the first line  of  the
2429             display  shall  be  (current last line) +1. If there are no lines
2430             after the last line in the display, it shall be an error.
2431
2432       ^     If line was specified, display a screen where the  last  line  of
2433             the  display  shall  contain  an unspecified portion of the first
2434             line of a display that had an unspecified portion of  the  speci‐
2435             fied  line  on  the last line of the display. If this calculation
2436             results in a line before the beginning of the edit  buffer,  dis‐
2437             play the first screen of the edit buffer.
2438
2439             Otherwise,  display  a  screen where the last line of the display
2440             shall contain an unspecified portion of (current first line  -1).
2441             If this calculation results in a line before the beginning of the
2442             edit buffer, it shall be an error.
2443
2444       Current line: If line and the '^' character were specified:
2445
2446        1. If the first screen was  displayed  as  a  result  of  the  command
2447           attempting  to  display lines before the beginning of the edit buf‐
2448           fer: if the first screen was already displayed,  unchanged;  other‐
2449           wise, set to (current first line -1).
2450
2451        2. Otherwise, set to the last line of the display.
2452
2453       If  line and the '+' character were specified, set to the first line of
2454       the display.
2455
2456       Otherwise, if line was specified, set to line.
2457
2458       Otherwise, unchanged.
2459
2460       Current column: Set to non-<blank>.
2461
2462   Exit
2463       Synopsis:
2464
2465                     ZZ
2466
2467       This command shall  be  equivalent  to  the  ex  xit  command  with  no
2468       addresses, trailing !, or filename (see the ex xit command).
2469
2470   Input Mode Commands in vi
2471       In  text  input mode, the current line shall consist of zero or more of
2472       the following categories, plus the terminating <newline>:
2473
2474        1. Characters preceding the text input entry point
2475
2476           Characters in this category shall not be modified during text input
2477           mode.
2478
2479        2. autoindent characters
2480
2481           autoindent  characters  shall  be  automatically inserted into each
2482           line that is created in text input mode,  either  as  a  result  of
2483           entering a <newline> or <carriage-return> while in text input mode,
2484           or as an effect of the command itself; for example, O or o (see the
2485           ex autoindent command), as if entered by the user.
2486
2487           It  shall be possible to erase autoindent characters with the <con‐
2488           trol>‐D command; it is unspecified whether they can  be  erased  by
2489           <control>‐H,  <control>‐U,  and <control>‐W characters. Erasing any
2490           autoindent character turns the glyph into erase-columns and deletes
2491           the  character from the edit buffer, but does not change its repre‐
2492           sentation on the screen.
2493
2494        3. Text input characters
2495
2496           Text input characters are the characters entered by the user. Eras‐
2497           ing any text input character turns the glyph into erase-columns and
2498           deletes the character from the edit buffer, but does not change its
2499           representation on the screen.
2500
2501           Each text input character entered by the user (that does not have a
2502           special meaning) shall be treated as follows:
2503
2504            a. The text input character shall be appended to the last  charac‐
2505               ter  in  the edit buffer from the first, second, or third cate‐
2506               gories.
2507
2508            b. If there are no erase-columns on the  screen,  the  text  input
2509               command was the R command, and characters in the fifth category
2510               from the original line follow the cursor, the next such charac‐
2511               ter shall be deleted from the edit buffer. If the slowopen edit
2512               option is not set, the corresponding glyph on the screen  shall
2513               become erase-columns.
2514
2515            c. If  there  are  erase-columns on the screen, as many columns as
2516               they occupy, or as are necessary, shall be overwritten to  dis‐
2517               play  the text input character. (If only part of a multi-column
2518               glyph is overwritten,  the  remainder  shall  be  left  on  the
2519               screen,  and  continue  to  be  treated as erase-columns; it is
2520               unspecified whether the remainder of the glyph is  modified  in
2521               any way.)
2522
2523            d. If  additional  display  line columns are needed to display the
2524               text input character:
2525
2526                i.  If the slowopen edit option is set, the text input charac‐
2527                    ters  shall  be  displayed on subsequent display line col‐
2528                    umns, overwriting any characters displayed in  those  col‐
2529                    umns.
2530
2531               ii.  Otherwise,  any characters currently displayed on or after
2532                    the column on the display line where the text input  char‐
2533                    acter  is to be displayed shall be pushed ahead the number
2534                    of display line columns necessary to display the  rest  of
2535                    the text input character.
2536
2537        4. Erase-columns
2538
2539           Erase-columns  are not logically part of the edit buffer, appearing
2540           only on the screen, and may be overwritten on the screen by  subse‐
2541           quent  text input characters. When text input mode ends, all erase-
2542           columns shall no longer appear on the screen.
2543
2544           Erase-columns are initially the region of text specified by  the  c
2545           command  (see  Change);  however,  erasing autoindent or text input
2546           characters causes the glyphs of the erased characters to be treated
2547           as erase-columns.
2548
2549        5. Characters following the text region for the c command, or the text
2550           input entry point for all other commands
2551
2552           Characters in this category shall not be modified during text input
2553           mode,  except  as  specified  in category 3.b. for the R text input
2554           command, or as <blank> characters deleted when a <newline> or <car‐
2555           riage-return> is entered.
2556
2557       It  is  unspecified whether it is an error to attempt to erase past the
2558       beginning of a line that was created by the entry  of  a  <newline>  or
2559       <carriage-return>  during  text  input mode. If it is not an error, the
2560       editor shall behave as if the erasing character was entered immediately
2561       after  the  last text input character entered on the previous line, and
2562       all of the non-<newline>  characters  on  the  current  line  shall  be
2563       treated as erase-columns.
2564
2565       When  text  input mode is entered, or after a text input mode character
2566       is entered (except as specified for the special characters below),  the
2567       cursor shall be positioned as follows:
2568
2569        1. On  the first column that displays any part of the first erase-col‐
2570           umn, if one exists
2571
2572        2. Otherwise, if the slowopen edit option is set, on the first display
2573           line column after the last character in the first, second, or third
2574           categories, if one exists
2575
2576        3. Otherwise, the first column that displays any  part  of  the  first
2577           character in the fifth category, if one exists
2578
2579        4. Otherwise,  the display line column after the last character in the
2580           first, second, or third categories, if one exists
2581
2582        5. Otherwise, on column position 1
2583
2584       The characters that are updated on the screen during  text  input  mode
2585       are  unspecified,  other  than that the last text input character shall
2586       always be updated, and, if the slowopen edit option  is  not  set,  the
2587       current cursor character shall always be updated.
2588
2589       The  following specifications are for command characters entered during
2590       text input mode.
2591
2592   NUL
2593       Synopsis:
2594
2595                     NUL
2596
2597       If the first character of the text input is a NUL,  the  most  recently
2598       input  text  shall  be  input  as if entered by the user, and then text
2599       input mode shall be exited. The text shall be input literally; that is,
2600       characters  are  neither  macro  or  abbreviation expanded, nor are any
2601       characters interpreted in any special manner. It is unspecified whether
2602       implementations  shall  support more than 256 bytes of remembered input
2603       text.
2604
2605   <control>-D
2606       Synopsis:
2607
2608                     <control>-D
2609
2610       The <control>‐D character shall have no special meaning  when  in  text
2611       input  mode  for  a  line-oriented command (see Command Descriptions in
2612       vi).
2613
2614       This command need not be supported on block-mode terminals.
2615
2616       If the cursor does not follow an autoindent character, or an autoindent
2617       character and a '0' or '^' character:
2618
2619        1. If  the  cursor  is in column position 1, the <control>‐D character
2620           shall be discarded and no further action taken.
2621
2622        2. Otherwise, the <control>‐D character shall have no special meaning.
2623
2624       If the last input character was a '0', the cursor  shall  be  moved  to
2625       column position 1.
2626
2627       Otherwise,  if  the last input character was a '^', the cursor shall be
2628       moved to column position 1. In addition, the autoindent level  for  the
2629       next  input  line  shall  be  derived from the same line from which the
2630       autoindent level for the current input line was derived.
2631
2632       Otherwise, the cursor shall be moved back to the column after the  pre‐
2633       vious shiftwidth (see the ex shiftwidth command) boundary.
2634
2635       All  of  the glyphs on columns between the starting cursor position and
2636       (inclusively) the ending cursor position shall become erase-columns  as
2637       described in Input Mode Commands in vi.
2638
2639       Current line: Unchanged.
2640
2641       Current  column:  Set  to 1 if the <control>‐D was preceded by a '^' or
2642       '0'; otherwise, set to (column -1) -((column -2) % shiftwidth).
2643
2644   <control>-H
2645       Synopsis:
2646
2647                     <control>-H
2648
2649       If in text input mode for a line-oriented command,  and  there  are  no
2650       characters  to  erase,  text input mode shall be terminated, no further
2651       action shall be done for this command, and the current line and  column
2652       shall be unchanged.
2653
2654       If there are characters other than autoindent characters that have been
2655       input on the current line before the cursor, the cursor shall move back
2656       one character.
2657
2658       Otherwise,  if  there  are  autoindent  characters  on the current line
2659       before the cursor, it is implementation-defined whether the <control>‐H
2660       command  is an error or if the cursor moves back one autoindent charac‐
2661       ter.
2662
2663       Otherwise, if the cursor is in column position 1 and there are previous
2664       lines  that  have  been input, it is implementation-defined whether the
2665       <control>‐H command is an error or if  it  is  equivalent  to  entering
2666       <control>‐H after the last input character on the previous input line.
2667
2668       Otherwise, it shall be an error.
2669
2670       All  of  the glyphs on columns between the starting cursor position and
2671       (inclusively) the ending cursor position shall become erase-columns  as
2672       described in Input Mode Commands in vi.
2673
2674       The current erase character (see stty) shall cause an equivalent action
2675       to the <control>‐H command, unless the  previously  inserted  character
2676       was  a <backslash>, in which case it shall be as if the literal current
2677       erase character had been inserted instead of the <backslash>.
2678
2679       Current line: Unchanged, unless previously input lines are  erased,  in
2680       which case it shall be set to line -1.
2681
2682       Current  column:  Set  to the first column that displays any portion of
2683       the character backed up over.
2684
2685   <newline>
2686       Synopsis:
2687
2688                     <newline>
2689                     <carriage-return>
2690                     <control>-J
2691                     <control>-M
2692
2693       If input was part of a line-oriented command, text input mode shall  be
2694       terminated and the command shall continue execution with the input pro‐
2695       vided.
2696
2697       Otherwise, terminate the current line. If there are no characters other
2698       than  autoindent  characters  on  the  line, all characters on the line
2699       shall be discarded.  Otherwise, it is unspecified whether  the  autoin‐
2700       dent characters in the line are modified by entering these characters.
2701
2702       Continue text input mode on a new line appended after the current line.
2703       If the slowopen edit option is set, the lines on the screen  below  the
2704       current  line  shall not be pushed down, but the first of them shall be
2705       cleared and shall appear to be overwritten. Otherwise, the lines of the
2706       screen below the current line shall be pushed down.
2707
2708       If  the autoindent edit option is set, an appropriate number of autoin‐
2709       dent characters shall be added as a prefix to the line as described  by
2710       the ex autoindent edit option.
2711
2712       All  columns  after  the cursor that are erase-columns (as described in
2713       Input Mode Commands in vi) shall be discarded.
2714
2715       If the autoindent edit option is set, all  <blank>  characters  immedi‐
2716       ately following the cursor shall be discarded.
2717
2718       All  remaining  characters after the cursor shall be transferred to the
2719       new line, positioned after any autoindent characters.
2720
2721       Current line: Set to current line +1.
2722
2723       Current column: Set to the first column that displays  any  portion  of
2724       the first character after the autoindent characters on the new line, if
2725       any, or the first column position after the last autoindent  character,
2726       if any, or column position 1.
2727
2728   <control>-T
2729       Synopsis:
2730
2731                     <control>-T
2732
2733       The  <control>‐T  character  shall have no special meaning when in text
2734       input mode for a line-oriented command  (see  Command  Descriptions  in
2735       vi).
2736
2737       This command need not be supported on block-mode terminals.
2738
2739       Behave  as if the user entered the minimum number of <blank> characters
2740       necessary to move the cursor forward to the column position  after  the
2741       next shiftwidth (see the ex shiftwidth command) boundary.
2742
2743       Current line: Unchanged.
2744
2745       Current   column:   Set  to  column  +  shiftwidth  -  ((column  -1)  %
2746       shiftwidth).
2747
2748   <control>-U
2749       Synopsis:
2750
2751                     <control>-U
2752
2753       If there are characters other than autoindent characters that have been
2754       input  on  the current line before the cursor, the cursor shall move to
2755       the first character input after the autoindent characters.
2756
2757       Otherwise, if there are  autoindent  characters  on  the  current  line
2758       before the cursor, it is implementation-defined whether the <control>‐U
2759       command is an error or if the cursor moves to the first column position
2760       on the line.
2761
2762       Otherwise, if the cursor is in column position 1 and there are previous
2763       lines that have been input, it is  implementation-defined  whether  the
2764       <control>‐U  command  is  an  error  or if it is equivalent to entering
2765       <control>‐U after the last input character on the previous input line.
2766
2767       Otherwise, it shall be an error.
2768
2769       All of the glyphs on columns between the starting cursor  position  and
2770       (inclusively)  the ending cursor position shall become erase-columns as
2771       described in Input Mode Commands in vi.
2772
2773       The current kill character (see stty) shall cause an equivalent  action
2774       to  the  <control>‐U  command, unless the previously inserted character
2775       was a <backslash>, in which case it shall be as if the literal  current
2776       kill character had been inserted instead of the <backslash>.
2777
2778       Current  line:  Unchanged, unless previously input lines are erased, in
2779       which case it shall be set to line -1.
2780
2781       Current column: Set to the first column that displays  any  portion  of
2782       the last character backed up over.
2783
2784   <control>-V
2785       Synopsis:
2786
2787                     <control>-V
2788                     <control>-Q
2789
2790       Allow  the entry of any subsequent character, other than <control>‐J or
2791       the <newline>, as a literal character,  removing  any  special  meaning
2792       that  it may have to the editor in text input mode. If a <control>‐V or
2793       <control>‐Q is entered before a <control>‐J  or  <newline>,  the  <con‐
2794       trol>‐V  or  <control>‐Q  character  shall  be discarded, and the <con‐
2795       trol>‐J or <newline> shall behave as described in the <newline> command
2796       character during input mode.
2797
2798       For  purposes  of the display only, the editor shall behave as if a '^'
2799       character was entered, and the cursor shall be positioned as  if  over‐
2800       writing  the '^' character. When a subsequent character is entered, the
2801       editor shall behave as if that character was  entered  instead  of  the
2802       original <control>‐V or <control>‐Q character.
2803
2804       Current line: Unchanged.
2805
2806       Current column: Unchanged.
2807
2808   <control>-W
2809       Synopsis:
2810
2811                     <control>-W
2812
2813       If there are characters other than autoindent characters that have been
2814       input on the current line before the cursor, the cursor shall move back
2815       over  the last word preceding the cursor (including any <blank> charac‐
2816       ters between the end of the last word and the current cursor); the cur‐
2817       sor  shall  not move to before the first character after the end of any
2818       autoindent characters.
2819
2820       Otherwise, if there are  autoindent  characters  on  the  current  line
2821       before the cursor, it is implementation-defined whether the <control>‐W
2822       command is an error or if the cursor moves to the first column position
2823       on the line.
2824
2825       Otherwise, if the cursor is in column position 1 and there are previous
2826       lines that have been input, it is  implementation-defined  whether  the
2827       <control>‐W  command  is  an  error  or if it is equivalent to entering
2828       <control>‐W after the last input character on the previous input line.
2829
2830       Otherwise, it shall be an error.
2831
2832       All of the glyphs on columns between the starting cursor  position  and
2833       (inclusively)  the ending cursor position shall become erase-columns as
2834       described in Input Mode Commands in vi.
2835
2836       Current line: Unchanged, unless previously input lines are  erased,  in
2837       which case it shall be set to line -1.
2838
2839       Current  column:  Set  to the first column that displays any portion of
2840       the last character backed up over.
2841
2842   <ESC>
2843       Synopsis:
2844
2845                     <ESC>
2846
2847       If input was part of a line-oriented command:
2848
2849        1. If interrupt was entered, text input mode shall be  terminated  and
2850           the  editor  shall  return  to  command mode. The terminal shall be
2851           alerted.
2852
2853        2. If <ESC> was entered, text input mode shall be terminated  and  the
2854           command shall continue execution with the input provided.
2855
2856       Otherwise, terminate text input mode and return to command mode.
2857
2858       Any  autoindent  characters entered on newly created lines that have no
2859       other non-<newline> characters shall be deleted.
2860
2861       Any leading autoindent and <blank> characters on  newly  created  lines
2862       shall  be rewritten to be the minimum number of <blank> characters pos‐
2863       sible.
2864
2865       The screen shall be redisplayed as necessary to match the  contents  of
2866       the edit buffer.
2867
2868       Current line: Unchanged.
2869
2870       Current column:
2871
2872        1. If  there are text input characters on the current line, the column
2873           shall be set to the last column where any portion of the last  text
2874           input character is displayed.
2875
2876        2. Otherwise,  if  a  character  is  displayed  in the current column,
2877           unchanged.
2878
2879        3. Otherwise, set to column position 1.
2880

EXIT STATUS

2882       The following exit values shall be returned:
2883
2884        0    Successful completion.
2885
2886       >0    An error occurred.
2887

CONSEQUENCES OF ERRORS

2889       When any error is encountered and the standard input is not a  terminal
2890       device  file,  vi shall not write the file or return to command or text
2891       input mode, and shall terminate with a non-zero exit status.
2892
2893       Otherwise, when an unrecoverable  error  is  encountered  it  shall  be
2894       equivalent to a SIGHUP asynchronous event.
2895
2896       Otherwise,  when  an  error  is encountered, the editor shall behave as
2897       specified in Command Descriptions in vi.
2898
2899       The following sections are informative.
2900

APPLICATION USAGE

2902       None.
2903

EXAMPLES

2905       None.
2906

RATIONALE

2908       See the RATIONALE for ex for more information on vi.  Major portions of
2909       the  vi  utility  specification point to ex to avoid inadvertent diver‐
2910       gence. While ex and vi have historically been implemented as  a  single
2911       utility, this is not required by POSIX.1‐2008.
2912
2913       It  is recognized that portions of vi would be difficult, if not impos‐
2914       sible, to implement satisfactorily on a block-mode terminal, or a  ter‐
2915       minal without any form of cursor addressing, thus it is not a mandatory
2916       requirement that such features should work on all terminals. It is  the
2917       intention,  however,  that  a vi implementation should provide the full
2918       set of capabilities on all terminals capable of supporting them.
2919
2920       Historically, vi exited immediately if the standard  input  was  not  a
2921       terminal. POSIX.1‐2008 permits, but does not require, this behavior. An
2922       end-of-file condition is not equivalent to an end-of-file character.  A
2923       common  end-of-file  character,  <control>‐D, is historically a vi com‐
2924       mand.
2925
2926       The text in the STDOUT section reflects the usage of the  verb  display
2927       in  this  section;  some  implementations  of vi use standard output to
2928       write to the terminal, but POSIX.1‐2008 does not require that to be the
2929       case.
2930
2931       Historically, implementations reverted to open mode if the terminal was
2932       incapable of supporting full visual mode.  POSIX.1‐2008  requires  this
2933       behavior.  Historically,  the  open  mode of vi behaved roughly equiva‐
2934       lently to the visual mode, with the exception that only a  single  line
2935       from  the  edit  buffer  (one  ``buffer line'') was kept current at any
2936       time. This line was normally displayed on the next-to-last  line  of  a
2937       terminal with cursor addressing (and the last line performed its normal
2938       visual functions for line-oriented commands and messages). In addition,
2939       some few commands behaved differently in open mode than in visual mode.
2940       POSIX.1‐2008 requires conformance to historical practice.
2941
2942       Historically, ex and vi implementations have expected text  to  proceed
2943       in  the  usual  European/Latin  order  of left to right, top to bottom.
2944       There is no requirement in POSIX.1‐2008 that  this  be  the  case.  The
2945       specification  was  deliberately  written  using words like ``before'',
2946       ``after'', ``first'', and ``last'' in order to  permit  implementations
2947       to support the natural text order of the language.
2948
2949       Historically,  lines  past  the end of the edit buffer were marked with
2950       single <tilde> ('~') characters; that is, if the one-based display  was
2951       20 lines in length, and the last line of the file was on line one, then
2952       lines 2-20 would contain only a single '~' character.
2953
2954       Historically, the vi editor attempted to display only complete lines at
2955       the  bottom  of  the screen (it did display partial lines at the top of
2956       the screen). If a line was too long to fit in its entirety at the  bot‐
2957       tom of the screen, the screen lines where the line would have been dis‐
2958       played were displayed as single '@' characters, instead  of  displaying
2959       part  of  the  line.  POSIX.1‐2008  permits, but does not require, this
2960       behavior. Implementations are encouraged to attempt always to display a
2961       complete  line  at  the  bottom  of  the screen when doing scrolling or
2962       screen positioning by buffer lines.
2963
2964       Historically, lines marked with '@' were also used to  minimize  output
2965       to dumb terminals over slow lines; that is, changes local to the cursor
2966       were updated, but changes to lines on the screen that were not close to
2967       the cursor were simply marked with an '@' sign instead of being updated
2968       to match the current text. POSIX.1‐2008 permits, but does  not  require
2969       this  feature  because  it  is  used  ever less frequently as terminals
2970       become smarter and connections are faster.
2971
2972   Initialization in ex and vi
2973       Historically, vi always had a line in the edit buffer, even if the edit
2974       buffer was ``empty''. For example:
2975
2976        1. The  ex  command  =  executed from visual mode wrote ``1'' when the
2977           buffer was empty.
2978
2979        2. Writes from visual mode of an empty edit buffer wrote  files  of  a
2980           single  character  (a  <newline>),  while writes from ex mode of an
2981           empty edit buffer wrote empty files.
2982
2983        3. Put and read commands into an empty edit buffer left an empty  line
2984           at the top of the edit buffer.
2985
2986       For consistency, POSIX.1‐2008 does not permit any of these behaviors.
2987
2988       Historically,  vi  did  not  always return the terminal to its original
2989       modes; for example, ICRNL was modified if it was  not  originally  set.
2990       POSIX.1‐2008 does not permit this behavior.
2991
2992   Command Descriptions in vi
2993       Motion  commands  are  among  the  most  complicated  aspects  of vi to
2994       describe. With some exceptions, the text region and buffer type  effect
2995       of  a  motion  command  on a vi command are described on a case-by-case
2996       basis. The  descriptions  of  text  regions  in  POSIX.1‐2008  are  not
2997       intended  to  imply direction; that is, an inclusive region from line n
2998       to line n+5 is identical to a region from line n+5 to line n.  This  is
2999       of  more  than  academic  interest—movements  to marks can be in either
3000       direction, and, if the wrapscan option is  set,  so  can  movements  to
3001       search  points.  Historically,  lines are always stored into buffers in
3002       text order; that is, from the start of the  edit  buffer  to  the  end.
3003       POSIX.1‐2008 requires conformance to historical practice.
3004
3005       Historically, command counts were applied to any associated motion, and
3006       were multiplicative to any supplied motion count. For example,  2cw  is
3007       the  same  as  c2w, and 2c3w is the same as c6w.  POSIX.1‐2008 requires
3008       this behavior. Historically, vi commands  that  used  bigwords,  words,
3009       paragraphs,  and sentences as objects treated groups of empty lines, or
3010       lines that contained only <blank> characters, inconsistently. Some com‐
3011       mands  treated  them as a single entity, while others treated each line
3012       separately. For example, the w, W, and B  commands  treated  groups  of
3013       empty  lines  as  individual words; that is, the command would move the
3014       cursor to each new empty line. The e and E commands treated  groups  of
3015       empty  lines  as  a single word; that is, the first use would move past
3016       the group of lines. The b command would just beep at the  user,  or  if
3017       done from the start of the line as a motion command, fail in unexpected
3018       ways. If the lines contained only (or ended with)  <blank>  characters,
3019       the  w and W commands would just beep at the user, the E and e commands
3020       would treat the group as a single word, and the B and b commands  would
3021       treat  the lines as individual words. For consistency and simplicity of
3022       specification, POSIX.1‐2008 requires that all vi commands treat  groups
3023       of  empty  or blank lines as a single entity, and that movement through
3024       lines ending with <blank> characters be  consistent  with  other  move‐
3025       ments.
3026
3027       Historically,  vi  documentation  indicated  that any number of double-
3028       quotes were skipped after punctuation  marks  at  sentence  boundaries;
3029       however,   implementations  only  skipped  single-quotes.  POSIX.1‐2008
3030       requires both to be skipped.
3031
3032       Historically, the first and last characters in  the  edit  buffer  were
3033       word boundaries. This historical practice is required by POSIX.1‐2008.
3034
3035       Historically,  vi  attempted to update the minimum number of columns on
3036       the screen possible, which could lead to misleading  information  being
3037       displayed.  POSIX.1‐2008 makes no requirements other than that the cur‐
3038       rent character being entered is displayed correctly, leaving all  other
3039       decisions in this area up to the implementation.
3040
3041       Historically,  lines  were  arbitrarily  folded  between columns of any
3042       characters that required multiple column positions on the screen,  with
3043       the  exception  of  tabs,  which  terminated  at the right-hand margin.
3044       POSIX.1‐2008 permits the former and requires  the  latter.  Implementa‐
3045       tions that do not arbitrarily break lines between columns of characters
3046       that occupy multiple column positions should not permit the  cursor  to
3047       rest on a column that does not contain any part of a character.
3048
3049       The  historical  vi  had a problem in that all movements were by buffer
3050       lines, not by display or screen lines. This is often the right thing to
3051       do;  for example, single line movements, such as j or k, should work on
3052       buffer lines. Commands like dj, or j., where .  is  a  change  command,
3053       only  make  sense for buffer lines. It is not, however, the right thing
3054       to do for screen motion or scrolling commands like  <control>‐D,  <con‐
3055       trol>‐F,  and  H.  If the window is fairly small, using buffer lines in
3056       these cases can result in completely random motion; for example, 1<con‐
3057       trol>‐D can result in a completely changed screen, without any overlap.
3058       This is clearly not what the user wanted. The problem is even worse  in
3059       the case of the H, L, and M commands—as they position the cursor at the
3060       first non-<blank> of the line, they may all refer to the same  location
3061       in large lines, and will result in no movement at all.
3062
3063       In  addition, if the line is larger than the screen, using buffer lines
3064       can make it impossible to display parts of the line—there are  not  any
3065       commands  that  do  not display the beginning of the line in historical
3066       vi, and if both the beginning and end of the  line  cannot  be  on  the
3067       screen  at the same time, the user suffers. Finally, the page and half-
3068       page scrolling commands historically moved to the first non-<blank>  in
3069       the new line. If the line is approximately the same size as the screen,
3070       this is inadequate because the cursor before and  after  a  <control>‐D
3071       command will refer to the same location on the screen.
3072
3073       Implementations  of  ex  and  vi  exist that do not have these problems
3074       because the relevant commands (<control>‐B,  <control>‐D,  <control>‐F,
3075       <control>‐U,  <control>‐Y, <control>‐E, H, L, and M) operate on display
3076       (screen) lines, not (edit) buffer lines.
3077
3078       POSIX.1‐2008 does not permit this behavior by default because the stan‐
3079       dard  developers  believed that users would find it too confusing. How‐
3080       ever, historical practice has been relaxed. For example, ex and vi his‐
3081       torically attempted, albeit sometimes unsuccessfully, to never put part
3082       of a line on the last lines of a screen; for example, if a  line  would
3083       not  fit  in  its  entirety, no part of the line was displayed, and the
3084       screen lines corresponding to the line contained single '@' characters.
3085       This  behavior  is permitted, but not required by POSIX.1‐2008, so that
3086       it is possible for implementations  to  support  long  lines  in  small
3087       screens more reasonably without changing the commands to be oriented to
3088       the display (instead of oriented to the buffer). POSIX.1‐2008 also per‐
3089       mits  implementations  to  refuse  to edit any edit buffer containing a
3090       line that will not fit on the screen in its entirety.
3091
3092       The display area (for example, the value of the window edit option) has
3093       historically  been  ``grown'',  or  expanded,  to display new text when
3094       local movements are done in displays where the  number  of  lines  dis‐
3095       played  is  less  than the maximum possible. Expansion has historically
3096       been the first choice, when the target line is less  than  the  maximum
3097       possible expansion value away. Scrolling has historically been the next
3098       choice, done when the target line is less than half a display away, and
3099       otherwise,  the  screen was redrawn. There were exceptions, however, in
3100       that ex commands generally always caused  the  screen  to  be  redrawn.
3101       POSIX.1‐2008  does not specify a standard behavior because there may be
3102       external issues, such as connection speed,  the  number  of  characters
3103       necessary to redraw as opposed to scroll, or terminal capabilities that
3104       implementations will have to accommodate.
3105
3106       The current line in POSIX.1‐2008 maps one-to-one to a  buffer  line  in
3107       the  file.  The current column does not. There are two different column
3108       values that are described by POSIX.1‐2008. The  first  is  the  current
3109       column  value  as  set by many of the vi commands. This value is remem‐
3110       bered for the lifetime of the editor. The second column  value  is  the
3111       actual  position  on the screen where the cursor rests. The two are not
3112       always the same. For example, when the cursor is backed by a multi-col‐
3113       umn  character,  the  actual cursor position on the screen has histori‐
3114       cally been the last column of the character in command  mode,  and  the
3115       first column of the character in input mode.
3116
3117       Commands  that  set  the  current line, but that do not set the current
3118       cursor value (for example, j and k) attempt to get as close as possible
3119       to the remembered column position, so that the cursor tends to restrict
3120       itself to a vertical column as the user moves around in the  edit  buf‐
3121       fer.  POSIX.1‐2008 requires conformance to historical practice, requir‐
3122       ing that the display location of the cursor  on  the  display  line  be
3123       adjusted  from  the  current  column value as necessary to support this
3124       historical behavior.
3125
3126       Historically, only a single line (and for some terminals, a single line
3127       minus  1  column)  of  characters  could be entered by the user for the
3128       line-oriented commands; that is, :, !, /, or ?.  POSIX.1‐2008  permits,
3129       but does not require, this limitation.
3130
3131       Historically,  ``soft'' errors in vi caused the terminal to be alerted,
3132       but no error message was displayed.  As a general rule, no  error  mes‐
3133       sage  was  displayed  for  errors  in command execution in vi, when the
3134       error resulted from  the  user  attempting  an  invalid  or  impossible
3135       action,  or when a searched-for object was not found.  Examples of soft
3136       errors included h at the left margin, <control>‐B or [[ at  the  begin‐
3137       ning  of  the  file, 2G at the end of the file, and so on. In addition,
3138       errors such as %, ]], }, ), N, n, f, F, t, and T failing  to  find  the
3139       searched-for object were soft as well. Less consistently, / and ?  dis‐
3140       played an error message if the pattern was not found, /, ?,  N,  and  n
3141       displayed  an  error message if no previous regular expression had been
3142       specified, and ; did not display an error message if no previous f,  F,
3143       t, or T command had occurred. Also, behavior in this area might reason‐
3144       ably be based on a runtime evaluation of the speed of a network connec‐
3145       tion.   Finally,  some implementations have provided error messages for
3146       soft errors in order to assist naive users, based on  the  value  of  a
3147       verbose  edit  option.  POSIX.1‐2008  does not list specific errors for
3148       which an error message shall be displayed. Implementations should  con‐
3149       form  to  historical  practice  in  the absence of any strong reason to
3150       diverge.
3151
3152   Page Backwards
3153       The <control>‐B and <control>‐F commands historically considered it  an
3154       error to attempt to page past the beginning or end of the file, whereas
3155       the <control>‐D and <control>‐U commands simply moved to the  beginning
3156       or  end  of the file. For consistency, POSIX.1‐2008 requires the latter
3157       behavior for all four commands.  All four commands still consider it an
3158       error  if  the  current  line  is  at the beginning (<control>‐B, <con‐
3159       trol>‐U) or end (<control>‐F, <control>‐D) of the  file.  Historically,
3160       the  <control>‐B  and  <control>‐F  commands skip two lines in order to
3161       include overlapping lines when a single command is entered. This  makes
3162       less sense in the presence of a count, as there will be, by definition,
3163       no overlapping lines. The actual calculation used by historical  imple‐
3164       mentations of the vi editor for <control>‐B was:
3165
3166
3167           ((current first line) - count x (window edit option)) +2
3168
3169       and for <control>‐F was:
3170
3171
3172           ((current first line) + count x (window edit option)) -2
3173
3174       This  calculation does not work well when intermixing commands with and
3175       without counts; for example, 3<control>‐F is not equivalent to entering
3176       the  <control>‐F command three times, and is not reversible by entering
3177       the <control>‐B command three times. For consistency with other vi com‐
3178       mands that take counts, POSIX.1‐2008 requires a different calculation.
3179
3180   Scroll Forward
3181       The  4BSD  and  System  V implementations of vi differed on the initial
3182       value used by the scroll command. 4BSD used:
3183
3184
3185           ((window edit option) +1) /2
3186
3187       while System V used the value of the scroll edit option. The  System  V
3188       version  is  specified  by POSIX.1‐2008 because the standard developers
3189       believed that it was more intuitive and permitted the user a method  of
3190       setting  the  scroll value initially without also setting the number of
3191       lines that are displayed.
3192
3193   Scroll Forward by Line
3194       Historically, the <control>‐E and <control>‐Y commands considered it an
3195       error  if  the  last and first lines, respectively, were already on the
3196       screen. POSIX.1‐2008 requires conformance to historical practice.  His‐
3197       torically,  the  <control>‐E  and <control>‐Y commands had no effect in
3198       open  mode.  For   simplicity   and   consistency   of   specification,
3199       POSIX.1‐2008  requires  that they behave as usual, albeit with a single
3200       line screen.
3201
3202   Clear and Redisplay
3203       The historical <control>‐L command refreshed the screen exactly  as  it
3204       was  supposed  to  be currently displayed, replacing any '@' characters
3205       for lines that had been deleted but not  updated  on  the  screen  with
3206       refreshed  '@'  characters. The intent of the <control>‐L command is to
3207       refresh when the screen has been accidentally overwritten; for example,
3208       by a write command from another user, or modem noise.
3209
3210   Redraw Screen
3211       The  historical  <control>‐R command redisplayed only when necessary to
3212       update lines that had been deleted but not updated on  the  screen  and
3213       that were flagged with '@' characters. There is no requirement that the
3214       screen be in any way refreshed if no lines of this form  are  currently
3215       displayed.  POSIX.1‐2008 permits implementations to extend this command
3216       to refresh lines on the screen flagged with '@' characters because they
3217       are  too  long  to  be displayed in the current framework; however, the
3218       current line and column need not be modified.
3219
3220   Search for tagstring
3221       Historically, the first non-<blank> at or  after  the  cursor  was  the
3222       first  character,  and all subsequent characters that were word charac‐
3223       ters, up to the end of the line, were included. For example,  with  the
3224       cursor  on  the  leading  <space>  or  on the '#' character in the text
3225       "#bar@", the tag was "#bar".  On the character 'b' it was "bar", and on
3226       the 'a' it was "ar".  POSIX.1‐2008 requires this behavior.
3227
3228   Replace Text with Results from Shell Command
3229       Historically,  the <, >, and !  commands considered most cursor motions
3230       other than line-oriented motions an error;  for  example,  the  command
3231       >/foo<CR>  succeeded, while the command >l failed, even though the text
3232       region described by the two commands might be  identical.  For  consis‐
3233       tency,  all  three  commands only consider entire lines and not partial
3234       lines, and the region is defined as any line that contains a  character
3235       that was specified by the motion.
3236
3237   Move to Matching Character
3238       Other  matching  characters  have  been  left implementation-defined in
3239       order to allow extensions such as matching '<' and  '>'  for  searching
3240       HTML, or #ifdef, #else, and #endif for searching C source.
3241
3242   Repeat Substitution
3243       POSIX.1‐2008  requires that any c and g flags specified to the previous
3244       substitute command be ignored; however, the r flag may still apply,  if
3245       supported by the implementation.
3246
3247   Return to Previous (Context or Section)
3248       The  [[,  ]],  (,  ),  {,  and } commands are all affected by ``section
3249       boundaries'', but in some historical implementations  not  all  of  the
3250       commands  recognize  the  same section boundaries. This is a bug, not a
3251       feature, and a unique section-boundary algorithm was not described  for
3252       each  command.  One special case that is preserved is that the sentence
3253       command moves to the end of the last line of the edit buffer while  the
3254       other  commands  go  to  the beginning, in order to preserve the tradi‐
3255       tional character cut semantics of the sentence  command.  Historically,
3256       vi  section boundaries at the beginning and end of the edit buffer were
3257       the first non-<blank> on the first and last lines of the edit buffer if
3258       one  exists;  otherwise, the last character of the first and last lines
3259       of the edit buffer if one exists. To increase  consistency  with  other
3260       section  locations,  this  has  been  simplified by POSIX.1‐2008 to the
3261       first character of the first and last lines of the edit buffer, or  the
3262       first and the last lines of the edit buffer if they are empty.
3263
3264       Sentence  boundaries  were problematic in the historical vi.  They were
3265       not only the boundaries as defined for the section and  paragraph  com‐
3266       mands,  but  they  were the first non-<blank> that occurred after those
3267       boundaries, as well. Historically, the vi section commands  were  docu‐
3268       mented  as taking an optional window size as a count preceding the com‐
3269       mand. This was not implemented in historical versions, so  POSIX.1‐2008
3270       requires  that the count repeat the command, for consistency with other
3271       vi commands.
3272
3273   Repeat
3274       Historically, mapped commands other than text input commands could  not
3275       be repeated using the period command. POSIX.1‐2008 requires conformance
3276       to historical practice.
3277
3278       The restrictions on the interpretation of special characters (for exam‐
3279       ple,  <control>‐H)  in  the  repetition  of text input mode commands is
3280       intended to match historical practice. For  example,  given  the  input
3281       sequence:
3282
3283
3284           iab<control>-H<control>-H<control>-Hdef<escape>
3285
3286       the  user  should  be  informed  of an error when the sequence is first
3287       entered, but not during a command repetition. The character <control>‐T
3288       is  specifically exempted from this restriction. Historical implementa‐
3289       tions of vi ignored <control>‐T characters that were input in the orig‐
3290       inal  command  during  command  repetition. POSIX.1‐2008 prohibits this
3291       behavior.
3292
3293   Find Regular Expression
3294       Historically, commands did not affect the line searched to or  from  if
3295       the motion command was a search (/, ?, N, n) and the final position was
3296       the start/end of the line. There were some special cases and vi was not
3297       consistent.  POSIX.1‐2008  does  not  permit this behavior, for consis‐
3298       tency. Historical implementations permitted but were unable  to  handle
3299       searches  as  motion  commands  that  wrapped (that is, due to the edit
3300       option wrapscan) to the original location. POSIX.1‐2008  requires  that
3301       this behavior be treated as an error.
3302
3303       Historically,  the  syntax "/RE/0" was used to force the command to cut
3304       text in line mode.  POSIX.1‐2008  requires  conformance  to  historical
3305       practice.
3306
3307       Historically,  in  open  mode, a z specified to a search command redis‐
3308       played the current line instead of displaying the current  screen  with
3309       the  current line highlighted. For consistency and simplicity of speci‐
3310       fication, POSIX.1‐2008 does not permit this behavior.
3311
3312       Historically, trailing z commands were permitted and ignored if entered
3313       as  part of a search used as a motion command. For consistency and sim‐
3314       plicity of specification, POSIX.1‐2008 does not permit this behavior.
3315
3316   Execute an ex Command
3317       Historically, vi implementations restricted the commands that could  be
3318       entered on the colon command line (for example, append and change), and
3319       some other commands were known to cause them to fail  catastrophically.
3320       For  consistency, POSIX.1‐2008 does not permit these restrictions. When
3321       executing an ex command by entering :, it is not possible  to  enter  a
3322       <newline>  as  part  of the command because it is considered the end of
3323       the command.  A different approach is to enter ex command mode by using
3324       the  vi  Q  command (and later resuming visual mode with the ex vi com‐
3325       mand). In ex command mode, the single-line limitation does  not  exist.
3326       So, for example, the following is valid:
3327
3328
3329           Q
3330           s/break here/break\
3331           here/
3332           vi
3333
3334       POSIX.1‐2008  requires  that,  if the ex command overwrites any part of
3335       the screen that would be erased by a refresh, vi pauses for a character
3336       from the user. Historically, this character could be any character; for
3337       example, a character input by the user before the message appeared,  or
3338       even  a  mapped  character. This is probably a bug, but implementations
3339       that have tried to be more rigorous by requiring that the user enter  a
3340       specific  character,  or that the user enter a character after the mes‐
3341       sage was displayed, have been forced by user indignation back into his‐
3342       torical behavior. POSIX.1‐2008 requires conformance to historical prac‐
3343       tice.
3344
3345   Shift Left (Right)
3346       Refer to the Rationale for the !  and / commands. Historically,  the  <
3347       and > commands sometimes moved the cursor to the first non-<blank> (for
3348       example if the command was repeated or with _ as the  motion  command),
3349       and  sometimes  left  it  unchanged.  POSIX.1‐2008 does not permit this
3350       inconsistency, requiring instead that the cursor  always  move  to  the
3351       first  non-<blank>.  Historically, the < and > commands did not support
3352       buffer arguments, although some implementations allow the specification
3353       of an optional buffer. This behavior is neither required nor disallowed
3354       by POSIX.1‐2008.
3355
3356   Execute
3357       Historically, buffers could execute other buffers, and loops,  infinite
3358       and otherwise, were possible. POSIX.1‐2008 requires conformance to his‐
3359       torical practice. The *buffer syntax of  ex  is  not  required  in  vi,
3360       because  it  is  not  historical  practice and has been used in some vi
3361       implementations to support additional scripting languages.
3362
3363   Reverse Case
3364       Historically, the ~ command ignored any  associated  count,  and  acted
3365       only  on the characters in the current line. For consistency with other
3366       vi commands, POSIX.1‐2008 requires that an associated count act on  the
3367       next count characters, and that the command move to subsequent lines if
3368       warranted by count, to make it possible to modify large pieces of  text
3369       in  a  reasonably efficient manner. There exist vi implementations that
3370       optionally require an associated motion  command  for  the  ~  command.
3371       Implementations supporting this functionality are encouraged to base it
3372       on the tildedop edit option and handle  the  text  regions  and  cursor
3373       positioning identically to the yank command.
3374
3375   Append
3376       Historically,  counts specified to the A, a, I, and i commands repeated
3377       the input of the first line count times, and did not repeat the  subse‐
3378       quent  lines  of  the input text. POSIX.1‐2008 requires that the entire
3379       text input be repeated count times.
3380
3381   Move Backward to Preceding Word
3382       Historically, vi became confused if word commands were used  as  motion
3383       commands  in  empty files. POSIX.1‐2008 requires that this be an error.
3384       Historical implementations of vi had a large number of bugs in the word
3385       movement  commands, and they varied greatly in behavior in the presence
3386       of empty lines, ``words'' made up of a single character, and lines con‐
3387       taining  only  <blank>  characters.  For  consistency and simplicity of
3388       specification, POSIX.1‐2008 does not permit this behavior.
3389
3390   Change to End-of-Line
3391       Some historical implementations of the C  command  did  not  behave  as
3392       described by POSIX.1‐2008 when the $ key was remapped because they were
3393       implemented by pushing the $ key onto the input queue and  reprocessing
3394       it. POSIX.1‐2008 does not permit this behavior. Historically, the C, S,
3395       and s commands did not copy replaced text into the numeric buffers. For
3396       consistency and simplicity of specification, POSIX.1‐2008 requires that
3397       they behave like their respective c commands in all respects.
3398
3399   Delete
3400       Historically, lines in open mode that were deleted  were  scrolled  up,
3401       and  an  @ glyph written over the beginning of the line. In the case of
3402       terminals that are incapable of the necessary cursor motions, the  edi‐
3403       tor erased the deleted line from the screen. POSIX.1‐2008 requires con‐
3404       formance to historical practice; that is, if the terminal  cannot  dis‐
3405       play the '@' character, the line cannot remain on the screen.
3406
3407   Delete to End-of-Line
3408       Some  historical  implementations  of  the  D command did not behave as
3409       described by POSIX.1‐2008 when the $ key was remapped because they were
3410       implemented  by pushing the $ key onto the input queue and reprocessing
3411       it. POSIX.1‐2008 does not permit this behavior.
3412
3413   Join
3414       An historical oddity of vi is that the commands J, 1J, and 2J  are  all
3415       equivalent.  POSIX.1‐2008  requires conformance to historical practice.
3416       The vi J command is specified in terms of the ex join command  with  an
3417       ex command count value. The address correction for a count that is past
3418       the end of the edit buffer is necessary  for  historical  compatibility
3419       for both ex and vi.
3420
3421   Mark Position
3422       Historical  practice is that only lowercase letters, plus backquote and
3423       single-quote, could be used to mark  a  cursor  position.  POSIX.1‐2008
3424       requires conformance to historical practice, but encourages implementa‐
3425       tions to support other characters as marks as well.
3426
3427   Repeat Regular Expression Find (Forward and Reverse)
3428       Historically, the N and n commands could not be used as  motion  compo‐
3429       nents  for  the  c command. With the exception of the cN command, which
3430       worked if the search crossed a line boundary, the text region would  be
3431       discarded,  and  the  user would not be in text input mode. For consis‐
3432       tency and simplicity of specification,  POSIX.1‐2008  does  not  permit
3433       this behavior.
3434
3435   Insert Empty Line (Below and Above)
3436       Historically, counts to the O and o commands were used as the number of
3437       physical lines to open, if the  terminal  was  dumb  and  the  slowopen
3438       option  was  not  set.  This was intended to minimize traffic over slow
3439       connections and repainting for dumb terminals.  POSIX.1‐2008  does  not
3440       permit this behavior, requiring that a count to the open command behave
3441       as for other text input commands. This change  to  historical  practice
3442       was  made  for consistency, and because a superset of the functionality
3443       is provided by the slowopen edit option.
3444
3445   Put from Buffer (Following and Before)
3446       Historically, counts to the p and P commands were ignored if the buffer
3447       was  a  line mode buffer, but were (mostly) implemented as described in
3448       POSIX.1‐2008 if the buffer was a character mode buffer. Because  imple‐
3449       mentations  exist that do not have this limitation, and because pasting
3450       lines multiple times is generally useful,  POSIX.1‐2008  requires  that
3451       count be supported for all p and P commands.
3452
3453       Historical  implementations of vi were widely known to have major prob‐
3454       lems in the p and P commands, particularly when unusual regions of text
3455       were  copied into the edit buffer. The standard developers viewed these
3456       as bugs, and they are not permitted for consistency and  simplicity  of
3457       specification.
3458
3459       Historically, a P or p command (or an ex put command executed from open
3460       or visual mode) executed in an empty file, left an empty  line  as  the
3461       first  line  of  the file. For consistency and simplicity of specifica‐
3462       tion, POSIX.1‐2008 does not permit this behavior.
3463
3464   Replace Character
3465       Historically, the r command did not correctly handle the erase and word
3466       erase  characters  as  arguments, nor did it handle an associated count
3467       greater than 1 with a <carriage-return> argument, for which it replaced
3468       count characters with a single <newline>.  POSIX.1‐2008 does not permit
3469       these inconsistencies.
3470
3471       Historically, the r  command  permitted  the  <control>‐V  escaping  of
3472       entered  characters,  such as <ESC> and the <carriage-return>; however,
3473       it  required  two  leading  <control>‐V  characters  instead  of   one.
3474       POSIX.1‐2008  requires  that  this  be changed for consistency with the
3475       other text input commands of vi.
3476
3477       Historically, it is an error to enter the r command if there  are  less
3478       than  count characters at or after the cursor in the line. While a rea‐
3479       sonable and unambiguous extension would be to permit the r  command  on
3480       empty  lines,  it  would  require that too large a count be adjusted to
3481       match the number of characters at or after the cursor for  consistency,
3482       which is sufficiently different from historical practice to be avoided.
3483       POSIX.1‐2008 requires conformance to historical practice.
3484
3485   Replace Characters
3486       Historically, if there were autoindent characters in the line on  which
3487       the  R  command  was  run,  and autoindent was set, the first <newline>
3488       would be properly indented and no characters would be replaced  by  the
3489       <newline>.  Each additional <newline> would replace n characters, where
3490       n was the number of characters that were needed to indent the  rest  of
3491       the line to the proper indentation level. This behavior is a bug and is
3492       not permitted by POSIX.1‐2008.
3493
3494   Undo
3495       Historical practice for cursor positioning after undoing  commands  was
3496       mixed.  In  most  cases,  when  undoing commands that affected a single
3497       line, the cursor was moved to the start of added or  changed  text,  or
3498       immediately after deleted text. However, if the user had moved from the
3499       line being changed, the column was either set to the first non-<blank>,
3500       returned  to  the  origin  of  the command, or remained unchanged. When
3501       undoing commands that affected multiple lines or entire lines, the cur‐
3502       sor  was moved to the first character in the first line restored. As an
3503       example of how inconsistent this was, a search, followed by an  o  text
3504       input command, followed by an undo would return the cursor to the loca‐
3505       tion where the o command was entered, but a cw command followed by an o
3506       command  followed  by  an  undo  would  return  the cursor to the first
3507       non-<blank> of the line. POSIX.1‐2008 requires the most useful of these
3508       behaviors,  and  discards  the least useful, in the interest of consis‐
3509       tency and simplicity of specification.
3510
3511   Yank
3512       Historically, the yank command did not move to the end of the motion if
3513       the  motion  was  in  the forward direction. It moved to the end of the
3514       motion if the motion was in the backward direction, except  for  the  _
3515       command,  or for the G and ' commands when the end of the motion was on
3516       the current line. This was further complicated by the fact that  for  a
3517       number  of  motion  commands, the yank command moved the cursor but did
3518       not update the screen; for example, a subsequent command would move the
3519       cursor from the end of the motion, even though the cursor on the screen
3520       had  not  reflected  the  cursor  movement  for   the   yank   command.
3521       POSIX.1‐2008  requires  that all yank commands associated with backward
3522       motions move the cursor to the end of the motion for  consistency,  and
3523       specifically, to make ' commands as motions consistent with search pat‐
3524       terns as motions.
3525
3526   Yank Current Line
3527       Some historical implementations of the Y  command  did  not  behave  as
3528       described  by  POSIX.1‐2008  when the '_' key was remapped because they
3529       were implemented by pushing the '_' key onto the input queue and repro‐
3530       cessing it. POSIX.1‐2008 does not permit this behavior.
3531
3532   Redraw Window
3533       Historically, the z command always redrew the screen. This is permitted
3534       but not required by POSIX.1‐2008, because of the frequent use of the  z
3535       command in macros such as map n nz.  for screen positioning, instead of
3536       its use to change the screen size.  The  standard  developers  believed
3537       that  expanding  or scrolling the screen offered a better interface for
3538       users. The ability to redraw the screen is preserved  if  the  optional
3539       new  window  size  is specified, and in the <control>‐L and <control>‐R
3540       commands.
3541
3542       The semantics of z^ are confusing at best. Historical practice is  that
3543       the screen before the screen that ended with the specified line is dis‐
3544       played. POSIX.1‐2008 requires conformance to historical practice.
3545
3546       Historically, the z command would not display a partial line at the top
3547       or  bottom  of the screen. If the partial line would normally have been
3548       displayed at the bottom of the screen, the command worked, but the par‐
3549       tial  line  was replaced with '@' characters. If the partial line would
3550       normally have been displayed at the top  of  the  screen,  the  command
3551       would   fail.   For   consistency   and  simplicity  of  specification,
3552       POSIX.1‐2008 does not permit this behavior.
3553
3554       Historically, the z command with a line specification of 1 ignored  the
3555       command.  For consistency and simplicity of specification, POSIX.1‐2008
3556       does not permit this behavior.
3557
3558       Historically, the z command did not set the cursor column to the  first
3559       non-<blank>  for the character if the first screen was to be displayed,
3560       and was already displayed. For consistency and simplicity of specifica‐
3561       tion, POSIX.1‐2008 does not permit this behavior.
3562
3563   Input Mode Commands in vi
3564       Historical  implementations of vi did not permit the user to erase more
3565       than a single line of input, or to use normal erase characters such  as
3566       line  erase,  worderase,  and  erase to erase autoindent characters. As
3567       there exist implementations of vi that do not have  these  limitations,
3568       both behaviors are permitted, but only historical practice is required.
3569       In the case of these extensions, vi is required to pause at the autoin‐
3570       dent and previous line boundaries.
3571
3572       Historical implementations of vi updated only the portion of the screen
3573       where the current cursor character was displayed. For example, consider
3574       the vi input keystrokes:
3575
3576
3577           iabcd<escape>0C<tab>
3578
3579       Historically,  the  <tab> would overwrite the characters "abcd" when it
3580       was displayed. Other implementations replace  only  the  'a'  character
3581       with  the  <tab>, and then push the rest of the characters ahead of the
3582       cursor. Both implementations have problems. The historical  implementa‐
3583       tion is probably visually nicer for the above example; however, for the
3584       keystrokes:
3585
3586
3587           iabcd<ESC>0R<tab><ESC>
3588
3589       the historical implementation results in the string "bcd"  disappearing
3590       and  then  magically  reappearing  when the <ESC> character is entered.
3591       POSIX.1‐2008 requires the former behavior when  overwriting  erase-col‐
3592       umns—that  is, overwriting characters that are no longer logically part
3593       of the edit buffer—and the latter behavior otherwise.
3594
3595       Historical implementations of vi discarded the  <control>‐D  and  <con‐
3596       trol>‐T characters when they were entered at places where their command
3597       functionality was not appropriate. POSIX.1‐2008 requires that the <con‐
3598       trol>‐T  functionality  always  be  available,  and that <control>‐D be
3599       treated as any other key when not operating on autoindent characters.
3600
3601   NUL
3602       Some historical implementations of vi limited the number of  characters
3603       entered  using  the NUL input character to 256 bytes. POSIX.1‐2008 per‐
3604       mits this limitation; however, implementations are encouraged to remove
3605       this limit.
3606
3607   <control>‐D
3608       See  also  Rationale  for the input mode command <newline>.  The hidden
3609       assumptions in the <control>‐D command (and in the vi autoindent speci‐
3610       fication in general) is that <space> characters take up a single column
3611       on the screen and that <tab> characters are comprised  of  an  integral
3612       number of <space> characters.
3613
3614   <newline>
3615       Implementations  are  permitted to rewrite autoindent characters in the
3616       line when <newline>, <carriage-return>,  <control>‐D,  and  <control>‐T
3617       are  entered,  or  when the shift commands are used, because historical
3618       implementations have both done so and found it necessary to do so.  For
3619       example,  a  <control>‐D when the cursor is preceded by a single <tab>,
3620       with tabstop set to 8, and shiftwidth set to  3,  will  result  in  the
3621       <tab> being replaced by several <space> characters.
3622
3623   <control>‐T
3624       See  also the Rationale for the input mode command <newline>.  Histori‐
3625       cally, <control>‐T only worked if no  non-<blank>  characters  had  yet
3626       been  input  in  the  current  input  line. In addition, the characters
3627       inserted by <control>‐T were  treated  as  autoindent  characters,  and
3628       could not be erased using normal user erase characters.  Because imple‐
3629       mentations exist that do not have these limitations, and as moving to a
3630       column  boundary  is  generally useful, POSIX.1‐2008 requires that both
3631       limitations be removed.
3632
3633   <control>‐V
3634       Historically, vi used ^V, regardless of the value of  the  literal-next
3635       character  of  the terminal.  POSIX.1‐2008 requires conformance to his‐
3636       torical practice.
3637
3638       The uses described for <control>‐V can also be accomplished with  <con‐
3639       trol>‐Q,  which  is  useful  on  terminals that use <control>‐V for the
3640       down-arrow function. However, most historical implementations use <con‐
3641       trol>‐Q  for  the termios START character, so the editor will generally
3642       not receive the <control>‐Q unless stty ixon mode is set  to  off.  (In
3643       addition,  some  historical  implementations  of vi explicitly set ixon
3644       mode to on, so it was difficult for the user to set it to off.) Any  of
3645       the  command  characters described in POSIX.1‐2008 can be made ineffec‐
3646       tive by their selection as termios control characters, using  the  stty
3647       utility  or  other methods described in the System Interfaces volume of
3648       POSIX.1‐2017.
3649
3650   <ESC>
3651       Historically, SIGINT alerted the terminal when used to end input  mode.
3652       This behavior is permitted, but not required, by POSIX.1‐2008.
3653

FUTURE DIRECTIONS

3655       None.
3656

SEE ALSO

3658       ed, ex, stty
3659
3660       The Base Definitions volume of POSIX.1‐2017, Section 12.2, Utility Syn‐
3661       tax Guidelines
3662
3664       Portions of this text are reprinted and reproduced in  electronic  form
3665       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
3666       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
3667       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
3668       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
3669       event of any discrepancy between this version and the original IEEE and
3670       The Open Group Standard, the original IEEE and The Open Group  Standard
3671       is  the  referee document. The original Standard can be obtained online
3672       at http://www.opengroup.org/unix/online.html .
3673
3674       Any typographical or formatting errors that appear  in  this  page  are
3675       most likely to have been introduced during the conversion of the source
3676       files to man page format. To report such errors,  see  https://www.ker
3677       nel.org/doc/man-pages/reporting_bugs.html .
3678
3679
3680
3681IEEE/The Open Group                  2017                               VI(1P)
Impressum