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

NAME

6       vi - screen-oriented (visual) display editor
7

SYNOPSIS

9       vi [-rR][-c command][-t tagstring][-w size][file ...]
10

DESCRIPTION

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

OPTIONS

42       The vi  utility  shall  conform  to  the  Base  Definitions  volume  of
43       IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
44
45       The following options shall be supported:
46
47       -c  command
48              See the ex command description of the -c option.
49
50       -r     See the ex command description of the -r option.
51
52       -R     See the ex command description of the -R option.
53
54       -t  tagstring
55              See the ex command description of the -t option.
56
57       -w  size
58              See the ex command description of the -w option.
59
60

OPERANDS

62       See the OPERANDS section of the ex command for a description of the op‐
63       erands supported by the vi command.
64

STDIN

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

INPUT FILES

75       See the INPUT FILES section of the ex command for a description of  the
76       input files supported by the vi command.
77

ENVIRONMENT VARIABLES

79       See  the  ENVIRONMENT VARIABLES section of the ex command for the envi‐
80       ronment variables that affect the execution of the vi command.
81

ASYNCHRONOUS EVENTS

83       See the ASYNCHRONOUS EVENTS section of  the  ex  for  the  asynchronous
84       events that affect the execution of the vi command.
85

STDOUT

87       If standard output is not a terminal device, undefined results occur.
88
89       Standard output may be used for writing prompts to the user, for infor‐
90       mational messages, and for writing lines from the file.
91

STDERR

93       If standard output is not a terminal device, undefined results occur.
94
95       The standard error shall be used only for diagnostic messages.
96

OUTPUT FILES

98       See the OUTPUT FILES section of the ex command for a description of the
99       output files supported by the vi command.
100

EXTENDED DESCRIPTION

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

EXIT STATUS

3099       The following exit values shall be returned:
3100
3101        0     Successful completion.
3102
3103       >0     An error occurred.
3104
3105

CONSEQUENCES OF ERRORS

3107       When any error is encountered and the standard input is not a  terminal
3108       device  file,  vi shall not write the file or return to command or text
3109       input mode, and shall terminate with a non-zero exit status.
3110
3111       Otherwise, when an unrecoverable  error  is  encountered  it  shall  be
3112       equivalent to a SIGHUP asynchronous event.
3113
3114       Otherwise,  when  an  error  is encountered, the editor shall behave as
3115       specified in Command Descriptions in vi .
3116
3117       The following sections are informative.
3118

APPLICATION USAGE

3120       None.
3121

EXAMPLES

3123       None.
3124

RATIONALE

3126       See the RATIONALE for ex for more information on vi. Major portions  of
3127       the  vi  utility  specification point to ex to avoid inadvertent diver‐
3128       gence. While ex and vi have historically been implemented as  a  single
3129       utility, this is not required by IEEE Std 1003.1-2001.
3130
3131       It  is recognized that portions of vi would be difficult, if not impos‐
3132       sible, to implement satisfactorily on a block-mode terminal, or a  ter‐
3133       minal without any form of cursor addressing, thus it is not a mandatory
3134       requirement that such features should work on all terminals. It is  the
3135       intention,  however,  that  a vi implementation should provide the full
3136       set of capabilities on all terminals capable of supporting them.
3137
3138       Historically, vi exited immediately if the standard  input  was  not  a
3139       terminal.  IEEE Std 1003.1-2001  permits,  but  does  not require, this
3140       behavior. An end-of-file condition is not equivalent to an  end-of-file
3141       character. A common end-of-file character, <control>-D, is historically
3142       a vi command.
3143
3144       The text in the STDOUT section reflects the usage of the  verb  display
3145       in  this  section;  some  implementations  of vi use standard output to
3146       write to the terminal, but IEEE Std 1003.1-2001 does not  require  that
3147       to be the case.
3148
3149       Historically, implementations reverted to open mode if the terminal was
3150       incapable  of  supporting  full  visual   mode.    IEEE Std 1003.1-2001
3151       requires  this  behavior.  Historically,  the  open  mode of vi behaved
3152       roughly equivalently to the visual mode, with the exception that only a
3153       single  line  from the edit buffer (one "buffer line") was kept current
3154       at any time.  This line was normally displayed on the next-to-last line
3155       of  a  terminal with cursor addressing (and the last line performed its
3156       normal visual functions for line-oriented commands and  messages).   In
3157       addition,  some  few  commands behaved differently in open mode than in
3158       visual mode. IEEE Std 1003.1-2001 requires  conformance  to  historical
3159       practice.
3160
3161       Historically,  ex  and vi implementations have expected text to proceed
3162       in the usual European/Latin order of left  to  right,  top  to  bottom.
3163       There  is no requirement in IEEE Std 1003.1-2001 that this be the case.
3164       The specification was deliberately written using words  like  "before",
3165       "after", "first", and "last" in order to permit implementations to sup‐
3166       port the natural text order of the language.
3167
3168       Historically, lines past the end of the edit buffer  were  marked  with
3169       single  tilde ( '~' ) characters; that is, if the one-based display was
3170       20 lines in length, and the last line of the file was on line one, then
3171       lines 2-20 would contain only a single '~' character.
3172
3173       Historically, the vi editor attempted to display only complete lines at
3174       the bottom of the screen (it did display partial lines at  the  top  of
3175       the  screen). If a line was too long to fit in its entirety at the bot‐
3176       tom of the screen, the screen lines where the line would have been dis‐
3177       played  were  displayed as single '@' characters, instead of displaying
3178       part of the line.  IEEE Std 1003.1-2001 permits, but does not  require,
3179       this  behavior.   Implementations  are  encouraged to attempt always to
3180       display a complete  line  at  the  bottom  of  the  screen  when  doing
3181       scrolling or screen positioning by buffer lines.
3182
3183       Historically,  lines  marked with '@' were also used to minimize output
3184       to dumb terminals over slow lines; that is, changes local to the cursor
3185       were updated, but changes to lines on the screen that were not close to
3186       the cursor were simply marked with an '@' sign instead of being updated
3187       to  match  the current text. IEEE Std 1003.1-2001 permits, but does not
3188       require this feature because it is used ever less frequently as  termi‐
3189       nals become smarter and connections are faster.
3190
3191   Initialization in ex and vi
3192       Historically, vi always had a line in the edit buffer, even if the edit
3193       buffer was "empty". For example:
3194
3195        1. The ex command = executed from visual mode wrote "1" when the  buf‐
3196           fer was empty.
3197
3198        2. Writes  from  visual  mode of an empty edit buffer wrote files of a
3199           single character (a <newline>), while writes from  ex  mode  of  an
3200           empty edit buffer wrote empty files.
3201
3202        3. Put  and read commands into an empty edit buffer left an empty line
3203           at the top of the edit buffer.
3204
3205       For consistency, IEEE Std 1003.1-2001 does  not  permit  any  of  these
3206       behaviors.
3207
3208       Historically,  vi  did  not  always return the terminal to its original
3209       modes; for example, ICRNL was modified if it was  not  originally  set.
3210       IEEE Std 1003.1-2001 does not permit this behavior.
3211
3212   Command Descriptions in vi
3213       Motion  commands  are  among  the  most  complicated  aspects  of vi to
3214       describe. With some exceptions, the text region and buffer type  effect
3215       of  a  motion  command  on a vi command are described on a case-by-case
3216       basis. The descriptions of text regions in IEEE Std 1003.1-2001 are not
3217       intended  to  imply direction; that is, an inclusive region from line n
3218       to line n+5 is identical to a region from line n+5 to line n.  This  is
3219       of  more  than  academic  interest-movements  to marks can be in either
3220       direction, and, if the wrapscan option is  set,  so  can  movements  to
3221       search  points.  Historically,  lines are always stored into buffers in
3222       text order; that is, from the start of the  edit  buffer  to  the  end.
3223       IEEE Std 1003.1-2001 requires conformance to historical practice.
3224
3225       Historically, command counts were applied to any associated motion, and
3226       were multiplicative to any supplied motion count. For example,  2cw  is
3227       the  same  as  c2w,  and  2c3w is the same as c6w. IEEE Std 1003.1-2001
3228       requires this behavior. Historically, vi commands that  used  bigwords,
3229       words,  paragraphs,  and  sentences  as objects treated groups of empty
3230       lines, or lines that contained  only  <blank>s,  inconsistently.   Some
3231       commands  treated  them  as  a single entity, while others treated each
3232       line separately. For example, the w, W, and B commands  treated  groups
3233       of empty lines as individual words; that is, the command would move the
3234       cursor to each new empty line. The e and E commands treated  groups  of
3235       empty  lines  as  a single word; that is, the first use would move past
3236       the group of lines. The b command would just beep at the  user,  or  if
3237       done from the start of the line as a motion command, fail in unexpected
3238       ways. If the lines contained only (or ended with) <blank>s, the w and W
3239       commands  would just beep at the user, the E and e commands would treat
3240       the group as a single word, and the B and b commands  would  treat  the
3241       lines as individual words. For consistency and simplicity of specifica‐
3242       tion, IEEE Std 1003.1-2001 requires that all vi commands  treat  groups
3243       of  empty  or blank lines as a single entity, and that movement through
3244       lines ending with <blank>s be consistent with other movements.
3245
3246       Historically, vi documentation indicated  that  any  number  of  double
3247       quotes  were  skipped  after  punctuation marks at sentence boundaries;
3248       however,    implementations     only     skipped     single     quotes.
3249       IEEE Std 1003.1-2001 requires both to be skipped.
3250
3251       Historically,  the  first  and  last characters in the edit buffer were
3252       word   boundaries.   This   historical   practice   is   required    by
3253       IEEE Std 1003.1-2001.
3254
3255       Historically,  vi  attempted to update the minimum number of columns on
3256       the screen possible, which could lead to misleading  information  being
3257       displayed.  IEEE Std 1003.1-2001  makes no requirements other than that
3258       the current character being entered is displayed correctly, leaving all
3259       other decisions in this area up to the implementation.
3260
3261       Historically,  lines  were  arbitrarily  folded  between columns of any
3262       characters that required multiple column positions on the screen,  with
3263       the  exception  of  tabs,  which  terminated  at the right-hand margin.
3264       IEEE Std 1003.1-2001 permits the former and requires the latter. Imple‐
3265       mentations that do not arbitrarily break lines between columns of char‐
3266       acters that occupy multiple column positions should not permit the cur‐
3267       sor to rest on a column that does not contain any part of a character.
3268
3269       The  historical  vi  had a problem in that all movements were by buffer
3270       lines, not by display or screen lines. This is often the right thing to
3271       do;  for example, single line movements, such as j or k, should work on
3272       buffer lines. Commands like dj, or j., where .  is  a  change  command,
3273       only  make  sense for buffer lines. It is not, however, the right thing
3274       to do for screen motion or scrolling commands like  <control>-D,  <con‐
3275       trol>-F,  and  H.  If the window is fairly small, using buffer lines in
3276       these cases can result in completely  random  motion;  for  example,  1
3277       <control>-D  can  result  in  a  completely changed screen, without any
3278       overlap. This is clearly not what the user wanted. The problem is  even
3279       worse in the case of the H, L, and M commands-as they position the cur‐
3280       sor at the first non- <blank> of the line, they may all  refer  to  the
3281       same location in large lines, and will result in no movement at all.
3282
3283       In  addition, if the line is larger than the screen, using buffer lines
3284       can make it impossible to display parts of the line-there are  not  any
3285       commands  that  do  not display the beginning of the line in historical
3286       vi, and if both the beginning and end of the  line  cannot  be  on  the
3287       screen at the same time, the user suffers.  Finally, the page and half-
3288       page scrolling commands historically moved to the first non- <blank> in
3289       the new line. If the line is approximately the same size as the screen,
3290       this is inadequate because the cursor before and  after  a  <control>-D
3291       command will refer to the same location on the screen.
3292
3293       Implementations  of  ex  and  vi  exist that do not have these problems
3294       because the relevant commands ( <control>-B, <control>-D,  <control>-F,
3295       <control>-U,  <control>-Y, <control>-E, H, L, and M) operate on display
3296       (screen) lines, not (edit) buffer lines.
3297
3298       IEEE Std 1003.1-2001 does not permit this behavior by  default  because
3299       the  standard  developers believed that users would find it too confus‐
3300       ing. However, historical practice has been relaxed. For example, ex and
3301       vi  historically  attempted,  albeit sometimes unsuccessfully, to never
3302       put part of a line on the last lines of a screen;  for  example,  if  a
3303       line  would not fit in its entirety, no part of the line was displayed,
3304       and the screen lines corresponding to the  line  contained  single  '@'
3305       characters.   This   behavior   is   permitted,  but  not  required  by
3306       IEEE Std 1003.1-2001, so that it is  possible  for  implementations  to
3307       support  long  lines  in small screens more reasonably without changing
3308       the commands to be oriented to the display (instead of oriented to  the
3309       buffer).   IEEE Std 1003.1-2001  also permits implementations to refuse
3310       to edit any edit buffer containing a line that  will  not  fit  on  the
3311       screen in its entirety.
3312
3313       The display area (for example, the value of the window edit option) has
3314       historically been "grown", or expanded, to display new text when  local
3315       movements  are  done in displays where the number of lines displayed is
3316       less than the maximum possible.  Expansion has  historically  been  the
3317       first  choice,  when  the target line is less than the maximum possible
3318       expansion value away.  Scrolling has historically been the next choice,
3319       done  when the target line is less than half a display away, and other‐
3320       wise, the screen was redrawn. There were exceptions, however,  in  that
3321       ex   commands  generally  always  caused  the  screen  to  be  redrawn.
3322       IEEE Std 1003.1-2001 does not specify a standard behavior because there
3323       may be external issues, such as connection speed, the number of charac‐
3324       ters necessary to redraw as opposed to scroll, or terminal capabilities
3325       that implementations will have to accommodate.
3326
3327       The  current  line  in IEEE Std 1003.1-2001 maps one-to-one to a buffer
3328       line in the file. The current column does not.  There are two different
3329       column values that are described by IEEE Std 1003.1-2001.  The first is
3330       the current column value as set by many of the vi commands. This  value
3331       is  remembered  for the lifetime of the editor. The second column value
3332       is the actual position on the screen where the cursor  rests.  The  two
3333       are  not  always  the same. For example, when the cursor is backed by a
3334       multi-column character, the actual cursor position on  the  screen  has
3335       historically been the last column of the character in command mode, and
3336       the first column of the character in input mode.
3337
3338       Commands that set the current line, but that do  not  set  the  current
3339       cursor value (for example, j and k) attempt to get as close as possible
3340       to the remembered column position, so that the cursor tends to restrict
3341       itself  to  a vertical column as the user moves around in the edit buf‐
3342       fer. IEEE Std 1003.1-2001 requires conformance to historical  practice,
3343       requiring  that  the display location of the cursor on the display line
3344       be adjusted from the current column value as necessary to support  this
3345       historical behavior.
3346
3347       Historically, only a single line (and for some terminals, a single line
3348       minus 1 column) of characters could be entered  by  the  user  for  the
3349       line-oriented  commands;  that  is, :, !, /, or ?. IEEE Std 1003.1-2001
3350       permits, but does not require, this limitation.
3351
3352       Historically, "soft" errors in vi caused the terminal  to  be  alerted,
3353       but no error message was displayed. As a general rule, no error message
3354       was displayed for errors in command execution in  vi,  when  the  error
3355       resulted  from  the user attempting an invalid or impossible action, or
3356       when a searched-for object was  not  found.  Examples  of  soft  errors
3357       included  h  at  the left margin, <control>-B or [[ at the beginning of
3358       the file, 2G at the end of the file, and so  on.  In  addition,  errors
3359       such as %, ]], }, ), N, n, f, F, t, and T failing to find the searched-
3360       for object were soft as well. Less consistently, / and ?  displayed  an
3361       error message if the pattern was not found, /, ?, N, and n displayed an
3362       error message if no previous regular expression had been specified, and
3363       ; did not display an error message if no previous f, F, t, or T command
3364       had occurred. Also, behavior in this area might reasonably be based  on
3365       a  runtime  evaluation  of the speed of a network connection.  Finally,
3366       some implementations have provided error messages for  soft  errors  in
3367       order  to  assist  naive  users,  based  on the value of a verbose edit
3368       option. IEEE Std 1003.1-2001 does not list specific errors for which an
3369       error  message  shall  be displayed.  Implementations should conform to
3370       historical practice in the absence of any strong reason to diverge.
3371
3372   Page Backwards
3373       The <control>-B and <control>-F commands historically considered it  an
3374       error to attempt to page past the beginning or end of the file, whereas
3375       the <control>-D and <control>-U commands simply moved to the  beginning
3376       or end of the file.  For consistency, IEEE Std 1003.1-2001 requires the
3377       latter behavior for all four commands. All four commands still consider
3378       it  an  error  if  the  current line is at the beginning ( <control>-B,
3379       <control>-U) or end ( <control>-F, <control>-D) of the  file.  Histori‐
3380       cally, the <control>-B and <control>-F commands skip two lines in order
3381       to include overlapping lines when a single  command  is  entered.  This
3382       makes less sense in the presence of a count, as there will be, by defi‐
3383       nition, no overlapping lines. The actual calculation used by historical
3384       implementations of the vi editor for <control>-B was:
3385
3386
3387              ((current first line) - count x (window edit option)) +2
3388
3389       and for <control>-F was:
3390
3391
3392              ((current first line) + count x (window edit option)) -2
3393
3394       This  calculation does not work well when intermixing commands with and
3395       without counts; for example, 3 <control>-F is not equivalent to  enter‐
3396       ing  the  <control>-F  command  three  times,  and is not reversible by
3397       entering the <control>-B command  three  times.  For  consistency  with
3398       other  vi  commands  that  take counts, IEEE Std 1003.1-2001 requires a
3399       different calculation.
3400
3401   Scroll Forward
3402       The 4BSD and System V implementations of vi  differed  on  the  initial
3403       value used by the scroll command. 4BSD used:
3404
3405
3406              ((window edit option) +1) /2
3407
3408       while  System  V used the value of the scroll edit option. The System V
3409       version is  specified  by  IEEE Std 1003.1-2001  because  the  standard
3410       developers believed that it was more intuitive and permitted the user a
3411       method of setting the scroll value initially without also  setting  the
3412       number of lines that are displayed.
3413
3414   Scroll Forward by Line
3415       Historically, the <control>-E and <control>-Y commands considered it an
3416       error if the last and first lines, respectively, were  already  on  the
3417       screen.  IEEE Std 1003.1-2001  requires conformance to historical prac‐
3418       tice. Historically, the <control>-E and  <control>-Y  commands  had  no
3419       effect  in open mode.  For simplicity and consistency of specification,
3420       IEEE Std 1003.1-2001 requires that they behave as usual, albeit with  a
3421       single line screen.
3422
3423   Clear and Redisplay
3424       The  historical  <control>-L command refreshed the screen exactly as it
3425       was supposed to be currently displayed, replacing  any  '@'  characters
3426       for  lines  that  had  been  deleted but not updated on the screen with
3427       refreshed '@' characters.  The intent of the <control>-L command is  to
3428       refresh when the screen has been accidentally overwritten; for example,
3429       by a write command from another user, or modem noise.
3430
3431   Redraw Screen
3432       The historical <control>-R command redisplayed only when  necessary  to
3433       update  lines  that  had been deleted but not updated on the screen and
3434       that were flagged with '@' characters. There is no requirement that the
3435       screen  be  in any way refreshed if no lines of this form are currently
3436       displayed. IEEE Std 1003.1-2001 permits implementations to extend  this
3437       command  to  refresh  lines  on  the screen flagged with '@' characters
3438       because they are too long to be displayed  in  the  current  framework;
3439       however, the current line and column need not be modified.
3440
3441   Search for tagstring
3442       Historically,  the  first  non-  <blank> at or after the cursor was the
3443       first character, and all subsequent characters that were  word  charac‐
3444       ters,  up  to the end of the line, were included. For example, with the
3445       cursor on the leading space or on the '#' character in the text "#bar@"
3446       ,  the  tag was "#bar" . On the character 'b' it was "bar" , and on the
3447       'a' it was "ar" . IEEE Std 1003.1-2001 requires this behavior.
3448
3449   Replace Text with Results from Shell Command
3450       Historically, the <, >, and ! commands considered most  cursor  motions
3451       other  than  line-oriented  motions  an error; for example, the command
3452       >/foo<CR> succeeded, while the command >l failed, even though the  text
3453       region  described  by the two commands might be identical.  For consis‐
3454       tency, all three commands only consider entire lines  and  not  partial
3455       lines,  and the region is defined as any line that contains a character
3456       that was specified by the motion.
3457
3458   Move to Matching Character
3459       Other matching characters  have  been  left  implementation-defined  in
3460       order  to  allow  extensions such as matching '<' and '>' for searching
3461       HTML, or #ifdef, #else, and #endif for searching C source.
3462
3463   Repeat Substitution
3464       IEEE Std 1003.1-2001 requires that any c and g flags specified  to  the
3465       previous  substitute  command be ignored; however, the r flag may still
3466       apply, if supported by the implementation.
3467
3468   Return to Previous (Context or Section)
3469       The [[, ]], (, ), {, and } commands are all affected by "section bound‐
3470       aries",  but in some historical implementations not all of the commands
3471       recognize the same section boundaries. This is a bug,  not  a  feature,
3472       and a unique section-boundary algorithm was not described for each com‐
3473       mand.  One special case that is preserved is that the sentence  command
3474       moves  to  the  end of the last line of the edit buffer while the other
3475       commands go to the beginning, in  order  to  preserve  the  traditional
3476       character  cut semantics of the sentence command. Historically, vi sec‐
3477       tion boundaries at the beginning and end of the edit  buffer  were  the
3478       first  non-  <blank>  on the first and last lines of the edit buffer if
3479       one exists; otherwise, the last character of the first and  last  lines
3480       of  the  edit buffer if one exists.  To increase consistency with other
3481       section locations, this has been simplified by IEEE Std 1003.1-2001  to
3482       the  first character of the first and last lines of the edit buffer, or
3483       the first and the last lines of the edit buffer if they are empty.
3484
3485       Sentence boundaries were problematic in the historical  vi.  They  were
3486       not  only  the boundaries as defined for the section and paragraph com‐
3487       mands, but they were the first non- <blank> that occurred  after  those
3488       boundaries,  as  well. Historically, the vi section commands were docu‐
3489       mented as taking an optional window size as a count preceding the  com‐
3490       mand.   This   was   not   implemented   in   historical  versions,  so
3491       IEEE Std 1003.1-2001 requires that the count repeat  the  command,  for
3492       consistency with other vi commands.
3493
3494   Repeat
3495       Historically,  mapped commands other than text input commands could not
3496       be repeated using the period  command.   IEEE Std 1003.1-2001  requires
3497       conformance to historical practice.
3498
3499       The restrictions on the interpretation of special characters (for exam‐
3500       ple, <control>-H) in the repetition of  text  input  mode  commands  is
3501       intended  to  match  historical  practice. For example, given the input
3502       sequence:
3503
3504
3505              iab<control>-H<control>-H<control>-Hdef<escape>
3506
3507       the user should be informed of an error  when  the  sequence  is  first
3508       entered, but not during a command repetition. The character <control>-T
3509       is specifically exempted from this restriction. Historical  implementa‐
3510       tions of vi ignored <control>-T characters that were input in the orig‐
3511       inal command during command repetition. IEEE Std 1003.1-2001  prohibits
3512       this behavior.
3513
3514   Find Regular Expression
3515       Historically,  commands  did not affect the line searched to or from if
3516       the motion command was a search ( /, ?, N, n) and  the  final  position
3517       was the start/end of the line. There were some special cases and vi was
3518       not consistent. IEEE Std 1003.1-2001 does not permit this behavior, for
3519       consistency.  Historical  implementations  permitted but were unable to
3520       handle searches as motion commands that wrapped (that is,  due  to  the
3521       edit  option  wrapscan)  to the original location. IEEE Std 1003.1-2001
3522       requires that this behavior be treated as an error.
3523
3524       Historically, the syntax "/RE/0" was used to force the command  to  cut
3525       text in line mode. IEEE Std 1003.1-2001 requires conformance to histor‐
3526       ical practice.
3527
3528       Historically, in open mode, a z specified to a  search  command  redis‐
3529       played  the  current line instead of displaying the current screen with
3530       the current line highlighted. For consistency and simplicity of  speci‐
3531       fication, IEEE Std 1003.1-2001 does not permit this behavior.
3532
3533       Historically, trailing z commands were permitted and ignored if entered
3534       as part of a search used as a motion command. For consistency and  sim‐
3535       plicity  of  specification,  IEEE Std 1003.1-2001  does not permit this
3536       behavior.
3537
3538   Execute an ex Command
3539       Historically, vi implementations restricted the commands that could  be
3540       entered on the colon command line (for example, append and change), and
3541       some other commands were known to cause them to fail  catastrophically.
3542       For  consistency,  IEEE Std 1003.1-2001  does not permit these restric‐
3543       tions. When executing an ex command by entering :, it is  not  possible
3544       to  enter  a  <newline> as part of the command because it is considered
3545       the end of the command. A different approach is  to  enter  ex  command
3546       mode by using the vi Q command (and later resuming visual mode with the
3547       ex vi command). In ex command mode, the single-line limitation does not
3548       exist. So, for example, the following is valid:
3549
3550
3551              Q
3552              s/break here/break\
3553              here/
3554              vi
3555
3556       IEEE Std 1003.1-2001  requires  that,  if the ex command overwrites any
3557       part of the screen that would be erased by a refresh, vi pauses  for  a
3558       character  from  the  user.  Historically,  this character could be any
3559       character; for example, a character input by the user before  the  mes‐
3560       sage  appeared, or even a mapped character. This is probably a bug, but
3561       implementations that have tried to be more rigorous by  requiring  that
3562       the user enter a specific character, or that the user enter a character
3563       after the message was displayed, have been forced by  user  indignation
3564       back  into  historical behavior.  IEEE Std 1003.1-2001 requires confor‐
3565       mance to historical practice.
3566
3567   Shift Left (Right)
3568       Refer to the Rationale for the ! and / commands.  Historically,  the  <
3569       and  >  commands  sometimes  moved the cursor to the first non- <blank>
3570       (for example if the command was repeated or with _ as the  motion  com‐
3571       mand),  and  sometimes left it unchanged. IEEE Std 1003.1-2001 does not
3572       permit this inconsistency, requiring instead  that  the  cursor  always
3573       move  to the first non- <blank>. Historically, the < and > commands did
3574       not support buffer arguments, although some implementations  allow  the
3575       specification  of an optional buffer. This behavior is neither required
3576       nor disallowed by IEEE Std 1003.1-2001.
3577
3578   Execute
3579       Historically, buffers could execute other buffers, and loops,  infinite
3580       and  otherwise,  were  possible.  IEEE Std 1003.1-2001 requires confor‐
3581       mance to historical practice.   The  *  buffer  syntax  of  ex  is  not
3582       required in vi, because it is not historical practice and has been used
3583       in some vi implementations to support additional scripting languages.
3584
3585   Reverse Case
3586       Historically, the ~ command ignored any  associated  count,  and  acted
3587       only  on the characters in the current line. For consistency with other
3588       vi commands, IEEE Std 1003.1-2001 requires that an associated count act
3589       on  the  next count characters, and that the command move to subsequent
3590       lines if warranted by count, to make it possible to modify large pieces
3591       of  text  in  a reasonably efficient manner. There exist vi implementa‐
3592       tions that optionally require an associated motion command  for  the  ~
3593       command.  Implementations  supporting this functionality are encouraged
3594       to base it on the tildedop edit option and handle the text regions  and
3595       cursor positioning identically to the yank command.
3596
3597   Append
3598       Historically,  counts specified to the A, a, I, and i commands repeated
3599       the input of the first line count times, and did not repeat the  subse‐
3600       quent  lines  of the input text. IEEE Std 1003.1-2001 requires that the
3601       entire text input be repeated count times.
3602
3603   Move Backward to Preceding Word
3604       Historically, vi became confused if word commands were used  as  motion
3605       commands in empty files.  IEEE Std 1003.1-2001 requires that this be an
3606       error. Historical implementations of vi had a large number of  bugs  in
3607       the  word movement commands, and they varied greatly in behavior in the
3608       presence of empty lines, "words" made up of  a  single  character,  and
3609       lines containing only <blank>s. For consistency and simplicity of spec‐
3610       ification, IEEE Std 1003.1-2001 does not permit this behavior.
3611
3612   Change to End-of-Line
3613       Some historical implementations of the C  command  did  not  behave  as
3614       described  by  IEEE Std 1003.1-2001 when the $ key was remapped because
3615       they were implemented by pushing the $ key onto  the  input  queue  and
3616       reprocessing  it.   IEEE Std 1003.1-2001 does not permit this behavior.
3617       Historically, the C, S, and s commands did not copy replaced text  into
3618       the  numeric  buffers. For consistency and simplicity of specification,
3619       IEEE Std 1003.1-2001 requires that they behave like their respective  c
3620       commands in all respects.
3621
3622   Delete
3623       Historically,  lines  in  open mode that were deleted were scrolled up,
3624       and an @ glyph written over the beginning of the line. In the  case  of
3625       terminals  that are incapable of the necessary cursor motions, the edi‐
3626       tor erased the  deleted  line  from  the  screen.  IEEE Std 1003.1-2001
3627       requires  conformance  to historical practice; that is, if the terminal
3628       cannot display the '@' character, the line cannot remain on the screen.
3629
3630   Delete to End-of-Line
3631       Some historical implementations of the D  command  did  not  behave  as
3632       described  by  IEEE Std 1003.1-2001 when the $ key was remapped because
3633       they were implemented by pushing the $ key onto  the  input  queue  and
3634       reprocessing it.  IEEE Std 1003.1-2001 does not permit this behavior.
3635
3636   Join
3637       An  historical  oddity of vi is that the commands J, 1J, and 2J are all
3638       equivalent.  IEEE Std 1003.1-2001 requires  conformance  to  historical
3639       practice.   The  vi J command is specified in terms of the ex join com‐
3640       mand with an ex command count value. The address correction for a count
3641       that  is  past  the  end of the edit buffer is necessary for historical
3642       compatibility for both ex and vi.
3643
3644   Mark Position
3645       Historical practice is that only lowercase letters, plus '`' and  '"  ,
3646       could  be used to mark a cursor position. IEEE Std 1003.1-2001 requires
3647       conformance to historical practice, but encourages  implementations  to
3648       support other characters as marks as well.
3649
3650   Repeat Regular Expression Find (Forward and Reverse)
3651       Historically,  the  N and n commands could not be used as motion compo‐
3652       nents for the c command. With the exception of the  cN  command,  which
3653       worked  if the search crossed a line boundary, the text region would be
3654       discarded, and the user would not be in text input  mode.  For  consis‐
3655       tency  and  simplicity  of specification, IEEE Std 1003.1-2001 does not
3656       permit this behavior.
3657
3658   Insert Empty Line (Below and Above)
3659       Historically, counts to the O and o commands were used as the number of
3660       physical  lines  to  open,  if  the  terminal was dumb and the slowopen
3661       option was not set. This was intended to  minimize  traffic  over  slow
3662       connections  and  repainting  for  dumb terminals. IEEE Std 1003.1-2001
3663       does not permit this behavior, requiring that a count to the open  com‐
3664       mand behave as for other text input commands. This change to historical
3665       practice was made for consistency, and because a superset of the  func‐
3666       tionality is provided by the slowopen edit option.
3667
3668   Put from Buffer (Following and Before)
3669       Historically, counts to the p and P commands were ignored if the buffer
3670       was a line mode buffer, but were (mostly) implemented as  described  in
3671       IEEE Std 1003.1-2001 if the buffer was a character mode buffer. Because
3672       implementations exist that do not have  this  limitation,  and  because
3673       pasting  lines multiple times is generally useful, IEEE Std 1003.1-2001
3674       requires that count be supported for all p and P commands.
3675
3676       Historical implementations of vi were widely known to have major  prob‐
3677       lems in the p and P commands, particularly when unusual regions of text
3678       were copied into the edit buffer. The standard developers viewed  these
3679       as  bugs,  and they are not permitted for consistency and simplicity of
3680       specification.
3681
3682       Historically, a P or p command (or an ex put command executed from open
3683       or  visual  mode)  executed in an empty file, left an empty line as the
3684       first line of the file. For consistency and  simplicity  of  specifica‐
3685       tion, IEEE Std 1003.1-2001 does not permit this behavior.
3686
3687   Replace Character
3688       Historically, the r command did not correctly handle the erase and word
3689       erase characters as arguments, nor did it handle  an  associated  count
3690       greater than 1 with a <carriage-return> argument, for which it replaced
3691       count characters with a single <newline>. IEEE Std 1003.1-2001 does not
3692       permit these inconsistencies.
3693
3694       Historically,  the  r  command  permitted  the  <control>-V escaping of
3695       entered characters, such as <ESC> and the  <carriage-return>;  however,
3696       it   required  two  leading  <control>-V  characters  instead  of  one.
3697       IEEE Std 1003.1-2001 requires that this be changed for consistency with
3698       the other text input commands of vi.
3699
3700       Historically,  it  is an error to enter the r command if there are less
3701       than count characters at or after the cursor in the line. While a  rea‐
3702       sonable  and  unambiguous extension would be to permit the r command on
3703       empty lines, it would require that too large a  count  be  adjusted  to
3704       match  the number of characters at or after the cursor for consistency,
3705       which is sufficiently different from historical practice to be avoided.
3706       IEEE Std 1003.1-2001 requires conformance to historical practice.
3707
3708   Replace Characters
3709       Historically,  if there were autoindent characters in the line on which
3710       the R command was run, and autoindent  was  set,  the  first  <newline>
3711       would  be  properly indented and no characters would be replaced by the
3712       <newline>. Each additional <newline> would replace n characters,  where
3713       n  was  the number of characters that were needed to indent the rest of
3714       the line to the proper indentation level. This behavior is a bug and is
3715       not permitted by IEEE Std 1003.1-2001.
3716
3717   Undo
3718       Historical  practice  for cursor positioning after undoing commands was
3719       mixed. In most cases, when undoing  commands  that  affected  a  single
3720       line,  the  cursor  was moved to the start of added or changed text, or
3721       immediately after deleted text. However, if the user had moved from the
3722       line  being  changed,  the  column  was  either  set  to the first non-
3723       <blank>, returned to the origin of the command, or remained  unchanged.
3724       When undoing commands that affected multiple lines or entire lines, the
3725       cursor was moved to the first character in the first line restored.  As
3726       an  example  of  how  inconsistent this was, a search, followed by an o
3727       text input command, followed by an undo would return the cursor to  the
3728       location  where the o command was entered, but a cw command followed by
3729       an o command followed by an undo would return the cursor to  the  first
3730       non- <blank> of the line. IEEE Std 1003.1-2001 requires the most useful
3731       of these behaviors, and discards the least useful, in the  interest  of
3732       consistency and simplicity of specification.
3733
3734   Yank
3735       Historically, the yank command did not move to the end of the motion if
3736       the motion was in the forward direction. It moved to  the  end  of  the
3737       motion  if  the  motion was in the backward direction, except for the _
3738       command, or for the G and ' commands when the end of the motion was  on
3739       the  current line.  This was further complicated by the fact that for a
3740       number of motion commands, the yank command moved the  cursor  but  did
3741       not update the screen; for example, a subsequent command would move the
3742       cursor from the end of the motion, even though the cursor on the screen
3743       had   not   reflected   the  cursor  movement  for  the  yank  command.
3744       IEEE Std 1003.1-2001 requires that all yank  commands  associated  with
3745       backward  motions  move the cursor to the end of the motion for consis‐
3746       tency, and specifically, to make ' commands as motions consistent  with
3747       search patterns as motions.
3748
3749   Yank Current Line
3750       Some  historical  implementations  of  the  Y command did not behave as
3751       described by IEEE Std 1003.1-2001 when the '_' key was remapped because
3752       they  were  implemented by pushing the '_' key onto the input queue and
3753       reprocessing it. IEEE Std 1003.1-2001 does not permit this behavior.
3754
3755   Redraw Window
3756       Historically, the z command always redrew the screen. This is permitted
3757       but  not  required by IEEE Std 1003.1-2001, because of the frequent use
3758       of the z command in macros such as map n nz.  for  screen  positioning,
3759       instead  of  its use to change the screen size. The standard developers
3760       believed that expanding or scrolling the screen offered a better inter‐
3761       face  for  users.  The ability to redraw the screen is preserved if the
3762       optional new window size is specified, and in the <control>-L and <con‐
3763       trol>-R commands.
3764
3765       The  semantics of z^ are confusing at best. Historical practice is that
3766       the screen before the screen that ended with the specified line is dis‐
3767       played.  IEEE Std 1003.1-2001  requires conformance to historical prac‐
3768       tice.
3769
3770       Historically, the z command would not display a partial line at the top
3771       or  bottom  of the screen. If the partial line would normally have been
3772       displayed at the bottom of the screen, the command worked, but the par‐
3773       tial  line  was replaced with '@' characters. If the partial line would
3774       normally have been displayed at the top  of  the  screen,  the  command
3775       would   fail.    For   consistency  and  simplicity  of  specification,
3776       IEEE Std 1003.1-2001 does not permit this behavior.
3777
3778       Historically, the z command with a line specification of 1 ignored  the
3779       command.    For    consistency   and   simplicity   of   specification,
3780       IEEE Std 1003.1-2001 does not permit this behavior.
3781
3782       Historically, the z command did not set the cursor column to the  first
3783       non- <blank> for the character if the first screen was to be displayed,
3784       and was already displayed. For consistency and simplicity of specifica‐
3785       tion, IEEE Std 1003.1-2001 does not permit this behavior.
3786
3787   Input Mode Commands in vi
3788       Historical  implementations of vi did not permit the user to erase more
3789       than a single line of input, or to use normal erase characters such  as
3790       line  erase,  worderase,  and  erase to erase autoindent characters. As
3791       there exist implementations of vi that do not have  these  limitations,
3792       both behaviors are permitted, but only historical practice is required.
3793       In the case of these extensions, vi is required to pause at the autoin‐
3794       dent and previous line boundaries.
3795
3796       Historical implementations of vi updated only the portion of the screen
3797       where the current cursor character was displayed.   For  example,  con‐
3798       sider the vi input keystrokes:
3799
3800
3801              iabcd<escape>0C<tab>
3802
3803       Historically,  the  <tab> would overwrite the characters "abcd" when it
3804       was displayed. Other implementations replace  only  the  'a'  character
3805       with  the  <tab>, and then push the rest of the characters ahead of the
3806       cursor. Both implementations have problems. The historical  implementa‐
3807       tion is probably visually nicer for the above example; however, for the
3808       keystrokes:
3809
3810
3811              iabcd<ESC>0R<tab><ESC>
3812
3813       the historical implementation results in the string "bcd"  disappearing
3814       and  then  magically  reappearing  when the <ESC> character is entered.
3815       IEEE Std 1003.1-2001 requires  the  former  behavior  when  overwriting
3816       erase-columns-that  is, overwriting characters that are no longer logi‐
3817       cally part of the edit buffer-and the latter behavior otherwise.
3818
3819       Historical implementations of vi discarded the  <control>-D  and  <con‐
3820       trol>-T characters when they were entered at places where their command
3821       functionality was not appropriate. IEEE Std 1003.1-2001  requires  that
3822       the <control>-T functionality always be available, and that <control>-D
3823       be treated as any other key when not operating  on  autoindent  charac‐
3824       ters.
3825
3826   NUL
3827       Some  historical implementations of vi limited the number of characters
3828       entered   using   the   NUL   input    character    to    256    bytes.
3829       IEEE Std 1003.1-2001  permits this limitation; however, implementations
3830       are encouraged to remove this limit.
3831
3832   <control>-D
3833       See also Rationale for the input mode  command  <newline>.  The  hidden
3834       assumptions in the <control>-D command (and in the vi autoindent speci‐
3835       fication in general) is that <space>s take up a single  column  on  the
3836       screen and that <tab>s are comprised of an integral number of <space>s.
3837
3838   <newline>
3839       Implementations  are  permitted to rewrite autoindent characters in the
3840       line when <newline>, <carriage-return>,  <control>-D,  and  <control>-T
3841       are  entered,  or  when the shift commands are used, because historical
3842       implementations have both done so and found it necessary to do so.  For
3843       example,  a  <control>-D when the cursor is preceded by a single <tab>,
3844       with tabstop set to 8, and shiftwidth set to  3,  will  result  in  the
3845       <tab> being replaced by several <space>s.
3846
3847   <control>-T
3848       See  also  the Rationale for the input mode command <newline>. Histori‐
3849       cally, <control>-T only worked if no non- <blank>s had yet  been  input
3850       in  the  current  input  line.  In addition, the characters inserted by
3851       <control>-T were treated as autoindent characters,  and  could  not  be
3852       erased  using  normal  user  erase  characters. Because implementations
3853       exist that do not have these limitations, and as  moving  to  a  column
3854       boundary  is  generally useful, IEEE Std 1003.1-2001 requires that both
3855       limitations be removed.
3856
3857   <control>-V
3858       Historically, vi used ^V, regardless of the value of  the  literal-next
3859       character  of  the terminal.  IEEE Std 1003.1-2001 requires conformance
3860       to historical practice.
3861
3862       The uses described for <control>-V can also be accomplished with  <con‐
3863       trol>-Q,  which  is  useful  on  terminals that use <control>-V for the
3864       down-arrow function. However, most historical implementations use <con‐
3865       trol>-Q  for  the termios START character, so the editor will generally
3866       not receive the <control>-Q unless stty ixon mode is set  to  off.  (In
3867       addition,  some  historical  implementations  of vi explicitly set ixon
3868       mode to on, so it was difficult for the user to set it to off.) Any  of
3869       the  command  characters  described in IEEE Std 1003.1-2001 can be made
3870       ineffective by their selection as termios control characters, using the
3871       stty utility or other methods described in the System Interfaces volume
3872       of IEEE Std 1003.1-2001.
3873
3874   <ESC>
3875       Historically, SIGINT alerted the terminal when used to end input  mode.
3876       This behavior is permitted, but not required, by IEEE Std 1003.1-2001.
3877

FUTURE DIRECTIONS

3879       None.
3880

SEE ALSO

3882       ed , ex , stty
3883
3885       Portions  of  this text are reprinted and reproduced in electronic form
3886       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
3887       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
3888       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
3889       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
3890       event of any discrepancy between this version and the original IEEE and
3891       The  Open Group Standard, the original IEEE and The Open Group Standard
3892       is the referee document. The original Standard can be  obtained  online
3893       at http://www.opengroup.org/unix/online.html .
3894
3895
3896
3897IEEE/The Open Group                  2003                                VI(P)
Impressum