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

PROLOG

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

NAME

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

SYNOPSIS

16       vi [−rR] [−c command] [−t tagstring] [−w size] [file...]
17

DESCRIPTION

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

OPTIONS

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

OPERANDS

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

STDIN

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

INPUT FILES

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

ENVIRONMENT VARIABLES

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

ASYNCHRONOUS EVENTS

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

STDOUT

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

STDERR

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

OUTPUT FILES

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

EXTENDED DESCRIPTION

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

EXIT STATUS

2776       The following exit values shall be returned:
2777
2778        0    Successful completion.
2779
2780       >0    An error occurred.
2781

CONSEQUENCES OF ERRORS

2783       When any error is encountered and the standard input is not a  terminal
2784       device  file,  vi shall not write the file or return to command or text
2785       input mode, and shall terminate with a non-zero exit status.
2786
2787       Otherwise, when an unrecoverable  error  is  encountered  it  shall  be
2788       equivalent to a SIGHUP asynchronous event.
2789
2790       Otherwise,  when  an  error  is encountered, the editor shall behave as
2791       specified in Command Descriptions in vi.
2792
2793       The following sections are informative.
2794

APPLICATION USAGE

2796       None.
2797

EXAMPLES

2799       None.
2800

RATIONALE

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

FUTURE DIRECTIONS

3542       None.
3543

SEE ALSO

3545       ed, ex, stty
3546
3547       The Base Definitions volume of POSIX.1‐2008, Section 12.2, Utility Syn‐
3548       tax Guidelines
3549
3551       Portions of this text are reprinted and reproduced in  electronic  form
3552       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
3553       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
3554       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
3555       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
3556       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
3557       event of any discrepancy between this version and the original IEEE and
3558       The  Open Group Standard, the original IEEE and The Open Group Standard
3559       is the referee document. The original Standard can be  obtained  online
3560       at http://www.unix.org/online.html .
3561
3562       Any  typographical  or  formatting  errors that appear in this page are
3563       most likely to have been introduced during the conversion of the source
3564       files  to  man page format. To report such errors, see https://www.ker
3565       nel.org/doc/man-pages/reporting_bugs.html .
3566
3567
3568
3569IEEE/The Open Group                  2013                               VI(1P)
Impressum