1VI(1P) POSIX Programmer's Manual VI(1P)
2
3
4
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
12 vi - screen-oriented (visual) display editor
13
15 vi [-rR][-c command][-t tagstring][-w size][file ...]
16
18 This utility shall be provided on systems that both support the User
19 Portability Utilities option and define the POSIX2_CHAR_TERM symbol. On
20 other systems it is optional.
21
22 The vi (visual) utility is a screen-oriented text editor. Only the open
23 and visual modes of the editor are described in IEEE Std 1003.1-2001;
24 see the line editor ex for additional editing capabilities used in vi.
25 The user can switch back and forth between vi and ex and execute ex
26 commands from within vi.
27
28 This reference page uses the term edit buffer to describe the current
29 working text. No specific implementation is implied by this term. All
30 editing changes are performed on the edit buffer, and no changes to it
31 shall affect any file until an editor command writes the file.
32
33 When using vi, the terminal screen acts as a window into the editing
34 buffer. Changes made to the editing buffer shall be reflected in the
35 screen display; the position of the cursor on the screen shall indicate
36 the position within the editing buffer.
37
38 Certain terminals do not have all the capabilities necessary to support
39 the complete vi definition. When these commands cannot be supported on
40 such terminals, this condition shall not produce an error message such
41 as "not an editor command" or report a syntax error. The implementation
42 may either accept the commands and produce results on the screen that
43 are the result of an unsuccessful attempt to meet the requirements of
44 this volume of IEEE Std 1003.1-2001 or report an error describing the
45 terminal-related deficiency.
46
48 The vi utility shall conform to the Base Definitions volume of
49 IEEE Std 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
50
51 The following options shall be supported:
52
53 -c command
54 See the ex command description of the -c option.
55
56 -r See the ex command description of the -r option.
57
58 -R See the ex command description of the -R option.
59
60 -t tagstring
61 See the ex command description of the -t option.
62
63 -w size
64 See the ex command description of the -w option.
65
66
68 See the OPERANDS section of the ex command for a description of the op‐
69 erands supported by the vi command.
70
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
81 See the INPUT FILES section of the ex command for a description of the
82 input files supported by the vi command.
83
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
89 See the ASYNCHRONOUS EVENTS section of the ex for the asynchronous
90 events that affect the execution of the vi command.
91
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
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
104 See the OUTPUT FILES section of the ex command for a description of the
105 output files supported by the vi command.
106
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 [ buffer]
128 and [ count] preceding the command name, they can be specified in
129 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 argument
133 is optional and shall default to 1 unless otherwise specified.
134
135 The Synopsis lines for the vi commands <control>-G, <control>-L, <con‐
136 trol>-R, <control>-], %, &, ^, D, m, M, Q, u, U, and ZZ do not have
137 count as an optional argument. Regardless, it shall not be an error to
138 specify a count to these commands, and any specified count shall be
139 ignored.
140
141 motion An optional trailing argument used by the !, <, >, c, d, and y
142 commands, which is used to indicate the region of text that
143 shall be affected by the command. The motion can be either one
144 of the command characters repeated or one of several other vi
145 commands (listed in the following table). Each of the applicable
146 commands specifies the region of text matched by repeating the
147 command; each command that can be used as a motion command spec‐
148 ifies the region of text it affects.
149
150 Commands that take motion arguments operate on either lines or charac‐
151 ters, depending on the circumstances. When operating on lines, all
152 lines that fall partially or wholly within the text region specified
153 for the command shall be affected. When operating on characters, only
154 the exact characters in the specified text region shall be affected.
155 Each motion command specifies this individually.
156
157 When commands that may be motion commands are not used as motion com‐
158 mands, they shall set the current position to the current line and col‐
159 umn as specified.
160
161 The following commands shall be valid cursor motion commands:
162
163
164 <apostrophe> ( - j H
165 <carriage-return> ) $ k L
166 <comma> [[ % l M
167 <control>-H ]] _ n N
168 <control>-N { ; t T
169 <control>-P } ? w W
170 <grave accent> ^ b B
171 <newline> + e E
172 <space> | f F
173 <zero> / h G
174
175 Any count that is specified to a command that has an associated motion
176 command shall be applied to the motion command. If a count is applied
177 to both the command and its associated motion command, the effect shall
178 be multiplicative.
179
180
181 The following symbols are used in this section to specify locations in
182 the edit buffer:
183
184 current character
185
186 The character that is currently indicated by the cursor.
187
188 end of a line
189
190 The point located between the last non- <newline> (if any) and
191 the terminating <newline> of a line. For an empty line, this
192 location coincides with the beginning of the line.
193
194 end of the edit buffer
195
196 The location corresponding to the end of the last line in the
197 edit buffer.
198
199
200 The following symbols are used in this section to specify command
201 actions:
202
203 bigword
204 In the POSIX locale, vi shall recognize four kinds of bigwords:
205
206 1. A maximal sequence of non- <blank>s preceded and followed by
207 <blank>s or the beginning or end of a line or the edit buf‐
208 fer
209
210 2. One or more sequential blank lines
211
212 3. The first character in the edit buffer
213
214 4. The last non- <newline> in the edit buffer
215
216 word In the POSIX locale, vi shall recognize five kinds of words:
217
218 1. A maximal sequence of letters, digits, and underscores,
219 delimited at both ends by:
220
221 * Characters other than letters, digits, or underscores
222
223 * The beginning or end of a line
224
225 * The beginning or end of the edit buffer
226
227 2. A maximal sequence of characters other than letters, digits,
228 underscores, or <blank>s, delimited at both ends by:
229
230 * A letter, digit, underscore
231
232 * <blank>s
233
234 * The beginning or end of a line
235
236 * The beginning or end of the edit buffer
237
238 3. One or more sequential blank lines
239
240 4. The first character in the edit buffer
241
242 5. The last non- <newline> in the edit buffer
243
244 section boundary
245
246 A section boundary is one of the following:
247
248 1. A line whose first character is a <form-feed>
249
250 2. A line whose first character is an open curly brace ( '{' )
251
252 3. A line whose first character is a period and whose second
253 and third characters match a two-character pair in the sec‐
254 tions edit option (see ed)
255
256 4. A line whose first character is a period and whose only
257 other character matches the first character of a two-charac‐
258 ter pair in the sections edit option, where the second char‐
259 acter of the two-character pair is a <space>
260
261 5. The first line of the edit buffer
262
263 6. The last line of the edit buffer if the last line of the
264 edit buffer is empty or if it is a ]] or } command; other‐
265 wise, the last non- <newline> of the last line of the edit
266 buffer
267
268 paragraph boundary
269
270 A paragraph boundary is one of the following:
271
272 1. A section boundary
273
274 2. A line whose first character is a period and whose second
275 and third characters match a two-character pair in the para‐
276 graphs edit option (see ed)
277
278 3. A line whose first character is a period and whose only
279 other character matches the first character of a two-charac‐
280 ter pair in the paragraphs edit option, where the second
281 character of the two-character pair is a <space>
282
283 4. One or more sequential blank lines
284
285 remembered search direction
286
287 See the description of remembered search direction in ed.
288
289 sentence boundary
290
291 A sentence boundary is one of the following:
292
293 1. A paragraph boundary
294
295 2. The first non- <blank> that occurs after a paragraph bound‐
296 ary
297
298 3. The first non- <blank> that occurs after a period ( '.' ),
299 exclamation mark ( '!' ), or question mark ( '?' ), followed
300 by two <space>s or the end of a line; any number of closing
301 parenthesis ( ')' ), closing brackets ( ']' ), double quote
302 ( ' ),' or single quote ( '" ) characters can appear between
303 the punctuation mark and the two <space>s or end-of-line
304
305 In the remainder of the description of the vi utility, the term "buffer
306 line" refers to a line in the edit buffer and the term "display line"
307 refers to the line or lines on the display screen used to display one
308 buffer line. The term "current line" refers to a specific "buffer
309 line".
310
311 If there are display lines on the screen for which there are no corre‐
312 sponding buffer lines because they correspond to lines that would be
313 after the end of the file, they shall be displayed as a single tilde (
314 '~' ) character, plus the terminating <newline>.
315
316 The last line of the screen shall be used to report errors or display
317 informational messages. It shall also be used to display the input for
318 "line-oriented commands" ( /, ?, :, and !). When a line-oriented com‐
319 mand is executed, the editor shall enter text input mode on the last
320 line on the screen, using the respective command characters as prompt
321 characters. (In the case of the ! command, the associated motion shall
322 be entered by the user before the editor enters text input mode.) The
323 line entered by the user shall be terminated by a <newline>, a non-
324 <control>-V-escaped <carriage-return>, or unescaped <ESC>. It is
325 unspecified if more characters than require a display width minus one
326 column number of screen columns can be entered.
327
328 If any command is executed that overwrites a portion of the screen
329 other than the last line of the screen (for example, the ex suspend or
330 ! commands), other than the ex shell command, the user shall be
331 prompted for a character before the screen is refreshed and the edit
332 session continued.
333
334 <tab>s shall take up the number of columns on the screen set by the
335 tabstop edit option (see ed), unless there are less than that number of
336 columns before the display margin that will cause the displayed line to
337 be folded; in this case, they shall only take up the number of columns
338 up to that boundary.
339
340 The cursor shall be placed on the current line and relative to the cur‐
341 rent column as specified by each command described in the following
342 sections.
343
344 In open mode, if the current line is not already displayed, then it
345 shall be displayed.
346
347 In visual mode, if the current line is not displayed, then the lines
348 that are displayed shall be expanded, scrolled, or redrawn to cause an
349 unspecified portion of the current line to be displayed. If the screen
350 is redrawn, no more than the number of display lines specified by the
351 value of the window edit option shall be displayed (unless the current
352 line cannot be completely displayed in the number of display lines
353 specified by the window edit option) and the current line shall be
354 positioned as close to the center of the displayed lines as possible
355 (within the constraints imposed by the distance of the line from the
356 beginning or end of the edit buffer). If the current line is before the
357 first line in the display and the screen is scrolled, an unspecified
358 portion of the current line shall be placed on the first line of the
359 display. If the current line is after the last line in the display and
360 the screen is scrolled, an unspecified portion of the current line
361 shall be placed on the last line of the display.
362
363 In visual mode, if a line from the edit buffer (other than the current
364 line) does not entirely fit into the lines at the bottom of the display
365 that are available for its presentation, the editor may choose not to
366 display any portion of the line. The lines of the display that do not
367 contain text from the edit buffer for this reason shall each consist of
368 a single '@' character.
369
370 In visual mode, the editor may choose for unspecified reasons to not
371 update lines in the display to correspond to the underlying edit buffer
372 text. The lines of the display that do not correctly correspond to text
373 from the edit buffer for this reason shall consist of a single '@'
374 character (plus the terminating <newline>), and the <control>-R command
375 shall cause the editor to update the screen to correctly represent the
376 edit buffer.
377
378 Open and visual mode commands that set the current column set it to a
379 column position in the display, and not a character position in the
380 line. In this case, however, the column position in the display shall
381 be calculated for an infinite width display; for example, the column
382 related to a character that is part of a line that has been folded onto
383 additional screen lines will be offset from the display line column
384 where the buffer line begins, not from the beginning of a particular
385 display line.
386
387 The display cursor column in the display is based on the value of the
388 current column, as follows, with each rule applied in turn:
389
390 1. If the current column is after the last display line column used by
391 the displayed line, the display cursor column shall be set to the
392 last display line column occupied by the last non- <newline> in the
393 current line; otherwise, the display cursor column shall be set to
394 the current column.
395
396 2. If the character of which some portion is displayed in the display
397 line column specified by the display cursor column requires more
398 than a single display line column:
399
400 a. If in text input mode, the display cursor column shall be
401 adjusted to the first display line column in which any portion
402 of that character is displayed.
403
404 b. Otherwise, the display cursor column shall be adjusted to the
405 last display line column in which any portion of that character
406 is displayed.
407
408 The current column shall not be changed by these adjustments to the
409 display cursor column.
410
411 If an error occurs during the parsing or execution of a vi command:
412
413 * The terminal shall be alerted. Execution of the vi command shall
414 stop, and the cursor (for example, the current line and column)
415 shall not be further modified.
416
417 * Unless otherwise specified by the following command sections, it is
418 unspecified whether an informational message shall be displayed.
419
420 * Any partially entered vi command shall be discarded.
421
422 * If the vi command resulted from a map expansion, all characters from
423 that map expansion shall be discarded, except as otherwise specified
424 by the map command (see ed).
425
426 * If the vi command resulted from the execution of a buffer, no fur‐
427 ther commands caused by the execution of the buffer shall be exe‐
428 cuted.
429
430 Page Backwards
431 Synopsis:
432
433
434 [count] <control>-B
435
436
437 If in open mode, the <control>-B command shall behave identically to
438 the z command. Otherwise, if the current line is the first line of the
439 edit buffer, it shall be an error.
440
441 If the window edit option is less than 3, display a screen where the
442 last line of the display shall be some portion of:
443
444
445 (current first line) -1
446
447 otherwise, display a screen where the first line of the display shall
448 be some portion of:
449
450
451 (current first line) - count x ((window edit option) -2)
452
453 If this calculation would result in a line that is before the first
454 line of the edit buffer, the first line of the display shall display
455 some portion of the first line of the edit buffer.
456
457 Current line: If no lines from the previous display remain on the
458 screen, set to the last line of the display; otherwise, set to ( line -
459 the number of new lines displayed on this screen).
460
461 Current column: Set to non- <blank>.
462
463 Scroll Forward
464 Synopsis:
465
466
467 [count] <control>-D
468
469
470 If the current line is the last line of the edit buffer, it shall be an
471 error.
472
473 If no count is specified, count shall default to the count associated
474 with the previous <control>-D or <control>-U command. If there was no
475 previous <control>-D or <control>-U command, count shall default to the
476 value of the scroll edit option.
477
478 If in open mode, write lines starting with the line after the current
479 line, until count lines or the last line of the file have been written.
480
481 Current line: If the current line + count is past the last line of the
482 edit buffer, set to the last line of the edit buffer; otherwise, set to
483 the current line + count.
484
485 Current column: Set to non- <blank>.
486
487 Scroll Forward by Line
488 Synopsis:
489
490
491 [count] <control>-E
492
493
494 Display the line count lines after the last line currently displayed.
495
496 If the last line of the edit buffer is displayed, it shall be an error.
497 If there is no line count lines after the last line currently dis‐
498 played, the last line of the display shall display some portion of the
499 last line of the edit buffer.
500
501 Current line: Unchanged if the previous current character is displayed;
502 otherwise, set to the first line displayed.
503
504 Current column: Unchanged.
505
506 Page Forward
507 Synopsis:
508
509
510 [count] <control>-F
511
512
513 If in open mode, the <control>-F command shall behave identically to
514 the z command. Otherwise, if the current line is the last line of the
515 edit buffer, it shall be an error.
516
517 If the window edit option is less than 3, display a screen where the
518 first line of the display shall be some portion of:
519
520
521 (current last line) +1
522
523 otherwise, display a screen where the first line of the display shall
524 be some portion of:
525
526
527 (current first line) + count x ((window edit option) -2)
528
529 If this calculation would result in a line that is after the last line
530 of the edit buffer, the last line of the display shall display some
531 portion of the last line of the edit buffer.
532
533 Current line: If no lines from the previous display remain on the
534 screen, set to the first line of the display; otherwise, set to ( line
535 + the number of new lines displayed on this screen).
536
537 Current column: Set to non- <blank>.
538
539 Display Information
540 Synopsis:
541
542
543 <control>-G
544
545
546 This command shall be equivalent to the ex file command.
547
548 Move Cursor Backwards
549 Synopsis:
550
551
552 [count] <control>-H
553
554
555 [count] h
556
557
558 the current erase character (see stty)
559
560
561 If there are no characters before the current character on the current
562 line, it shall be an error. If there are less than count previous char‐
563 acters on the current line, count shall be adjusted to the number of
564 previous characters on the line.
565
566 If used as a motion command:
567
568 1. The text region shall be from the character before the starting
569 cursor up to and including the countth character before the start‐
570 ing cursor.
571
572 2. Any text copied to a buffer shall be in character mode.
573
574 If not used as a motion command:
575
576 Current line: Unchanged.
577
578 Current column: Set to ( column - the number of columns occupied by
579 count characters ending with the previous current column).
580
581 Move Down
582 Synopsis:
583
584
585 [count] <newline>
586
587
588 [count] <control>-J
589
590
591 [count] <control>-M
592
593
594 [count] <control>-N
595
596
597 [count] j
598
599
600 [count] <carriage-return>
601
602
603 [count] +
604
605
606 If there are less than count lines after the current line in the edit
607 buffer, it shall be an error.
608
609 If used as a motion command:
610
611 1. The text region shall include the starting line and the next count
612 - 1 lines.
613
614 2. Any text copied to a buffer shall be in line mode.
615
616 If not used as a motion command:
617
618 Current line: Set to current line+ count.
619
620 Current column: Set to non- <blank> for the <carriage-return>, <con‐
621 trol>-M, and + commands; otherwise, unchanged.
622
623 Clear and Redisplay
624 Synopsis:
625
626
627 <control>-L
628
629
630 If in open mode, clear the screen and redisplay the current line. Oth‐
631 erwise, clear and redisplay the screen.
632
633 Current line: Unchanged.
634
635 Current column: Unchanged.
636
637 Move Up
638 Synopsis:
639
640
641 [count] <control>-P
642
643
644 [count] k
645
646
647 [count] -
648
649
650 If there are less than count lines before the current line in the edit
651 buffer, it shall be an error.
652
653 If used as a motion command:
654
655 1. The text region shall include the starting line and the previous
656 count lines.
657
658 2. Any text copied to a buffer shall be in line mode.
659
660 If not used as a motion command:
661
662 Current line: Set to current line - count.
663
664 Current column: Set to non- <blank> for the - command; otherwise,
665 unchanged.
666
667 Redraw Screen
668 Synopsis:
669
670
671 <control>-R
672
673
674 If any lines have been deleted from the display screen and flagged as
675 deleted on the terminal using the @ convention (see the beginning of
676 the EXTENDED DESCRIPTION section), they shall be redisplayed to match
677 the contents of the edit buffer.
678
679 It is unspecified whether lines flagged with @ because they do not fit
680 on the terminal display shall be affected.
681
682 Current line: Unchanged.
683
684 Current column: Unchanged.
685
686 Scroll Backward
687 Synopsis:
688
689
690 [count] <control>-U
691
692
693 If the current line is the first line of the edit buffer, it shall be
694 an error.
695
696 If no count is specified, count shall default to the count associated
697 with the previous <control>-D or <control>-U command. If there was no
698 previous <control>-D or <control>-U command, count shall default to the
699 value of the scroll edit option.
700
701 Current line: If count is greater than the current line, set to 1; oth‐
702 erwise, set to the current line - count.
703
704 Current column: Set to non- <blank>.
705
706 Scroll Backward by Line
707 Synopsis:
708
709
710 [count] <control>-Y
711
712
713 Display the line count lines before the first line currently displayed.
714
715 If the current line is the first line of the edit buffer, it shall be
716 an error. If this calculation would result in a line that is before the
717 first line of the edit buffer, the first line of the display shall dis‐
718 play some portion of the first line of the edit buffer.
719
720 Current line: Unchanged if the previous current character is displayed;
721 otherwise, set to the first line displayed.
722
723 Current column: Unchanged.
724
725 Edit the Alternate File
726 Synopsis:
727
728
729 <control>-^
730
731 This command shall be equivalent to the ex edit command, with the
732 alternate pathname as its argument.
733
734 Terminate Command or Input Mode
735 Synopsis:
736
737
738 <ESC>
739
740
741 If a partial vi command (as defined by at least one, non- count charac‐
742 ter) has been entered, discard the count and the command character(s).
743
744 Otherwise, if no command characters have been entered, and the <ESC>
745 was the result of a map expansion, the terminal shall be alerted and
746 the <ESC> character shall be discarded, but it shall not be an error.
747
748 Otherwise, it shall be an error.
749
750 Current line: Unchanged.
751
752 Current column: Unchanged.
753
754 Search for tagstring
755 Synopsis:
756
757
758 <control>-]
759
760
761 If the current character is not a word or <blank>, it shall be an
762 error.
763
764 This command shall be equivalent to the ex tag command, with the argu‐
765 ment to that command defined as follows.
766
767 If the current character is a <blank>:
768
769 1. Skip all <blank>s after the cursor up to the end of the line.
770
771 2. If the end of the line is reached, it shall be an error.
772
773 Then, the argument to the ex tag command shall be the current character
774 and all subsequent characters, up to the first non-word character or
775 the end of the line.
776
777 Move Cursor Forward
778 Synopsis:
779
780
781 [count] <space>
782
783
784 [count] l (ell)
785
786
787 If there are less than count non- <newline>s after the cursor on the
788 current line, count shall be adjusted to the number of non- <newline>s
789 after the cursor on the line.
790
791 If used as a motion command:
792
793 1. If the current or countth character after the cursor is the last
794 non- <newline> in the line, the text region shall be comprised of
795 the current character up to and including the last non- <newline>
796 in the line. Otherwise, the text region shall be from the current
797 character up to, but not including, the countth character after the
798 cursor.
799
800 2. Any text copied to a buffer shall be in character mode.
801
802 If not used as a motion command:
803
804 If there are no non- <newline>s after the current character on the cur‐
805 rent line, it shall be an error.
806
807 Current line: Unchanged.
808
809 Current column: Set to the last column that displays any portion of the
810 countth character after the current character.
811
812 Replace Text with Results from Shell Command
813 Synopsis:
814
815
816 [count] ! motion shell-commands <newline>
817
818
819 If the motion command is the ! command repeated:
820
821 1. If the edit buffer is empty and no count was supplied, the command
822 shall be the equivalent of the ex :read ! command, with the text
823 input, and no text shall be copied to any buffer.
824
825 2. Otherwise:
826
827 a. If there are less than count -1 lines after the current line in
828 the edit buffer, it shall be an error.
829
830 b. The text region shall be from the current line up to and
831 including the next count -1 lines.
832
833 Otherwise, the text region shall be the lines in which any character of
834 the text region specified by the motion command appear.
835
836 Any text copied to a buffer shall be in line mode.
837
838 This command shall be equivalent to the ex ! command for the specified
839 lines.
840
841 Move Cursor to End-of-Line
842 Synopsis:
843
844
845 [count] $
846
847
848 It shall be an error if there are less than ( count -1) lines after the
849 current line in the edit buffer.
850
851 If used as a motion command:
852
853 1. If count is 1:
854
855 a. It shall be an error if the line is empty.
856
857 b. Otherwise, the text region shall consist of all characters from
858 the starting cursor to the last non- <newline> in the line,
859 inclusive, and any text copied to a buffer shall be in charac‐
860 ter mode.
861
862 2. Otherwise, if the starting cursor position is at or before the
863 first non- <blank> in the line, the text region shall consist of
864 the current and the next count -1 lines, and any text saved to a
865 buffer shall be in line mode.
866
867 3. Otherwise, the text region shall consist of all characters from the
868 starting cursor to the last non- <newline> in the line that is
869 count -1 lines forward from the current line, and any text copied
870 to a buffer shall be in character mode.
871
872 If not used as a motion command:
873
874 Current line: Set to the current line + count-1.
875
876 Current column: The current column is set to the last display line col‐
877 umn of the last non- <newline> in the line, or column position 1 if the
878 line is empty.
879
880 The current column shall be adjusted to be on the last display line
881 column of the last non- <newline> of the current line as subsequent
882 commands change the current line, until a command changes the current
883 column.
884
885 Move to Matching Character
886 Synopsis:
887
888
889 %
890
891
892 If the character at the current position is not a parenthesis, bracket,
893 or curly brace, search forward in the line to the first one of those
894 characters. If no such character is found, it shall be an error.
895
896 The matching character shall be the parenthesis, bracket, or curly
897 brace matching the parenthesis, bracket, or curly brace, respectively,
898 that was at the current position or that was found on the current line.
899
900 Matching shall be determined as follows, for an open parenthesis:
901
902 1. Set a counter to 1.
903
904 2. Search forwards until a parenthesis is found or the end of the edit
905 buffer is reached.
906
907 3. If the end of the edit buffer is reached, it shall be an error.
908
909 4. If an open parenthesis is found, increment the counter by 1.
910
911 5. If a close parenthesis is found, decrement the counter by 1.
912
913 6. If the counter is zero, the current character is the matching char‐
914 acter.
915
916 Matching for a close parenthesis shall be equivalent, except that the
917 search shall be backwards, from the starting character to the beginning
918 of the buffer, a close parenthesis shall increment the counter by 1,
919 and an open parenthesis shall decrement the counter by 1.
920
921 Matching for brackets and curly braces shall be equivalent, except that
922 searching shall be done for open and close brackets or open and close
923 curly braces. It is implementation-defined whether other characters are
924 searched for and matched as well.
925
926 If used as a motion command:
927
928 1. If the matching cursor was after the starting cursor in the edit
929 buffer, and the starting cursor position was at or before the first
930 non- <blank> non- <newline> in the starting line, and the matching
931 cursor position was at or after the last non- <blank> non- <new‐
932 line> in the matching line, the text region shall consist of the
933 current line to the matching line, inclusive, and any text copied
934 to a buffer shall be in line mode.
935
936 2. If the matching cursor was before the starting cursor in the edit
937 buffer, and the starting cursor position was at or after the last
938 non- <blank> non- <newline> in the starting line, and the matching
939 cursor position was at or before the first non- <blank> non- <new‐
940 line> in the matching line, the text region shall consist of the
941 current line to the matching line, inclusive, and any text copied
942 to a buffer shall be in line mode.
943
944 3. Otherwise, the text region shall consist of the starting character
945 to the matching character, inclusive, and any text copied to a buf‐
946 fer shall be in character mode.
947
948 If not used as a motion command:
949
950 Current line: Set to the line where the matching character is located.
951
952 Current column: Set to the last column where any portion of the match‐
953 ing character is displayed.
954
955 Repeat Substitution
956 Synopsis:
957
958
959 &
960
961
962 Repeat the previous substitution command. This command shall be equiva‐
963 lent to the ex & command with the current line as its addresses, and
964 without options, count, or flags.
965
966 Return to Previous Context at Beginning of Line
967 Synopsis:
968
969
970 ' character
971
972
973 It shall be an error if there is no line in the edit buffer marked by
974 character.
975
976 If used as a motion command:
977
978 1. If the starting cursor is after the marked cursor, then the loca‐
979 tions of the starting cursor and the marked cursor in the edit buf‐
980 fer shall be logically swapped.
981
982 2. The text region shall consist of the starting line up to and
983 including the marked line, and any text copied to a buffer shall be
984 in line mode.
985
986 If not used as a motion command:
987
988 Current line: Set to the line referenced by the mark.
989
990 Current column: Set to non- <blank>.
991
992 Return to Previous Context
993 Synopsis:
994
995
996 ` character
997
998
999 It shall be an error if the marked line is no longer in the edit buf‐
1000 fer. If the marked line no longer contains a character in the saved
1001 numbered character position, it shall be as if the marked position is
1002 the first non- <blank>.
1003
1004 If used as a motion command:
1005
1006 1. It shall be an error if the marked cursor references the same char‐
1007 acter in the edit buffer as the starting cursor.
1008
1009 2. If the starting cursor is after the marked cursor, then the loca‐
1010 tions of the starting cursor and the marked cursor in the edit buf‐
1011 fer shall be logically swapped.
1012
1013 3. If the starting line is empty or the starting cursor is at or
1014 before the first non- <blank> non- <newline> of the starting line,
1015 and the marked cursor line is empty or the marked cursor references
1016 the first character of the marked cursor line, the text region
1017 shall consist of all lines containing characters from the starting
1018 cursor to the line before the marked cursor line, inclusive, and
1019 any text copied to a buffer shall be in line mode.
1020
1021 4. Otherwise, if the marked cursor line is empty or the marked cursor
1022 references a character at or before the first non- <blank> non-
1023 <newline> of the marked cursor line, the region of text shall be
1024 from the starting cursor to the last non- <newline> of the line
1025 before the marked cursor line, inclusive, and any text copied to a
1026 buffer shall be in character mode.
1027
1028 5. Otherwise, the region of text shall be from the starting cursor
1029 (inclusive), to the marked cursor (exclusive), and any text copied
1030 to a buffer shall be in character mode.
1031
1032 If not used as a motion command:
1033
1034 Current line: Set to the line referenced by the mark.
1035
1036 Current column: Set to the last column in which any portion of the
1037 character referenced by the mark is displayed.
1038
1039 Return to Previous Section
1040 Synopsis:
1041
1042
1043 [count] [[
1044
1045
1046 Move the cursor backward through the edit buffer to the first character
1047 of the previous section boundary, count times.
1048
1049 If used as a motion command:
1050
1051 1. If the starting cursor was at the first character of the starting
1052 line or the starting line was empty, and the first character of the
1053 boundary was the first character of the boundary line, the text
1054 region shall consist of the current line up to and including the
1055 line where the countth next boundary starts, and any text copied to
1056 a buffer shall be in line mode.
1057
1058 2. If the boundary was the last line of the edit buffer or the last
1059 non- <newline> of the last line of the edit buffer, the text region
1060 shall consist of the last character in the edit buffer up to and
1061 including the starting character, and any text saved to a buffer
1062 shall be in character mode.
1063
1064 3. Otherwise, the text region shall consist of the starting character
1065 up to but not including the first character in the countth next
1066 boundary, and any text copied to a buffer shall be in character
1067 mode.
1068
1069 If not used as a motion command:
1070
1071 Current line: Set to the line where the countth next boundary in the
1072 edit buffer starts.
1073
1074 Current column: Set to the last column in which any portion of the
1075 first character of the countth next boundary is displayed, or column
1076 position 1 if the line is empty.
1077
1078 Move to Next Section
1079 Synopsis:
1080
1081
1082 [count] ]]
1083
1084
1085 Move the cursor forward through the edit buffer to the first character
1086 of the next section boundary, count times.
1087
1088 If used as a motion command:
1089
1090 1. If the starting cursor was at the first character of the starting
1091 line or the starting line was empty, and the first character of the
1092 boundary was the first character of the boundary line, the text
1093 region shall consist of the current line up to and including the
1094 line where the countth previous boundary starts, and any text
1095 copied to a buffer shall be in line mode.
1096
1097 2. If the boundary was the first line of the edit buffer, the text
1098 region shall consist of the first character in the edit buffer up
1099 to but not including the starting character, and any text copied to
1100 a buffer shall be in character mode.
1101
1102 3. Otherwise, the text region shall consist of the first character in
1103 the countth previous section boundary up to but not including the
1104 starting character, and any text copied to a buffer shall be in
1105 character mode.
1106
1107 If not used as a motion command:
1108
1109 Current line: Set to the line where the countth previous boundary in
1110 the edit buffer starts.
1111
1112 Current column: Set to the last column in which any portion of the
1113 first character of the countth previous boundary is displayed, or col‐
1114 umn position 1 if the line is empty.
1115
1116 Move to First Non-<blank> Position on Current Line
1117 Synopsis:
1118
1119
1120 ^
1121
1122 If used as a motion command:
1123
1124 1. If the line has no non- <blank> non- <newline>s, or if the cursor
1125 is at the first non- <blank> non- <newline> of the line, it shall
1126 be an error.
1127
1128 2. If the cursor is before the first non- <blank> non- <newline> of
1129 the line, the text region shall be comprised of the current charac‐
1130 ter, up to, but not including, the first non- <blank> non- <new‐
1131 line> of the line.
1132
1133 3. If the cursor is after the first non- <blank> non- <newline> of the
1134 line, the text region shall be from the character before the start‐
1135 ing cursor up to and including the first non- <blank> non- <new‐
1136 line> of the line.
1137
1138 4. Any text copied to a buffer shall be in character mode.
1139
1140 If not used as a motion command:
1141
1142 Current line: Unchanged.
1143
1144 Current column: Set to non- <blank>.
1145
1146 Current and Line Above
1147 Synopsis:
1148
1149
1150 [count] _
1151
1152
1153 If there are less than count -1 lines after the current line in the
1154 edit buffer, it shall be an error.
1155
1156 If used as a motion command:
1157
1158 1. If count is less than 2, the text region shall be the current line.
1159
1160 2. Otherwise, the text region shall include the starting line and the
1161 next count -1 lines.
1162
1163 3. Any text copied to a buffer shall be in line mode.
1164
1165 If not used as a motion command:
1166
1167 Current line: Set to current line + count -1.
1168
1169 Current column: Set to non- <blank>.
1170
1171 Move Back to Beginning of Sentence
1172 Synopsis:
1173
1174
1175 [count] (
1176
1177
1178 Move backward to the beginning of a sentence. This command shall be
1179 equivalent to the [[ command, with the exception that sentence bound‐
1180 aries shall be used instead of section boundaries.
1181
1182 Move Forward to Beginning of Sentence
1183 Synopsis:
1184
1185
1186 [count] )
1187
1188
1189 Move forward to the beginning of a sentence. This command shall be
1190 equivalent to the ]] command, with the exception that sentence bound‐
1191 aries shall be used instead of section boundaries.
1192
1193 Move Back to Preceding Paragraph
1194 Synopsis:
1195
1196
1197 [count] {
1198
1199
1200 Move back to the beginning of the preceding paragraph. This command
1201 shall be equivalent to the [[ command, with the exception that para‐
1202 graph boundaries shall be used instead of section boundaries.
1203
1204 Move Forward to Next Paragraph
1205 Synopsis:
1206
1207
1208 [count] }
1209
1210
1211 Move forward to the beginning of the next paragraph. This command shall
1212 be equivalent to the ]] command, with the exception that paragraph
1213 boundaries shall be used instead of section boundaries.
1214
1215 Move to Specific Column Position
1216 Synopsis:
1217
1218
1219 [count] |
1220
1221
1222 For the purposes of this command, lines that are too long for the cur‐
1223 rent display and that have been folded shall be treated as having a
1224 single, 1-based, number of columns.
1225
1226 If there are less than count columns in which characters from the cur‐
1227 rent line are displayed on the screen, count shall be adjusted to be
1228 the last column in which any portion of the line is displayed on the
1229 screen.
1230
1231 If used as a motion command:
1232
1233 1. If the line is empty, or the cursor character is the same as the
1234 character on the countth column of the line, it shall be an error.
1235
1236 2. If the cursor is before the countth column of the line, the text
1237 region shall be comprised of the current character, up to but not
1238 including the character on the countth column of the line.
1239
1240 3. If the cursor is after the countth column of the line, the text
1241 region shall be from the character before the starting cursor up to
1242 and including the character on the countth column of the line.
1243
1244 4. Any text copied to a buffer shall be in character mode.
1245
1246 If not used as a motion command:
1247
1248 Current line: Unchanged.
1249
1250 Current column: Set to the last column in which any portion of the
1251 character that is displayed in the count column of the line is dis‐
1252 played.
1253
1254 Reverse Find Character
1255 Synopsis:
1256
1257
1258 [count] ,
1259
1260
1261 If the last F, f, T, or t command was F, f, T, or t, this command shall
1262 be equivalent to an f, F, t, or T command, respectively, with the spec‐
1263 ified count and the same search character.
1264
1265 If there was no previous F, f, T, or t command, it shall be an error.
1266
1267 Repeat
1268 Synopsis:
1269
1270
1271 [count] .
1272
1273
1274 Repeat the last !, <, >, A, C, D, I, J, O, P, R, S, X, Y, a, c, d, i,
1275 o, p, r, s, x, y, or ~ command. It shall be an error if none of these
1276 commands have been executed. Commands (other than commands that enter
1277 text input mode) executed as a result of map expansions, shall not
1278 change the value of the last repeatable command.
1279
1280 Repeated commands with associated motion commands shall repeat the
1281 motion command as well; however, any specified count shall replace the
1282 count(s) that were originally specified to the repeated command or its
1283 associated motion command.
1284
1285 If the motion component of the repeated command is f, F, t, or T, the
1286 repeated command shall not set the remembered search character for the
1287 ; and , commands.
1288
1289 If the repeated command is p or P, and the buffer associated with that
1290 command was a numeric buffer named with a number less than 9, the buf‐
1291 fer associated with the repeated command shall be set to be the buffer
1292 named by the name of the previous buffer logically incremented by 1.
1293
1294 If the repeated character is a text input command, the input text asso‐
1295 ciated with that command is repeated literally:
1296
1297 * Input characters are neither macro or abbreviation-expanded.
1298
1299 * Input characters are not interpreted in any special way with the
1300 exception that <newline>, <carriage-return>, and <control>-T behave
1301 as described in Input Mode Commands in vi .
1302
1303 Current line: Set as described for the repeated command.
1304
1305 Current column: Set as described for the repeated command.
1306
1307 Find Regular Expression
1308 Synopsis:
1309
1310
1311 /
1312
1313
1314 If the input line contains no non- <newline>s, it shall be equivalent
1315 to a line containing only the last regular expression encountered. The
1316 enhanced regular expressions supported by vi are described in Regular
1317 Expressions in ex .
1318
1319 Otherwise, the line shall be interpreted as one or more regular expres‐
1320 sions, optionally followed by an address offset or a vi z command.
1321
1322 If the regular expression is not the last regular expression on the
1323 line, or if a line offset or z command is specified, the regular
1324 expression shall be terminated by an unescaped '/' character, which
1325 shall not be used as part of the regular expression. If the regular
1326 expression is not the first regular expression on the line, it shall be
1327 preceded by zero or more <blank>s, a semicolon, zero or more <blank>s,
1328 and a leading '/' character, which shall not be interpreted as part of
1329 the regular expression. It shall be an error to precede any regular
1330 expression with any characters other than these.
1331
1332 Each search shall begin from the character after the first character of
1333 the last match (or, if it is the first search, after the cursor). If
1334 the wrapscan edit option is set, the search shall continue to the char‐
1335 acter before the starting cursor character; otherwise, to the end of
1336 the edit buffer. It shall be an error if any search fails to find a
1337 match, and an informational message to this effect shall be displayed.
1338
1339 An optional address offset (see Addressing in ex ) can be specified
1340 after the last regular expression by including a trailing '/' character
1341 after the regular expression and specifying the address offset. This
1342 offset will be from the line containing the match for the last regular
1343 expression specified. It shall be an error if the line offset would
1344 indicate a line address less than 1 or greater than the last line in
1345 the edit buffer. An address offset of zero shall be supported. It shall
1346 be an error to follow the address offset with any other characters than
1347 <blank>s.
1348
1349 If not used as a motion command, an optional z command (see Redraw Win‐
1350 dow ) can be specified after the last regular expression by including a
1351 trailing '/' character after the regular expression, zero or more
1352 <blank>s, a 'z', zero or more <blank>s, an optional new window edit
1353 option value, zero or more <blank>s, and a location character. The
1354 effect shall be as if the z command was executed after the / command.
1355 It shall be an error to follow the z command with any other characters
1356 than <blank>s.
1357
1358 The remembered search direction shall be set to forward.
1359
1360 If used as a motion command:
1361
1362 1. It shall be an error if the last match references the same charac‐
1363 ter in the edit buffer as the starting cursor.
1364
1365 2. If any address offset is specified, the last match shall be
1366 adjusted by the specified offset as described previously.
1367
1368 3. If the starting cursor is after the last match, then the locations
1369 of the starting cursor and the last match in the edit buffer shall
1370 be logically swapped.
1371
1372 4. If any address offset is specified, the text region shall consist
1373 of all lines containing characters from the starting cursor to the
1374 last match line, inclusive, and any text copied to a buffer shall
1375 be in line mode.
1376
1377 5. Otherwise, if the starting line is empty or the starting cursor is
1378 at or before the first non- <blank> non- <newline> of the starting
1379 line, and the last match line is empty or the last match starts at
1380 the first character of the last match line, the text region shall
1381 consist of all lines containing characters from the starting cursor
1382 to the line before the last match line, inclusive, and any text
1383 copied to a buffer shall be in line mode.
1384
1385 6. Otherwise, if the last match line is empty or the last match begins
1386 at a character at or before the first non- <blank> non- <newline>
1387 of the last match line, the region of text shall be from the cur‐
1388 rent cursor to the last non- <newline> of the line before the last
1389 match line, inclusive, and any text copied to a buffer shall be in
1390 character mode.
1391
1392 7. Otherwise, the region of text shall be from the current cursor
1393 (inclusive), to the first character of the last match (exclusive),
1394 and any text copied to a buffer shall be in character mode.
1395
1396 If not used as a motion command:
1397
1398 Current line: If a match is found, set to the last matched line plus
1399 the address offset, if any; otherwise, unchanged.
1400
1401 Current column: Set to the last column on which any portion of the
1402 first character in the last matched string is displayed, if a match is
1403 found; otherwise, unchanged.
1404
1405 Move to First Character in Line
1406 Synopsis:
1407
1408
1409 0 (zero)
1410
1411
1412 Move to the first character on the current line. The character '0'
1413 shall not be interpreted as a command if it is immediately preceded by
1414 a digit.
1415
1416 If used as a motion command:
1417
1418 1. If the cursor character is the first character in the line, it
1419 shall be an error.
1420
1421 2. The text region shall be from the character before the cursor char‐
1422 acter up to and including the first character in the line.
1423
1424 3. Any text copied to a buffer shall be in character mode.
1425
1426 If not used as a motion command:
1427
1428 Current line: Unchanged.
1429
1430 Current column: The last column in which any portion of the first char‐
1431 acter in the line is displayed, or if the line is empty, unchanged.
1432
1433 Execute an ex Command
1434 Synopsis:
1435
1436
1437 :
1438
1439
1440 Execute one or more ex commands.
1441
1442 If any portion of the screen other than the last line of the screen was
1443 overwritten by any ex command (except shell), vi shall display a mes‐
1444 sage indicating that it is waiting for an input from the user, and
1445 shall then read a character. This action may also be taken for other,
1446 unspecified reasons.
1447
1448 If the next character entered is a ':', another ex command shall be
1449 accepted and executed. Any other character shall cause the screen to be
1450 refreshed and vi shall return to command mode.
1451
1452 Current line: As specified for the ex command.
1453
1454 Current column: As specified for the ex command.
1455
1456 Repeat Find
1457 Synopsis:
1458
1459
1460 [count] ;
1461
1462
1463 This command shall be equivalent to the last F, f, T, or t command,
1464 with the specified count, and with the same search character used for
1465 the last F, f, T, or t command. If there was no previous F, f, T, or t
1466 command, it shall be an error.
1467
1468 Shift Left
1469 Synopsis:
1470
1471
1472 [count] < motion
1473
1474
1475 If the motion command is the < command repeated:
1476
1477 1. If there are less than count -1 lines after the current line in the
1478 edit buffer, it shall be an error.
1479
1480 2. The text region shall be from the current line, up to and including
1481 the next count -1 lines.
1482
1483 Shift any line in the text region specified by the count and motion
1484 command one shiftwidth (see the ex shiftwidth option) toward the start
1485 of the line, as described by the ex < command. The unshifted lines
1486 shall be copied to the unnamed buffer in line mode.
1487
1488 Current line: If the motion was from the current cursor position toward
1489 the end of the edit buffer, unchanged. Otherwise, set to the first line
1490 in the edit buffer that is part of the text region specified by the
1491 motion command.
1492
1493 Current column: Set to non- <blank>.
1494
1495 Shift Right
1496 Synopsis:
1497
1498
1499 [count] > motion
1500
1501
1502 If the motion command is the > command repeated:
1503
1504 1. If there are less than count -1 lines after the current line in the
1505 edit buffer, it shall be an error.
1506
1507 2. The text region shall be from the current line, up to and including
1508 the next count -1 lines.
1509
1510 Shift any line with characters in the text region specified by the
1511 count and motion command one shiftwidth (see the ex shiftwidth option)
1512 away from the start of the line, as described by the ex > command. The
1513 unshifted lines shall be copied into the unnamed buffer in line mode.
1514
1515 Current line: If the motion was from the current cursor position toward
1516 the end of the edit buffer, unchanged. Otherwise, set to the first line
1517 in the edit buffer that is part of the text region specified by the
1518 motion command.
1519
1520 Current column: Set to non- <blank>.
1521
1522 Scan Backwards for Regular Expression
1523 Synopsis:
1524
1525
1526 ?
1527
1528
1529 Scan backwards; the ? command shall be equivalent to the / command (see
1530 Find Regular Expression ) with the following exceptions:
1531
1532 1. The input prompt shall be a '?' .
1533
1534 2. Each search shall begin from the character before the first charac‐
1535 ter of the last match (or, if it is the first search, the character
1536 before the cursor character).
1537
1538 3. The search direction shall be from the cursor toward the beginning
1539 of the edit buffer, and the wrapscan edit option shall affect
1540 whether the search wraps to the end of the edit buffer and contin‐
1541 ues.
1542
1543 4. The remembered search direction shall be set to backward.
1544
1545 Execute
1546 Synopsis:
1547
1548
1549 @buffer
1550
1551
1552 If the buffer is specified as @, the last buffer executed shall be
1553 used. If no previous buffer has been executed, it shall be an error.
1554
1555 Behave as if the contents of the named buffer were entered as standard
1556 input. After each line of a line-mode buffer, and all but the last line
1557 of a character mode buffer, behave as if a <newline> were entered as
1558 standard input.
1559
1560 If an error occurs during this process, an error message shall be writ‐
1561 ten, and no more characters resulting from the execution of this com‐
1562 mand shall be processed.
1563
1564 If a count is specified, behave as if that count were entered as user
1565 input before the characters from the @ buffer were entered.
1566
1567 Current line: As specified for the individual commands.
1568
1569 Current column: As specified for the individual commands.
1570
1571 Reverse Case
1572 Synopsis:
1573
1574
1575 [count] ~
1576
1577
1578 Reverse the case of the current character and the next count -1 charac‐
1579 ters, such that lowercase characters that have uppercase counterparts
1580 shall be changed to uppercase characters, and uppercase characters that
1581 have lowercase counterparts shall be changed to lowercase characters,
1582 as prescribed by the current locale. No other characters shall be
1583 affected by this command.
1584
1585 If there are less than count -1 characters after the cursor in the edit
1586 buffer, count shall be adjusted to the number of characters after the
1587 cursor in the edit buffer minus 1.
1588
1589 For the purposes of this command, the next character after the last
1590 non- <newline> on the line shall be the next character in the edit buf‐
1591 fer.
1592
1593 Current line: Set to the line including the ( count-1)th character
1594 after the cursor.
1595
1596 Current column: Set to the last column in which any portion of the (
1597 count-1)th character after the cursor is displayed.
1598
1599 Append
1600 Synopsis:
1601
1602
1603 [count] a
1604
1605
1606 Enter text input mode after the current cursor position. No characters
1607 already in the edit buffer shall be affected by this command. A count
1608 shall cause the input text to be appended count -1 more times to the
1609 end of the input.
1610
1611 Current line/column: As specified for the text input commands (see
1612 Input Mode Commands in vi ).
1613
1614 Append at End-of-Line
1615 Synopsis:
1616
1617
1618 [count] A
1619
1620
1621 This command shall be equivalent to the vi command:
1622
1623
1624 $ [ count ] a
1625
1626 (see Append ).
1627
1628 Move Backward to Preceding Word
1629 Synopsis:
1630
1631
1632 [count] b
1633
1634
1635 With the exception that words are used as the delimiter instead of big‐
1636 words, this command shall be equivalent to the B command.
1637
1638 Move Backward to Preceding Bigword
1639 Synopsis:
1640
1641
1642 [count] B
1643
1644
1645 If the edit buffer is empty or the cursor is on the first character of
1646 the edit buffer, it shall be an error. If less than count bigwords
1647 begin between the cursor and the start of the edit buffer, count shall
1648 be adjusted to the number of bigword beginnings between the cursor and
1649 the start of the edit buffer.
1650
1651 If used as a motion command:
1652
1653 1. The text region shall be from the first character of the countth
1654 previous bigword beginning up to but not including the cursor char‐
1655 acter.
1656
1657 2. Any text copied to a buffer shall be in character mode.
1658
1659 If not used as a motion command:
1660
1661 Current line: Set to the line containing the current column.
1662
1663 Current column: Set to the last column upon which any part of the first
1664 character of the countth previous bigword is displayed.
1665
1666 Change
1667 Synopsis:
1668
1669
1670 [buffer][count] c motion
1671
1672
1673 If the motion command is the c command repeated:
1674
1675 1. The buffer text shall be in line mode.
1676
1677 2. If there are less than count -1 lines after the current line in the
1678 edit buffer, it shall be an error.
1679
1680 3. The text region shall be from the current line up to and including
1681 the next count -1 lines.
1682
1683 Otherwise, the buffer text mode and text region shall be as specified
1684 by the motion command.
1685
1686 The replaced text shall be copied into buffer, if specified, and into
1687 the unnamed buffer. If the text to be replaced contains characters from
1688 more than a single line, or the buffer text is in line mode, the
1689 replaced text shall be copied into the numeric buffers as well.
1690
1691 If the buffer text is in line mode:
1692
1693 1. Any lines that contain characters in the region shall be deleted,
1694 and the editor shall enter text input mode at the beginning of a
1695 new line which shall replace the first line deleted.
1696
1697 2. If the autoindent edit option is set, autoindent characters equal
1698 to the autoindent characters on the first line deleted shall be
1699 inserted as if entered by the user.
1700
1701 Otherwise, if characters from more than one line are in the region of
1702 text:
1703
1704 1. The text shall be deleted.
1705
1706 2. Any text remaining in the last line in the text region shall be
1707 appended to the first line in the region, and the last line in the
1708 region shall be deleted.
1709
1710 3. The editor shall enter text input mode after the last character not
1711 deleted from the first line in the text region, if any; otherwise,
1712 on the first column of the first line in the region.
1713
1714 Otherwise:
1715
1716 1. If the glyph for '$' is smaller than the region, the end of the
1717 region shall be marked with a '$' .
1718
1719 2. The editor shall enter text input mode, overwriting the region of
1720 text.
1721
1722 Current line/column: As specified for the text input commands (see
1723 Input Mode Commands in vi ).
1724
1725 Change to End-of-Line
1726 Synopsis:
1727
1728
1729 [buffer][count] C
1730
1731
1732 This command shall be equivalent to the vi command:
1733
1734
1735 [buffer][count] c$
1736
1737 See the c command.
1738
1739 Delete
1740 Synopsis:
1741
1742
1743 [buffer][count] d motion
1744
1745
1746 If the motion command is the d command repeated:
1747
1748 1. The buffer text shall be in line mode.
1749
1750 2. If there are less than count -1 lines after the current line in the
1751 edit buffer, it shall be an error.
1752
1753 3. The text region shall be from the current line up to and including
1754 the next count -1 lines.
1755
1756 Otherwise, the buffer text mode and text region shall be as specified
1757 by the motion command.
1758
1759 If in open mode, and the current line is deleted, and the line remains
1760 on the display, an '@' character shall be displayed as the first glyph
1761 of that line.
1762
1763 Delete the region of text into buffer, if specified, and into the
1764 unnamed buffer. If the text to be deleted contains characters from more
1765 than a single line, or the buffer text is in line mode, the deleted
1766 text shall be copied into the numeric buffers, as well.
1767
1768 Current line: Set to the first text region line that appears in the
1769 edit buffer, unless that line has been deleted, in which case it shall
1770 be set to the last line in the edit buffer, or line 1 if the edit buf‐
1771 fer is empty.
1772
1773 Current column:
1774
1775 1. If the line is empty, set to column position 1.
1776
1777 2. Otherwise, if the buffer text is in line mode or the motion was
1778 from the cursor toward the end of the edit buffer:
1779
1780 a. If a character from the current line is displayed in the cur‐
1781 rent column, set to the last column that displays any portion
1782 of that character.
1783
1784 b. Otherwise, set to the last column in which any portion of any
1785 character in the line is displayed.
1786
1787 3. Otherwise, if a character is displayed in the column that began the
1788 text region, set to the last column that displays any portion of
1789 that character.
1790
1791 4. Otherwise, set to the last column in which any portion of any char‐
1792 acter in the line is displayed.
1793
1794 Delete to End-of-Line
1795 Synopsis:
1796
1797
1798 [buffer] D
1799
1800
1801 Delete the text from the current position to the end of the current
1802 line; equivalent to the vi command:
1803
1804
1805 [buffer] d$
1806
1807 Move to End-of-Word
1808 Synopsis:
1809
1810
1811 [count] e
1812
1813
1814 With the exception that words are used instead of bigwords as the
1815 delimiter, this command shall be equivalent to the E command.
1816
1817 Move to End-of-Bigword
1818 Synopsis:
1819
1820
1821 [count] E
1822
1823
1824 If the edit buffer is empty it shall be an error. If less than count
1825 bigwords end between the cursor and the end of the edit buffer, count
1826 shall be adjusted to the number of bigword endings between the cursor
1827 and the end of the edit buffer.
1828
1829 If used as a motion command:
1830
1831 1. The text region shall be from the last character of the countth
1832 next bigword up to and including the cursor character.
1833
1834 2. Any text copied to a buffer shall be in character mode.
1835
1836 If not used as a motion command:
1837
1838 Current line: Set to the line containing the current column.
1839
1840 Current column: Set to the last column upon which any part of the last
1841 character of the countth next bigword is displayed.
1842
1843 Find Character in Current Line (Forward)
1844 Synopsis:
1845
1846
1847 [count] f character
1848
1849
1850 It shall be an error if count occurrences of the character do not occur
1851 after the cursor in the line.
1852
1853 If used as a motion command:
1854
1855 1. The text range shall be from the cursor character up to and includ‐
1856 ing the countth occurrence of the specified character after the
1857 cursor.
1858
1859 2. Any text copied to a buffer shall be in character mode.
1860
1861 If not used as a motion command:
1862
1863 Current line: Unchanged.
1864
1865 Current column: Set to the last column in which any portion of the
1866 countth occurrence of the specified character after the cursor appears
1867 in the line.
1868
1869 Find Character in Current Line (Reverse)
1870 Synopsis:
1871
1872
1873 [count] F character
1874
1875
1876 It shall be an error if count occurrences of the character do not occur
1877 before the cursor in the line.
1878
1879 If used as a motion command:
1880
1881 1. The text region shall be from the countth occurrence of the speci‐
1882 fied character before the cursor, up to, but not including the cur‐
1883 sor character.
1884
1885 2. Any text copied to a buffer shall be in character mode.
1886
1887 If not used as a motion command:
1888
1889 Current line: Unchanged.
1890
1891 Current column: Set to the last column in which any portion of the
1892 countth occurrence of the specified character before the cursor appears
1893 in the line.
1894
1895 Move to Line
1896 Synopsis:
1897
1898
1899 [count] G
1900
1901
1902 If count is not specified, it shall default to the last line of the
1903 edit buffer. If count is greater than the last line of the edit buffer,
1904 it shall be an error.
1905
1906 If used as a motion command:
1907
1908 1. The text region shall be from the cursor line up to and including
1909 the specified line.
1910
1911 2. Any text copied to a buffer shall be in line mode.
1912
1913 If not used as a motion command:
1914
1915 Current line: Set to count if count is specified; otherwise, the last
1916 line.
1917
1918 Current column: Set to non- <blank>.
1919
1920 Move to Top of Screen
1921 Synopsis:
1922
1923
1924 [count] H
1925
1926
1927 If the beginning of the line count greater than the first line of which
1928 any portion appears on the display does not exist, it shall be an
1929 error.
1930
1931 If used as a motion command:
1932
1933 1. If in open mode, the text region shall be the current line.
1934
1935 2. Otherwise, the text region shall be from the starting line up to
1936 and including (the first line of the display + count -1).
1937
1938 3. Any text copied to a buffer shall be in line mode.
1939
1940 If not used as a motion command:
1941
1942 If in open mode, this command shall set the current column to non-
1943 <blank> and do nothing else.
1944
1945 Otherwise, it shall set the current line and current column as follows.
1946
1947 Current line: Set to (the first line of the display + count -1).
1948
1949 Current column: Set to non- <blank>.
1950
1951 Insert Before Cursor
1952 Synopsis:
1953
1954
1955 [count] i
1956
1957
1958 Enter text input mode before the current cursor position. No characters
1959 already in the edit buffer shall be affected by this command. A count
1960 shall cause the input text to be appended count -1 more times to the
1961 end of the input.
1962
1963 Current line/column: As specified for the text input commands (see
1964 Input Mode Commands in vi ).
1965
1966 Insert at Beginning of Line
1967 Synopsis:
1968
1969
1970 [count] I
1971
1972
1973 This command shall be equivalent to the vi command ^[ count] i.
1974
1975 Join
1976 Synopsis:
1977
1978
1979 [count] J
1980
1981
1982 If the current line is the last line in the edit buffer, it shall be an
1983 error.
1984
1985 This command shall be equivalent to the ex join command with no
1986 addresses, and an ex command count value of 1 if count was not speci‐
1987 fied or if a count of 1 was specified, and an ex command count value of
1988 count -1 for any other value of count, except that the current line and
1989 column shall be set as follows.
1990
1991 Current line: Unchanged.
1992
1993 Current column: The last column in which any portion of the character
1994 following the last character in the initial line is displayed, or the
1995 last non- <newline> in the line if no characters were appended.
1996
1997 Move to Bottom of Screen
1998 Synopsis:
1999
2000
2001 [count] L
2002
2003
2004 If the beginning of the line count less than the last line of which any
2005 portion appears on the display does not exist, it shall be an error.
2006
2007 If used as a motion command:
2008
2009 1. If in open mode, the text region shall be the current line.
2010
2011 2. Otherwise, the text region shall include all lines from the start‐
2012 ing cursor line to (the last line of the display -( count -1)).
2013
2014 3. Any text copied to a buffer shall be in line mode.
2015
2016 If not used as a motion command:
2017
2018 1. If in open mode, this command shall set the current column to non-
2019 <blank> and do nothing else.
2020
2021 2. Otherwise, it shall set the current line and current column as fol‐
2022 lows.
2023
2024 Current line: Set to (the last line of the display -( count -1)).
2025
2026 Current column: Set to non- <blank>.
2027
2028 Mark Position
2029 Synopsis:
2030
2031
2032 m letter
2033
2034
2035 This command shall be equivalent to the ex mark command with the speci‐
2036 fied character as an argument.
2037
2038 Move to Middle of Screen
2039 Synopsis:
2040
2041
2042 M
2043
2044
2045 The middle line of the display shall be calculated as follows:
2046
2047
2048 (the top line of the display) + (((number of lines displayed) +1) /2) -1
2049
2050 If used as a motion command:
2051
2052 1. If in open mode, the text region shall be the current line.
2053
2054 2. Otherwise, the text region shall include all lines from the start‐
2055 ing cursor line up to and including the middle line of the display.
2056
2057 3. Any text copied to a buffer shall be in line mode.
2058
2059 If not used as a motion command:
2060
2061 If in open mode, this command shall set the current column to non-
2062 <blank> and do nothing else.
2063
2064 Otherwise, it shall set the current line and current column as follows.
2065
2066 Current line: Set to the middle line of the display.
2067
2068 Current column: Set to non- <blank>.
2069
2070 Repeat Regular Expression Find (Forward)
2071 Synopsis:
2072
2073
2074 n
2075
2076
2077 If the remembered search direction was forward, the n command shall be
2078 equivalent to the vi / command with no characters entered by the user.
2079 Otherwise, it shall be equivalent to the vi ? command with no charac‐
2080 ters entered by the user.
2081
2082 If the n command is used as a motion command for the ! command, the
2083 editor shall not enter text input mode on the last line on the screen,
2084 and shall behave as if the user entered a single '!' character as the
2085 text input.
2086
2087 Repeat Regular Expression Find (Reverse)
2088 Synopsis:
2089
2090
2091 N
2092
2093
2094 Scan for the next match of the last pattern given to / or ?, but in the
2095 reverse direction; this is the reverse of n.
2096
2097 If the remembered search direction was forward, the N command shall be
2098 equivalent to the vi ? command with no characters entered by the user.
2099 Otherwise, it shall be equivalent to the vi / command with no charac‐
2100 ters entered by the user. If the N command is used as a motion command
2101 for the ! command, the editor shall not enter text input mode on the
2102 last line on the screen, and shall behave as if the user entered a sin‐
2103 gle ! character as the text input.
2104
2105 Insert Empty Line Below
2106 Synopsis:
2107
2108
2109 o
2110
2111
2112 Enter text input mode in a new line appended after the current line. A
2113 count shall cause the input text to be appended count -1 more times to
2114 the end of the already added text, each time starting on a new,
2115 appended line.
2116
2117 Current line/column: As specified for the text input commands (see
2118 Input Mode Commands in vi ).
2119
2120 Insert Empty Line Above
2121 Synopsis:
2122
2123
2124 O
2125
2126
2127 Enter text input mode in a new line inserted before the current line.
2128 A count shall cause the input text to be appended count -1 more times
2129 to the end of the already added text, each time starting on a new,
2130 appended line.
2131
2132 Current line/column: As specified for the text input commands (see
2133 Input Mode Commands in vi ).
2134
2135 Put from Buffer Following
2136 Synopsis:
2137
2138
2139 [buffer] p
2140
2141
2142 If no buffer is specified, the unnamed buffer shall be used.
2143
2144 If the buffer text is in line mode, the text shall be appended below
2145 the current line, and each line of the buffer shall become a new line
2146 in the edit buffer. A count shall cause the buffer text to be appended
2147 count -1 more times to the end of the already added text, each time
2148 starting on a new, appended line.
2149
2150 If the buffer text is in character mode, the text shall be appended
2151 into the current line after the cursor, and each line of the buffer
2152 other than the first and last shall become a new line in the edit buf‐
2153 fer. A count shall cause the buffer text to be appended count -1 more
2154 times to the end of the already added text, each time starting after
2155 the last added character.
2156
2157 Current line: If the buffer text is in line mode, set the line to line
2158 +1; otherwise, unchanged.
2159
2160 Current column: If the buffer text is in line mode:
2161
2162 1. If there is a non- <blank> in the first line of the buffer, set to
2163 the last column on which any portion of the first non- <blank> in
2164 the line is displayed.
2165
2166 2. If there is no non- <blank> in the first line of the buffer, set to
2167 the last column on which any portion of the last non- <newline> in
2168 the first line of the buffer is displayed.
2169
2170 If the buffer text is in character mode:
2171
2172 1. If the text in the buffer is from more than a single line, then set
2173 to the last column on which any portion of the first character from
2174 the buffer is displayed.
2175
2176 2. Otherwise, if the buffer is the unnamed buffer, set to the last
2177 column on which any portion of the last character from the buffer
2178 is displayed.
2179
2180 3. Otherwise, set to the first column on which any portion of the
2181 first character from the buffer is displayed.
2182
2183 Put from Buffer Before
2184 Synopsis:
2185
2186
2187 [buffer] P
2188
2189
2190 If no buffer is specified, the unnamed buffer shall be used.
2191
2192 If the buffer text is in line mode, the text shall be inserted above
2193 the current line, and each line of the buffer shall become a new line
2194 in the edit buffer. A count shall cause the buffer text to be appended
2195 count -1 more times to the end of the already added text, each time
2196 starting on a new, appended line.
2197
2198 If the buffer text is in character mode, the text shall be inserted
2199 into the current line before the cursor, and each line of the buffer
2200 other than the first and last shall become a new line in the edit buf‐
2201 fer. A count shall cause the buffer text to be appended count -1 more
2202 times to the end of the already added text, each time starting after
2203 the last added character.
2204
2205 Current line: Unchanged.
2206
2207 Current column: If the buffer text is in line mode:
2208
2209 1. If there is a non- <blank> in the first line of the buffer, set to
2210 the last column on which any portion of that character is dis‐
2211 played.
2212
2213 2. If there is no non- <blank> in the first line of the buffer, set to
2214 the last column on which any portion of the last non- <newline> in
2215 the first line of the buffer is displayed.
2216
2217 If the buffer text is in character mode:
2218
2219 1. If the buffer is the unnamed buffer, set to the last column on
2220 which any portion of the last character from the buffer is dis‐
2221 played.
2222
2223 2. Otherwise, set to the first column on which any portion of the
2224 first character from the buffer is displayed.
2225
2226 Enter ex Mode
2227 Synopsis:
2228
2229
2230 Q
2231
2232
2233 Leave visual or open mode and enter ex command mode.
2234
2235 Current line: Unchanged.
2236
2237 Current column: Unchanged.
2238
2239 Replace Character
2240 Synopsis:
2241
2242
2243 [count] r character
2244
2245
2246 Replace the count characters at and after the cursor with the specified
2247 character. If there are less than count non- <newline>s at and after
2248 the cursor on the line, it shall be an error.
2249
2250 If character is <control>-V, any next character other than the <new‐
2251 line> shall be stripped of any special meaning and used as a literal
2252 character.
2253
2254 If character is <ESC>, no replacement shall be made and the current
2255 line and current column shall be unchanged.
2256
2257 If character is <carriage-return> or <newline>, count new lines shall
2258 be appended to the current line. All but the last of these lines shall
2259 be empty. count characters at and after the cursor shall be discarded,
2260 and any remaining characters after the cursor in the current line shall
2261 be moved to the last of the new lines. If the autoindent edit option is
2262 set, they shall be preceded by the same number of autoindent characters
2263 found on the line from which the command was executed.
2264
2265 Current line: Unchanged unless the replacement character is a <car‐
2266 riage-return> or <newline>, in which case it shall be set to line +
2267 count.
2268
2269 Current column: Set to the last column position on which a portion of
2270 the last replaced character is displayed, or if the replacement charac‐
2271 ter caused new lines to be created, set to non- <blank>.
2272
2273 Replace Characters
2274 Synopsis:
2275
2276
2277 R
2278
2279
2280 Enter text input mode at the current cursor position possibly replacing
2281 text on the current line. A count shall cause the input text to be
2282 appended count -1 more times to the end of the input.
2283
2284 Current line/column: As specified for the text input commands (see
2285 Input Mode Commands in vi ).
2286
2287 Substitute Character
2288 Synopsis:
2289
2290
2291 [buffer][count] s
2292
2293
2294 This command shall be equivalent to the vi command:
2295
2296
2297 [buffer][count] c<space>
2298
2299 Substitute Lines
2300 Synopsis:
2301
2302
2303 [buffer][count] S
2304
2305
2306 This command shall be equivalent to the vi command:
2307
2308
2309 [buffer][count] c_
2310
2311 Move Cursor to Before Character (Forward)
2312 Synopsis:
2313
2314
2315 [count] t character
2316
2317
2318 It shall be an error if count occurrences of the character do not occur
2319 after the cursor in the line.
2320
2321 If used as a motion command:
2322
2323 1. The text region shall be from the cursor up to but not including
2324 the countth occurrence of the specified character after the cursor.
2325
2326 2. Any text copied to a buffer shall be in character mode.
2327
2328 If not used as a motion command:
2329
2330 Current line: Unchanged.
2331
2332 Current column: Set to the last column in which any portion of the
2333 character before the countth occurrence of the specified character
2334 after the cursor appears in the line.
2335
2336 Move Cursor to After Character (Reverse)
2337 Synopsis:
2338
2339
2340 [count] T character
2341
2342
2343 It shall be an error if count occurrences of the character do not occur
2344 before the cursor in the line.
2345
2346 If used as a motion command:
2347
2348 1. If the character before the cursor is the specified character, it
2349 shall be an error.
2350
2351 2. The text region shall be from the character before the cursor up to
2352 but not including the countth occurrence of the specified character
2353 before the cursor.
2354
2355 3. Any text copied to a buffer shall be in character mode.
2356
2357 If not used as a motion command:
2358
2359 Current line: Unchanged.
2360
2361 Current column: Set to the last column in which any portion of the
2362 character after the countth occurrence of the specified character
2363 before the cursor appears in the line.
2364
2365 Undo
2366 Synopsis:
2367
2368
2369 u
2370
2371
2372 This command shall be equivalent to the ex undo command except that the
2373 current line and current column shall be set as follows:
2374
2375 Current line: Set to the first line added or changed if any; otherwise,
2376 move to the line preceding any deleted text if one exists; otherwise,
2377 move to line 1.
2378
2379 Current column: If undoing an ex command, set to the first non-
2380 <blank>.
2381
2382 Otherwise, if undoing a text input command:
2383
2384 1. If the command was a C, c, O, o, R, S, or s command, the current
2385 column shall be set to the value it held when the text input com‐
2386 mand was entered.
2387
2388 2. Otherwise, set to the last column in which any portion of the first
2389 character after the deleted text is displayed, or, if no non- <new‐
2390 line>s follow the text deleted from this line, set to the last col‐
2391 umn in which any portion of the last non- <newline> in the line is
2392 displayed, or 1 if the line is empty.
2393
2394 Otherwise, if a single line was modified (that is, not added or
2395 deleted) by the u command:
2396
2397 1. If text was added or changed, set to the last column in which any
2398 portion of the first character added or changed is displayed.
2399
2400 2. If text was deleted, set to the last column in which any portion of
2401 the first character after the deleted text is displayed, or, if no
2402 non- <newline>s follow the deleted text, set to the last column in
2403 which any portion of the last non- <newline> in the line is dis‐
2404 played, or 1 if the line is empty.
2405
2406 Otherwise, set to non- <blank>.
2407
2408 Undo Current Line
2409 Synopsis:
2410
2411
2412 U
2413
2414
2415 Restore the current line to its state immediately before the most
2416 recent time that it became the current line.
2417
2418 Current line: Unchanged.
2419
2420 Current column: Set to the first column in the line in which any por‐
2421 tion of the first character in the line is displayed.
2422
2423 Move to Beginning of Word
2424 Synopsis:
2425
2426
2427 [count] w
2428
2429
2430 With the exception that words are used as the delimiter instead of big‐
2431 words, this command shall be equivalent to the W command.
2432
2433 Move to Beginning of Bigword
2434 Synopsis:
2435
2436
2437 [count] W
2438
2439
2440 If the edit buffer is empty, it shall be an error. If there are less
2441 than count bigwords between the cursor and the end of the edit buffer,
2442 count shall be adjusted to move the cursor to the last bigword in the
2443 edit buffer.
2444
2445 If used as a motion command:
2446
2447 1. If the associated command is c, count is 1, and the cursor is on a
2448 <blank>, the region of text shall be the current character and no
2449 further action shall be taken.
2450
2451 2. If there are less than count bigwords between the cursor and the
2452 end of the edit buffer, then the command shall succeed, and the
2453 region of text shall include the last character of the edit buffer.
2454
2455 3. If there are <blank>s or an end-of-line that precede the countth
2456 bigword, and the associated command is c, the region of text shall
2457 be up to and including the last character before the preceding
2458 <blank>s or end-of-line.
2459
2460 4. If there are <blank>s or an end-of-line that precede the bigword,
2461 and the associated command is d or y, the region of text shall be
2462 up to and including the last <blank> before the start of the big‐
2463 word or end-of-line.
2464
2465 5. Any text copied to a buffer shall be in character mode.
2466
2467 If not used as a motion command:
2468
2469 1. If the cursor is on the last character of the edit buffer, it shall
2470 be an error.
2471
2472 Current line: Set to the line containing the current column.
2473
2474 Current column: Set to the last column in which any part of the first
2475 character of the countth next bigword is displayed.
2476
2477 Delete Character at Cursor
2478 Synopsis:
2479
2480
2481 [buffer][count] x
2482
2483
2484 Delete the count characters at and after the current character into
2485 buffer, if specified, and into the unnamed buffer.
2486
2487 If the line is empty, it shall be an error. If there are less than
2488 count non- <newline>s at and after the cursor on the current line,
2489 count shall be adjusted to the number of non- <newline>s at and after
2490 the cursor.
2491
2492 Current line: Unchanged.
2493
2494 Current column: If the line is empty, set to column position 1. Other‐
2495 wise, if there were count or less non- <newline>s at and after the cur‐
2496 sor on the current line, set to the last column that displays any part
2497 of the last non- <newline> of the line. Otherwise, unchanged.
2498
2499 Delete Character Before Cursor
2500 Synopsis:
2501
2502
2503 [buffer][count] X
2504
2505
2506 Delete the count characters before the current character into buffer,
2507 if specified, and into the unnamed buffer.
2508
2509 If there are no characters before the current character on the current
2510 line, it shall be an error. If there are less than count previous char‐
2511 acters on the current line, count shall be adjusted to the number of
2512 previous characters on the line.
2513
2514 Current line: Unchanged.
2515
2516 Current column: Set to (current column - the width of the deleted char‐
2517 acters).
2518
2519 Yank
2520 Synopsis:
2521
2522
2523 [buffer][count] y motion
2524
2525
2526 Copy (yank) the region of text into buffer, if specified, and into the
2527 unnamed buffer.
2528
2529 If the motion command is the y command repeated:
2530
2531 1. The buffer shall be in line mode.
2532
2533 2. If there are less than count -1 lines after the current line in the
2534 edit buffer, it shall be an error.
2535
2536 3. The text region shall be from the current line up to and including
2537 the next count -1 lines.
2538
2539 Otherwise, the buffer text mode and text region shall be as specified
2540 by the motion command.
2541
2542 Current line: If the motion was from the current cursor position toward
2543 the end of the edit buffer, unchanged. Otherwise, set to the first line
2544 in the edit buffer that is part of the text region specified by the
2545 motion command.
2546
2547 Current column:
2548
2549 1. If the motion was from the current cursor position toward the end
2550 of the edit buffer, unchanged.
2551
2552 2. Otherwise, if the current line is empty, set to column position 1.
2553
2554 3. Otherwise, set to the last column that displays any part of the
2555 first character in the file that is part of the text region speci‐
2556 fied by the motion command.
2557
2558 Yank Current Line
2559 Synopsis:
2560
2561
2562 [buffer][count] Y
2563
2564
2565 This command shall be equivalent to the vi command:
2566
2567
2568 [buffer][count] y_
2569
2570 Redraw Window
2571 If in open mode, the z command shall have the Synopsis:
2572
2573 Synopsis:
2574
2575
2576 [count] z
2577
2578
2579 If count is not specified, it shall default to the window edit option
2580 -1. The z command shall be equivalent to the ex z command, with a type
2581 character of = and a count of count -2, except that the current line
2582 and current column shall be set as follows, and the window edit option
2583 shall not be affected. If the calculation for the count argument would
2584 result in a negative number, the count argument to the ex z command
2585 shall be zero. A blank line shall be written after the last line is
2586 written.
2587
2588 Current line: Unchanged.
2589
2590 Current column: Unchanged.
2591
2592 If not in open mode, the z command shall have the following Synopsis:
2593
2594 Synopsis:
2595
2596
2597 [line] z [count] character
2598
2599
2600 If line is not specified, it shall default to the current line. If
2601 line is specified, but is greater than the number of lines in the edit
2602 buffer, it shall default to the number of lines in the edit buffer.
2603
2604 If count is specified, the value of the window edit option shall be set
2605 to count (as described in the ex window command), and the screen shall
2606 be redrawn.
2607
2608 line shall be placed as specified by the following characters:
2609
2610 <newline>, <carriage-return>
2611
2612 Place the beginning of the line on the first line of the dis‐
2613 play.
2614
2615 . Place the beginning of the line in the center of the display.
2616 The middle line of the display shall be calculated as described
2617 for the M command.
2618
2619 - Place an unspecified portion of the line on the last line of the
2620 display.
2621
2622 + If line was specified, equivalent to the <newline> case. If line
2623 was not specified, display a screen where the first line of the
2624 display shall be (current last line) +1. If there are no lines
2625 after the last line in the display, it shall be an error.
2626
2627 ^ If line was specified, display a screen where the last line of
2628 the display shall contain an unspecified portion of the first
2629 line of a display that had an unspecified portion of the speci‐
2630 fied line on the last line of the display. If this calculation
2631 results in a line before the beginning of the edit buffer, dis‐
2632 play the first screen of the edit buffer.
2633
2634 Otherwise, display a screen where the last line of the display shall
2635 contain an unspecified portion of (current first line -1). If this
2636 calculation results in a line before the beginning of the edit buffer,
2637 it shall be an error.
2638
2639
2640 Current line: If line and the '^' character were specified:
2641
2642 1. If the first screen was displayed as a result of the command
2643 attempting to display lines before the beginning of the edit buf‐
2644 fer: if the first screen was already displayed, unchanged; other‐
2645 wise, set to (current first line -1).
2646
2647 2. Otherwise, set to the last line of the display.
2648
2649 If line and the '+' character were specified, set to the first line of
2650 the display.
2651
2652 Otherwise, if line was specified, set to line.
2653
2654 Otherwise, unchanged.
2655
2656 Current column: Set to non- <blank>.
2657
2658 Exit
2659 Synopsis:
2660
2661
2662 ZZ
2663
2664
2665 This command shall be equivalent to the ex xit command with no
2666 addresses, trailing !, or filename (see the ex xit command).
2667
2668 Input Mode Commands in vi
2669 In text input mode, the current line shall consist of zero or more of
2670 the following categories, plus the terminating <newline>:
2671
2672 1. Characters preceding the text input entry point
2673
2674 Characters in this category shall not be modified during text input
2675 mode.
2676
2677 2. autoindent characters
2678
2679 autoindent characters shall be automatically inserted into each line
2680 that is created in text input mode, either as a result of entering a
2681 <newline> or <carriage-return> while in text input mode, or as an
2682 effect of the command itself; for example, O or o (see the ex autoin‐
2683 dent command), as if entered by the user.
2684
2685 It shall be possible to erase autoindent characters with the <con‐
2686 trol>-D command; it is unspecified whether they can be erased by <con‐
2687 trol>-H, <control>-U, and <control>-W characters. Erasing any autoin‐
2688 dent character turns the glyph into erase-columns and deletes the char‐
2689 acter from the edit buffer, but does not change its representation on
2690 the screen.
2691
2692 3. Text input characters
2693
2694 Text input characters are the characters entered by the user. Erasing
2695 any text input character turns the glyph into erase-columns and deletes
2696 the character from the edit buffer, but does not change its representa‐
2697 tion on the screen.
2698
2699 Each text input character entered by the user (that does not have a
2700 special meaning) shall be treated as follows:
2701
2702 a. The text input character shall be appended to the last char‐
2703 acter in the edit buffer from the first, second, or third
2704 categories.
2705
2706 b. If there are no erase-columns on the screen, the text input
2707 command was the R command, and characters in the fifth cate‐
2708 gory from the original line follow the cursor, the next such
2709 character shall be deleted from the edit buffer. If the
2710 slowopen edit option is not set, the corresponding glyph on
2711 the screen shall become erase-columns.
2712
2713 c. If there are erase-columns on the screen, as many columns as
2714 they occupy, or as are necessary, shall be overwritten to
2715 display the text input character. (If only part of a multi-
2716 column glyph is overwritten, the remainder shall be left on
2717 the screen, and continue to be treated as erase-columns; it
2718 is unspecified whether the remainder of the glyph is modi‐
2719 fied in any way.)
2720
2721 d. If additional display line columns are needed to display the
2722 text input character:
2723
2724 1. If the slowopen edit option is set, the text input char‐
2725 acters shall be displayed on subsequent display line
2726 columns, overwriting any characters displayed in those
2727 columns.
2728
2729 2. Otherwise, any characters currently displayed on or
2730 after the column on the display line where the text
2731 input character is to be displayed shall be pushed ahead
2732 the number of display line columns necessary to display
2733 the rest of the text input character.
2734
2735 4. Erase-columns
2736
2737 Erase-columns are not logically part of the edit buffer, appearing only
2738 on the screen, and may be overwritten on the screen by subsequent text
2739 input characters. When text input mode ends, all erase-columns shall no
2740 longer appear on the screen.
2741
2742 Erase-columns are initially the region of text specified by the c com‐
2743 mand (see Change ); however, erasing autoindent or text input charac‐
2744 ters causes the glyphs of the erased characters to be treated as erase-
2745 columns.
2746
2747 5. Characters following the text region for the c command, or the text
2748 input entry point for all other commands
2749
2750 Characters in this category shall not be modified during text input
2751 mode, except as specified in category 3.b. for the R text input com‐
2752 mand, or as <blank>s deleted when a <newline> or <carriage-return> is
2753 entered.
2754
2755 It is unspecified whether it is an error to attempt to erase past the
2756 beginning of a line that was created by the entry of a <newline> or
2757 <carriage-return> during text input mode. If it is not an error, the
2758 editor shall behave as if the erasing character was entered immediately
2759 after the last text input character entered on the previous line, and
2760 all of the non- <newline>s on the current line shall be treated as
2761 erase-columns.
2762
2763 When text input mode is entered, or after a text input mode character
2764 is entered (except as specified for the special characters below), the
2765 cursor shall be positioned as follows:
2766
2767 1. On the first column that displays any part of the first erase-col‐
2768 umn, if one exists
2769
2770 2. Otherwise, if the slowopen edit option is set, on the first display
2771 line column after the last character in the first, second, or third
2772 categories, if one exists
2773
2774 3. Otherwise, the first column that displays any part of the first
2775 character in the fifth category, if one exists
2776
2777 4. Otherwise, the display line column after the last character in the
2778 first, second, or third categories, if one exists
2779
2780 5. Otherwise, on column position 1
2781
2782 The characters that are updated on the screen during text input mode
2783 are unspecified, other than that the last text input character shall
2784 always be updated, and, if the slowopen edit option is not set, the
2785 current cursor character shall always be updated.
2786
2787 The following specifications are for command characters entered during
2788 text input mode.
2789
2790 NUL
2791 Synopsis:
2792
2793
2794 NUL
2795
2796
2797 If the first character of the text input is a NUL, the most recently
2798 input text shall be input as if entered by the user, and then text
2799 input mode shall be exited. The text shall be input literally; that is,
2800 characters are neither macro or abbreviation expanded, nor are any
2801 characters interpreted in any special manner. It is unspecified
2802 whether implementations shall support more than 256 bytes of remembered
2803 input text.
2804
2805 <control>-D
2806 Synopsis:
2807
2808
2809 <control>-D
2810
2811
2812 The <control>-D character shall have no special meaning when in text
2813 input mode for a line-oriented command (see Command Descriptions in vi
2814 ).
2815
2816 This command need not be supported on block-mode terminals.
2817
2818 If the cursor does not follow an autoindent character, or an autoindent
2819 character and a '0' or '^' character:
2820
2821 1. If the cursor is in column position 1, the <control>-D character
2822 shall be discarded and no further action taken.
2823
2824 2. Otherwise, the <control>-D character shall have no special meaning.
2825
2826 If the last input character was a '0', the cursor shall be moved to
2827 column position 1.
2828
2829 Otherwise, if the last input character was a '^', the cursor shall be
2830 moved to column position 1. In addition, the autoindent level for the
2831 next input line shall be derived from the same line from which the
2832 autoindent level for the current input line was derived.
2833
2834 Otherwise, the cursor shall be moved back to the column after the pre‐
2835 vious shiftwidth (see the ex shiftwidth command) boundary.
2836
2837 All of the glyphs on columns between the starting cursor position and
2838 (inclusively) the ending cursor position shall become erase-columns as
2839 described in Input Mode Commands in vi .
2840
2841 Current line: Unchanged.
2842
2843 Current column: Set to 1 if the <control>-D was preceded by a '^' or
2844 '0' ; otherwise, set to (column -1) -((column -2) % shiftwidth).
2845
2846 <control>-H
2847 Synopsis:
2848
2849
2850 <control>-H
2851
2852
2853 If in text input mode for a line-oriented command, and there are no
2854 characters to erase, text input mode shall be terminated, no further
2855 action shall be done for this command, and the current line and column
2856 shall be unchanged.
2857
2858 If there are characters other than autoindent characters that have been
2859 input on the current line before the cursor, the cursor shall move back
2860 one character.
2861
2862 Otherwise, if there are autoindent characters on the current line
2863 before the cursor, it is implementation-defined whether the <control>-H
2864 command is an error or if the cursor moves back one autoindent charac‐
2865 ter.
2866
2867 Otherwise, if the cursor is in column position 1 and there are previous
2868 lines that have been input, it is implementation-defined whether the
2869 <control>-H command is an error or if it is equivalent to entering
2870 <control>-H after the last input character on the previous input line.
2871
2872 Otherwise, it shall be an error.
2873
2874 All of the glyphs on columns between the starting cursor position and
2875 (inclusively) the ending cursor position shall become erase-columns as
2876 described in Input Mode Commands in vi .
2877
2878 The current erase character (see stty) shall cause an equivalent action
2879 to the <control>-H command, unless the previously inserted character
2880 was a backslash, in which case it shall be as if the literal current
2881 erase character had been inserted instead of the backslash.
2882
2883 Current line: Unchanged, unless previously input lines are erased, in
2884 which case it shall be set to line -1.
2885
2886 Current column: Set to the first column that displays any portion of
2887 the character backed up over.
2888
2889 <newline>
2890 Synopsis:
2891
2892
2893 <newline>
2894
2895
2896 <carriage-return>
2897
2898
2899 <control>-J
2900
2901
2902 <control>-M
2903
2904
2905 If input was part of a line-oriented command, text input mode shall be
2906 terminated and the command shall continue execution with the input pro‐
2907 vided.
2908
2909 Otherwise, terminate the current line. If there are no characters other
2910 than autoindent characters on the line, all characters on the line
2911 shall be discarded. Otherwise, it is unspecified whether the autoindent
2912 characters in the line are modified by entering these characters.
2913
2914 Continue text input mode on a new line appended after the current line.
2915 If the slowopen edit option is set, the lines on the screen below the
2916 current line shall not be pushed down, but the first of them shall be
2917 cleared and shall appear to be overwritten. Otherwise, the lines of the
2918 screen below the current line shall be pushed down.
2919
2920 If the autoindent edit option is set, an appropriate number of autoin‐
2921 dent characters shall be added as a prefix to the line as described by
2922 the ex autoindent edit option.
2923
2924 All columns after the cursor that are erase-columns (as described in
2925 Input Mode Commands in vi ) shall be discarded.
2926
2927 If the autoindent edit option is set, all <blank>s immediately follow‐
2928 ing the cursor shall be discarded.
2929
2930 All remaining characters after the cursor shall be transferred to the
2931 new line, positioned after any autoindent characters.
2932
2933 Current line: Set to current line +1.
2934
2935 Current column: Set to the first column that displays any portion of
2936 the first character after the autoindent characters on the new line, if
2937 any, or the first column position after the last autoindent character,
2938 if any, or column position 1.
2939
2940 <control>-T
2941 Synopsis:
2942
2943
2944 <control>-T
2945
2946
2947 The <control>-T character shall have no special meaning when in text
2948 input mode for a line-oriented command (see Command Descriptions in vi
2949 ).
2950
2951 This command need not be supported on block-mode terminals.
2952
2953 Behave as if the user entered the minimum number of <blank>s necessary
2954 to move the cursor forward to the column position after the next
2955 shiftwidth (see the ex shiftwidth command) boundary.
2956
2957 Current line: Unchanged.
2958
2959 Current column: Set to column + shiftwidth - ((column -1) %
2960 shiftwidth).
2961
2962 <control>-U
2963 Synopsis:
2964
2965
2966 <control>-U
2967
2968
2969 If there are characters other than autoindent characters that have been
2970 input on the current line before the cursor, the cursor shall move to
2971 the first character input after the autoindent characters.
2972
2973 Otherwise, if there are autoindent characters on the current line
2974 before the cursor, it is implementation-defined whether the <control>-U
2975 command is an error or if the cursor moves to the first column position
2976 on the line.
2977
2978 Otherwise, if the cursor is in column position 1 and there are previous
2979 lines that have been input, it is implementation-defined whether the
2980 <control>-U command is an error or if it is equivalent to entering
2981 <control>-U after the last input character on the previous input line.
2982
2983 Otherwise, it shall be an error.
2984
2985 All of the glyphs on columns between the starting cursor position and
2986 (inclusively) the ending cursor position shall become erase-columns as
2987 described in Input Mode Commands in vi .
2988
2989 The current kill character (see stty) shall cause an equivalent action
2990 to the <control>-U command, unless the previously inserted character
2991 was a backslash, in which case it shall be as if the literal current
2992 kill character had been inserted instead of the backslash.
2993
2994 Current line: Unchanged, unless previously input lines are erased, in
2995 which case it shall be set to line -1.
2996
2997 Current column: Set to the first column that displays any portion of
2998 the last character backed up over.
2999
3000 <control>-V
3001 Synopsis:
3002
3003
3004 <control>-V
3005
3006
3007 <control>-Q
3008
3009
3010 Allow the entry of any subsequent character, other than <control>-J or
3011 the <newline>, as a literal character, removing any special meaning
3012 that it may have to the editor in text input mode. If a <control>-V or
3013 <control>-Q is entered before a <control>-J or <newline>, the <con‐
3014 trol>-V or <control>-Q character shall be discarded, and the <con‐
3015 trol>-J or <newline> shall behave as described in the <newline> command
3016 character during input mode.
3017
3018 For purposes of the display only, the editor shall behave as if a '^'
3019 character was entered, and the cursor shall be positioned as if over‐
3020 writing the '^' character. When a subsequent character is entered, the
3021 editor shall behave as if that character was entered instead of the
3022 original <control>-V or <control>-Q character.
3023
3024 Current line: Unchanged.
3025
3026 Current column: Unchanged.
3027
3028 <control>-W
3029 Synopsis:
3030
3031
3032 <control>-W
3033
3034
3035 If there are characters other than autoindent characters that have been
3036 input on the current line before the cursor, the cursor shall move back
3037 over the last word preceding the cursor (including any <blank>s between
3038 the end of the last word and the current cursor); the cursor shall not
3039 move to before the first character after the end of any autoindent
3040 characters.
3041
3042 Otherwise, if there are autoindent characters on the current line
3043 before the cursor, it is implementation-defined whether the <control>-W
3044 command is an error or if the cursor moves to the first column position
3045 on the line.
3046
3047 Otherwise, if the cursor is in column position 1 and there are previous
3048 lines that have been input, it is implementation-defined whether the
3049 <control>-W command is an error or if it is equivalent to entering
3050 <control>-W after the last input character on the previous input line.
3051
3052 Otherwise, it shall be an error.
3053
3054 All of the glyphs on columns between the starting cursor position and
3055 (inclusively) the ending cursor position shall become erase-columns as
3056 described in Input Mode Commands in vi .
3057
3058 Current line: Unchanged, unless previously input lines are erased, in
3059 which case it shall be set to line -1.
3060
3061 Current column: Set to the first column that displays any portion of
3062 the last character backed up over.
3063
3064 <ESC>
3065 Synopsis:
3066
3067
3068 <ESC>
3069
3070
3071 If input was part of a line-oriented command:
3072
3073 1. If interrupt was entered, text input mode shall be terminated and
3074 the editor shall return to command mode. The terminal shall be
3075 alerted.
3076
3077 2. If <ESC> was entered, text input mode shall be terminated and the
3078 command shall continue execution with the input provided.
3079
3080 Otherwise, terminate text input mode and return to command mode.
3081
3082 Any autoindent characters entered on newly created lines that have no
3083 other non- <newline>s shall be deleted.
3084
3085 Any leading autoindent and <blank>s on newly created lines shall be
3086 rewritten to be the minimum number of <blank>s possible.
3087
3088 The screen shall be redisplayed as necessary to match the contents of
3089 the edit buffer.
3090
3091 Current line: Unchanged.
3092
3093 Current column:
3094
3095 1. If there are text input characters on the current line, the column
3096 shall be set to the last column where any portion of the last text
3097 input character is displayed.
3098
3099 2. Otherwise, if a character is displayed in the current column,
3100 unchanged.
3101
3102 3. Otherwise, set to column position 1.
3103
3105 The following exit values shall be returned:
3106
3107 0 Successful completion.
3108
3109 >0 An error occurred.
3110
3111
3113 When any error is encountered and the standard input is not a terminal
3114 device file, vi shall not write the file or return to command or text
3115 input mode, and shall terminate with a non-zero exit status.
3116
3117 Otherwise, when an unrecoverable error is encountered it shall be
3118 equivalent to a SIGHUP asynchronous event.
3119
3120 Otherwise, when an error is encountered, the editor shall behave as
3121 specified in Command Descriptions in vi .
3122
3123 The following sections are informative.
3124
3126 None.
3127
3129 None.
3130
3132 See the RATIONALE for ex for more information on vi. Major portions of
3133 the vi utility specification point to ex to avoid inadvertent diver‐
3134 gence. While ex and vi have historically been implemented as a single
3135 utility, this is not required by IEEE Std 1003.1-2001.
3136
3137 It is recognized that portions of vi would be difficult, if not impos‐
3138 sible, to implement satisfactorily on a block-mode terminal, or a ter‐
3139 minal without any form of cursor addressing, thus it is not a mandatory
3140 requirement that such features should work on all terminals. It is the
3141 intention, however, that a vi implementation should provide the full
3142 set of capabilities on all terminals capable of supporting them.
3143
3144 Historically, vi exited immediately if the standard input was not a
3145 terminal. IEEE Std 1003.1-2001 permits, but does not require, this
3146 behavior. An end-of-file condition is not equivalent to an end-of-file
3147 character. A common end-of-file character, <control>-D, is historically
3148 a vi command.
3149
3150 The text in the STDOUT section reflects the usage of the verb display
3151 in this section; some implementations of vi use standard output to
3152 write to the terminal, but IEEE Std 1003.1-2001 does not require that
3153 to be the case.
3154
3155 Historically, implementations reverted to open mode if the terminal was
3156 incapable of supporting full visual mode. IEEE Std 1003.1-2001
3157 requires this behavior. Historically, the open mode of vi behaved
3158 roughly equivalently to the visual mode, with the exception that only a
3159 single line from the edit buffer (one "buffer line") was kept current
3160 at any time. This line was normally displayed on the next-to-last line
3161 of a terminal with cursor addressing (and the last line performed its
3162 normal visual functions for line-oriented commands and messages). In
3163 addition, some few commands behaved differently in open mode than in
3164 visual mode. IEEE Std 1003.1-2001 requires conformance to historical
3165 practice.
3166
3167 Historically, ex and vi implementations have expected text to proceed
3168 in the usual European/Latin order of left to right, top to bottom.
3169 There is no requirement in IEEE Std 1003.1-2001 that this be the case.
3170 The specification was deliberately written using words like "before",
3171 "after", "first", and "last" in order to permit implementations to sup‐
3172 port the natural text order of the language.
3173
3174 Historically, lines past the end of the edit buffer were marked with
3175 single tilde ( '~' ) characters; that is, if the one-based display was
3176 20 lines in length, and the last line of the file was on line one, then
3177 lines 2-20 would contain only a single '~' character.
3178
3179 Historically, the vi editor attempted to display only complete lines at
3180 the bottom of the screen (it did display partial lines at the top of
3181 the screen). If a line was too long to fit in its entirety at the bot‐
3182 tom of the screen, the screen lines where the line would have been dis‐
3183 played were displayed as single '@' characters, instead of displaying
3184 part of the line. IEEE Std 1003.1-2001 permits, but does not require,
3185 this behavior. Implementations are encouraged to attempt always to
3186 display a complete line at the bottom of the screen when doing
3187 scrolling or screen positioning by buffer lines.
3188
3189 Historically, lines marked with '@' were also used to minimize output
3190 to dumb terminals over slow lines; that is, changes local to the cursor
3191 were updated, but changes to lines on the screen that were not close to
3192 the cursor were simply marked with an '@' sign instead of being updated
3193 to match the current text. IEEE Std 1003.1-2001 permits, but does not
3194 require this feature because it is used ever less frequently as termi‐
3195 nals become smarter and connections are faster.
3196
3197 Initialization in ex and vi
3198 Historically, vi always had a line in the edit buffer, even if the edit
3199 buffer was "empty". For example:
3200
3201 1. The ex command = executed from visual mode wrote "1" when the buf‐
3202 fer was empty.
3203
3204 2. Writes from visual mode of an empty edit buffer wrote files of a
3205 single character (a <newline>), while writes from ex mode of an
3206 empty edit buffer wrote empty files.
3207
3208 3. Put and read commands into an empty edit buffer left an empty line
3209 at the top of the edit buffer.
3210
3211 For consistency, IEEE Std 1003.1-2001 does not permit any of these
3212 behaviors.
3213
3214 Historically, vi did not always return the terminal to its original
3215 modes; for example, ICRNL was modified if it was not originally set.
3216 IEEE Std 1003.1-2001 does not permit this behavior.
3217
3218 Command Descriptions in vi
3219 Motion commands are among the most complicated aspects of vi to
3220 describe. With some exceptions, the text region and buffer type effect
3221 of a motion command on a vi command are described on a case-by-case
3222 basis. The descriptions of text regions in IEEE Std 1003.1-2001 are not
3223 intended to imply direction; that is, an inclusive region from line n
3224 to line n+5 is identical to a region from line n+5 to line n. This is
3225 of more than academic interest-movements to marks can be in either
3226 direction, and, if the wrapscan option is set, so can movements to
3227 search points. Historically, lines are always stored into buffers in
3228 text order; that is, from the start of the edit buffer to the end.
3229 IEEE Std 1003.1-2001 requires conformance to historical practice.
3230
3231 Historically, command counts were applied to any associated motion, and
3232 were multiplicative to any supplied motion count. For example, 2cw is
3233 the same as c2w, and 2c3w is the same as c6w. IEEE Std 1003.1-2001
3234 requires this behavior. Historically, vi commands that used bigwords,
3235 words, paragraphs, and sentences as objects treated groups of empty
3236 lines, or lines that contained only <blank>s, inconsistently. Some
3237 commands treated them as a single entity, while others treated each
3238 line separately. For example, the w, W, and B commands treated groups
3239 of empty lines as individual words; that is, the command would move the
3240 cursor to each new empty line. The e and E commands treated groups of
3241 empty lines as a single word; that is, the first use would move past
3242 the group of lines. The b command would just beep at the user, or if
3243 done from the start of the line as a motion command, fail in unexpected
3244 ways. If the lines contained only (or ended with) <blank>s, the w and W
3245 commands would just beep at the user, the E and e commands would treat
3246 the group as a single word, and the B and b commands would treat the
3247 lines as individual words. For consistency and simplicity of specifica‐
3248 tion, IEEE Std 1003.1-2001 requires that all vi commands treat groups
3249 of empty or blank lines as a single entity, and that movement through
3250 lines ending with <blank>s be consistent with other movements.
3251
3252 Historically, vi documentation indicated that any number of double
3253 quotes were skipped after punctuation marks at sentence boundaries;
3254 however, implementations only skipped single quotes.
3255 IEEE Std 1003.1-2001 requires both to be skipped.
3256
3257 Historically, the first and last characters in the edit buffer were
3258 word boundaries. This historical practice is required by
3259 IEEE Std 1003.1-2001.
3260
3261 Historically, vi attempted to update the minimum number of columns on
3262 the screen possible, which could lead to misleading information being
3263 displayed. IEEE Std 1003.1-2001 makes no requirements other than that
3264 the current character being entered is displayed correctly, leaving all
3265 other decisions in this area up to the implementation.
3266
3267 Historically, lines were arbitrarily folded between columns of any
3268 characters that required multiple column positions on the screen, with
3269 the exception of tabs, which terminated at the right-hand margin.
3270 IEEE Std 1003.1-2001 permits the former and requires the latter. Imple‐
3271 mentations that do not arbitrarily break lines between columns of char‐
3272 acters that occupy multiple column positions should not permit the cur‐
3273 sor to rest on a column that does not contain any part of a character.
3274
3275 The historical vi had a problem in that all movements were by buffer
3276 lines, not by display or screen lines. This is often the right thing to
3277 do; for example, single line movements, such as j or k, should work on
3278 buffer lines. Commands like dj, or j., where . is a change command,
3279 only make sense for buffer lines. It is not, however, the right thing
3280 to do for screen motion or scrolling commands like <control>-D, <con‐
3281 trol>-F, and H. If the window is fairly small, using buffer lines in
3282 these cases can result in completely random motion; for example, 1
3283 <control>-D can result in a completely changed screen, without any
3284 overlap. This is clearly not what the user wanted. The problem is even
3285 worse in the case of the H, L, and M commands-as they position the cur‐
3286 sor at the first non- <blank> of the line, they may all refer to the
3287 same location in large lines, and will result in no movement at all.
3288
3289 In addition, if the line is larger than the screen, using buffer lines
3290 can make it impossible to display parts of the line-there are not any
3291 commands that do not display the beginning of the line in historical
3292 vi, and if both the beginning and end of the line cannot be on the
3293 screen at the same time, the user suffers. Finally, the page and half-
3294 page scrolling commands historically moved to the first non- <blank> in
3295 the new line. If the line is approximately the same size as the screen,
3296 this is inadequate because the cursor before and after a <control>-D
3297 command will refer to the same location on the screen.
3298
3299 Implementations of ex and vi exist that do not have these problems
3300 because the relevant commands ( <control>-B, <control>-D, <control>-F,
3301 <control>-U, <control>-Y, <control>-E, H, L, and M) operate on display
3302 (screen) lines, not (edit) buffer lines.
3303
3304 IEEE Std 1003.1-2001 does not permit this behavior by default because
3305 the standard developers believed that users would find it too confus‐
3306 ing. However, historical practice has been relaxed. For example, ex and
3307 vi historically attempted, albeit sometimes unsuccessfully, to never
3308 put part of a line on the last lines of a screen; for example, if a
3309 line would not fit in its entirety, no part of the line was displayed,
3310 and the screen lines corresponding to the line contained single '@'
3311 characters. This behavior is permitted, but not required by
3312 IEEE Std 1003.1-2001, so that it is possible for implementations to
3313 support long lines in small screens more reasonably without changing
3314 the commands to be oriented to the display (instead of oriented to the
3315 buffer). IEEE Std 1003.1-2001 also permits implementations to refuse
3316 to edit any edit buffer containing a line that will not fit on the
3317 screen in its entirety.
3318
3319 The display area (for example, the value of the window edit option) has
3320 historically been "grown", or expanded, to display new text when local
3321 movements are done in displays where the number of lines displayed is
3322 less than the maximum possible. Expansion has historically been the
3323 first choice, when the target line is less than the maximum possible
3324 expansion value away. Scrolling has historically been the next choice,
3325 done when the target line is less than half a display away, and other‐
3326 wise, the screen was redrawn. There were exceptions, however, in that
3327 ex commands generally always caused the screen to be redrawn.
3328 IEEE Std 1003.1-2001 does not specify a standard behavior because there
3329 may be external issues, such as connection speed, the number of charac‐
3330 ters necessary to redraw as opposed to scroll, or terminal capabilities
3331 that implementations will have to accommodate.
3332
3333 The current line in IEEE Std 1003.1-2001 maps one-to-one to a buffer
3334 line in the file. The current column does not. There are two different
3335 column values that are described by IEEE Std 1003.1-2001. The first is
3336 the current column value as set by many of the vi commands. This value
3337 is remembered for the lifetime of the editor. The second column value
3338 is the actual position on the screen where the cursor rests. The two
3339 are not always the same. For example, when the cursor is backed by a
3340 multi-column character, the actual cursor position on the screen has
3341 historically been the last column of the character in command mode, and
3342 the first column of the character in input mode.
3343
3344 Commands that set the current line, but that do not set the current
3345 cursor value (for example, j and k) attempt to get as close as possible
3346 to the remembered column position, so that the cursor tends to restrict
3347 itself to a vertical column as the user moves around in the edit buf‐
3348 fer. IEEE Std 1003.1-2001 requires conformance to historical practice,
3349 requiring that the display location of the cursor on the display line
3350 be adjusted from the current column value as necessary to support this
3351 historical behavior.
3352
3353 Historically, only a single line (and for some terminals, a single line
3354 minus 1 column) of characters could be entered by the user for the
3355 line-oriented commands; that is, :, !, /, or ?. IEEE Std 1003.1-2001
3356 permits, but does not require, this limitation.
3357
3358 Historically, "soft" errors in vi caused the terminal to be alerted,
3359 but no error message was displayed. As a general rule, no error message
3360 was displayed for errors in command execution in vi, when the error
3361 resulted from the user attempting an invalid or impossible action, or
3362 when a searched-for object was not found. Examples of soft errors
3363 included h at the left margin, <control>-B or [[ at the beginning of
3364 the file, 2G at the end of the file, and so on. In addition, errors
3365 such as %, ]], }, ), N, n, f, F, t, and T failing to find the searched-
3366 for object were soft as well. Less consistently, / and ? displayed an
3367 error message if the pattern was not found, /, ?, N, and n displayed an
3368 error message if no previous regular expression had been specified, and
3369 ; did not display an error message if no previous f, F, t, or T command
3370 had occurred. Also, behavior in this area might reasonably be based on
3371 a runtime evaluation of the speed of a network connection. Finally,
3372 some implementations have provided error messages for soft errors in
3373 order to assist naive users, based on the value of a verbose edit
3374 option. IEEE Std 1003.1-2001 does not list specific errors for which an
3375 error message shall be displayed. Implementations should conform to
3376 historical practice in the absence of any strong reason to diverge.
3377
3378 Page Backwards
3379 The <control>-B and <control>-F commands historically considered it an
3380 error to attempt to page past the beginning or end of the file, whereas
3381 the <control>-D and <control>-U commands simply moved to the beginning
3382 or end of the file. For consistency, IEEE Std 1003.1-2001 requires the
3383 latter behavior for all four commands. All four commands still consider
3384 it an error if the current line is at the beginning ( <control>-B,
3385 <control>-U) or end ( <control>-F, <control>-D) of the file. Histori‐
3386 cally, the <control>-B and <control>-F commands skip two lines in order
3387 to include overlapping lines when a single command is entered. This
3388 makes less sense in the presence of a count, as there will be, by defi‐
3389 nition, no overlapping lines. The actual calculation used by historical
3390 implementations of the vi editor for <control>-B was:
3391
3392
3393 ((current first line) - count x (window edit option)) +2
3394
3395 and for <control>-F was:
3396
3397
3398 ((current first line) + count x (window edit option)) -2
3399
3400 This calculation does not work well when intermixing commands with and
3401 without counts; for example, 3 <control>-F is not equivalent to enter‐
3402 ing the <control>-F command three times, and is not reversible by
3403 entering the <control>-B command three times. For consistency with
3404 other vi commands that take counts, IEEE Std 1003.1-2001 requires a
3405 different calculation.
3406
3407 Scroll Forward
3408 The 4BSD and System V implementations of vi differed on the initial
3409 value used by the scroll command. 4BSD used:
3410
3411
3412 ((window edit option) +1) /2
3413
3414 while System V used the value of the scroll edit option. The System V
3415 version is specified by IEEE Std 1003.1-2001 because the standard
3416 developers believed that it was more intuitive and permitted the user a
3417 method of setting the scroll value initially without also setting the
3418 number of lines that are displayed.
3419
3420 Scroll Forward by Line
3421 Historically, the <control>-E and <control>-Y commands considered it an
3422 error if the last and first lines, respectively, were already on the
3423 screen. IEEE Std 1003.1-2001 requires conformance to historical prac‐
3424 tice. Historically, the <control>-E and <control>-Y commands had no
3425 effect in open mode. For simplicity and consistency of specification,
3426 IEEE Std 1003.1-2001 requires that they behave as usual, albeit with a
3427 single line screen.
3428
3429 Clear and Redisplay
3430 The historical <control>-L command refreshed the screen exactly as it
3431 was supposed to be currently displayed, replacing any '@' characters
3432 for lines that had been deleted but not updated on the screen with
3433 refreshed '@' characters. The intent of the <control>-L command is to
3434 refresh when the screen has been accidentally overwritten; for example,
3435 by a write command from another user, or modem noise.
3436
3437 Redraw Screen
3438 The historical <control>-R command redisplayed only when necessary to
3439 update lines that had been deleted but not updated on the screen and
3440 that were flagged with '@' characters. There is no requirement that the
3441 screen be in any way refreshed if no lines of this form are currently
3442 displayed. IEEE Std 1003.1-2001 permits implementations to extend this
3443 command to refresh lines on the screen flagged with '@' characters
3444 because they are too long to be displayed in the current framework;
3445 however, the current line and column need not be modified.
3446
3447 Search for tagstring
3448 Historically, the first non- <blank> at or after the cursor was the
3449 first character, and all subsequent characters that were word charac‐
3450 ters, up to the end of the line, were included. For example, with the
3451 cursor on the leading space or on the '#' character in the text
3452 "#bar@", the tag was "#bar" . On the character 'b' it was "bar", and on
3453 the 'a' it was "ar" . IEEE Std 1003.1-2001 requires this behavior.
3454
3455 Replace Text with Results from Shell Command
3456 Historically, the <, >, and ! commands considered most cursor motions
3457 other than line-oriented motions an error; for example, the command
3458 >/foo<CR> succeeded, while the command >l failed, even though the text
3459 region described by the two commands might be identical. For consis‐
3460 tency, all three commands only consider entire lines and not partial
3461 lines, and the region is defined as any line that contains a character
3462 that was specified by the motion.
3463
3464 Move to Matching Character
3465 Other matching characters have been left implementation-defined in
3466 order to allow extensions such as matching '<' and '>' for searching
3467 HTML, or #ifdef, #else, and #endif for searching C source.
3468
3469 Repeat Substitution
3470 IEEE Std 1003.1-2001 requires that any c and g flags specified to the
3471 previous substitute command be ignored; however, the r flag may still
3472 apply, if supported by the implementation.
3473
3474 Return to Previous (Context or Section)
3475 The [[, ]], (, ), {, and } commands are all affected by "section bound‐
3476 aries", but in some historical implementations not all of the commands
3477 recognize the same section boundaries. This is a bug, not a feature,
3478 and a unique section-boundary algorithm was not described for each com‐
3479 mand. One special case that is preserved is that the sentence command
3480 moves to the end of the last line of the edit buffer while the other
3481 commands go to the beginning, in order to preserve the traditional
3482 character cut semantics of the sentence command. Historically, vi sec‐
3483 tion boundaries at the beginning and end of the edit buffer were the
3484 first non- <blank> on the first and last lines of the edit buffer if
3485 one exists; otherwise, the last character of the first and last lines
3486 of the edit buffer if one exists. To increase consistency with other
3487 section locations, this has been simplified by IEEE Std 1003.1-2001 to
3488 the first character of the first and last lines of the edit buffer, or
3489 the first and the last lines of the edit buffer if they are empty.
3490
3491 Sentence boundaries were problematic in the historical vi. They were
3492 not only the boundaries as defined for the section and paragraph com‐
3493 mands, but they were the first non- <blank> that occurred after those
3494 boundaries, as well. Historically, the vi section commands were docu‐
3495 mented as taking an optional window size as a count preceding the com‐
3496 mand. This was not implemented in historical versions, so
3497 IEEE Std 1003.1-2001 requires that the count repeat the command, for
3498 consistency with other vi commands.
3499
3500 Repeat
3501 Historically, mapped commands other than text input commands could not
3502 be repeated using the period command. IEEE Std 1003.1-2001 requires
3503 conformance to historical practice.
3504
3505 The restrictions on the interpretation of special characters (for exam‐
3506 ple, <control>-H) in the repetition of text input mode commands is
3507 intended to match historical practice. For example, given the input
3508 sequence:
3509
3510
3511 iab<control>-H<control>-H<control>-Hdef<escape>
3512
3513 the user should be informed of an error when the sequence is first
3514 entered, but not during a command repetition. The character <control>-T
3515 is specifically exempted from this restriction. Historical implementa‐
3516 tions of vi ignored <control>-T characters that were input in the orig‐
3517 inal command during command repetition. IEEE Std 1003.1-2001 prohibits
3518 this behavior.
3519
3520 Find Regular Expression
3521 Historically, commands did not affect the line searched to or from if
3522 the motion command was a search ( /, ?, N, n) and the final position
3523 was the start/end of the line. There were some special cases and vi was
3524 not consistent. IEEE Std 1003.1-2001 does not permit this behavior, for
3525 consistency. Historical implementations permitted but were unable to
3526 handle searches as motion commands that wrapped (that is, due to the
3527 edit option wrapscan) to the original location. IEEE Std 1003.1-2001
3528 requires that this behavior be treated as an error.
3529
3530 Historically, the syntax "/RE/0" was used to force the command to cut
3531 text in line mode. IEEE Std 1003.1-2001 requires conformance to histor‐
3532 ical practice.
3533
3534 Historically, in open mode, a z specified to a search command redis‐
3535 played the current line instead of displaying the current screen with
3536 the current line highlighted. For consistency and simplicity of speci‐
3537 fication, IEEE Std 1003.1-2001 does not permit this behavior.
3538
3539 Historically, trailing z commands were permitted and ignored if entered
3540 as part of a search used as a motion command. For consistency and sim‐
3541 plicity of specification, IEEE Std 1003.1-2001 does not permit this
3542 behavior.
3543
3544 Execute an ex Command
3545 Historically, vi implementations restricted the commands that could be
3546 entered on the colon command line (for example, append and change), and
3547 some other commands were known to cause them to fail catastrophically.
3548 For consistency, IEEE Std 1003.1-2001 does not permit these restric‐
3549 tions. When executing an ex command by entering :, it is not possible
3550 to enter a <newline> as part of the command because it is considered
3551 the end of the command. A different approach is to enter ex command
3552 mode by using the vi Q command (and later resuming visual mode with the
3553 ex vi command). In ex command mode, the single-line limitation does not
3554 exist. So, for example, the following is valid:
3555
3556
3557 Q
3558 s/break here/break\
3559 here/
3560 vi
3561
3562 IEEE Std 1003.1-2001 requires that, if the ex command overwrites any
3563 part of the screen that would be erased by a refresh, vi pauses for a
3564 character from the user. Historically, this character could be any
3565 character; for example, a character input by the user before the mes‐
3566 sage appeared, or even a mapped character. This is probably a bug, but
3567 implementations that have tried to be more rigorous by requiring that
3568 the user enter a specific character, or that the user enter a character
3569 after the message was displayed, have been forced by user indignation
3570 back into historical behavior. IEEE Std 1003.1-2001 requires confor‐
3571 mance to historical practice.
3572
3573 Shift Left (Right)
3574 Refer to the Rationale for the ! and / commands. Historically, the <
3575 and > commands sometimes moved the cursor to the first non- <blank>
3576 (for example if the command was repeated or with _ as the motion com‐
3577 mand), and sometimes left it unchanged. IEEE Std 1003.1-2001 does not
3578 permit this inconsistency, requiring instead that the cursor always
3579 move to the first non- <blank>. Historically, the < and > commands did
3580 not support buffer arguments, although some implementations allow the
3581 specification of an optional buffer. This behavior is neither required
3582 nor disallowed by IEEE Std 1003.1-2001.
3583
3584 Execute
3585 Historically, buffers could execute other buffers, and loops, infinite
3586 and otherwise, were possible. IEEE Std 1003.1-2001 requires confor‐
3587 mance to historical practice. The * buffer syntax of ex is not
3588 required in vi, because it is not historical practice and has been used
3589 in some vi implementations to support additional scripting languages.
3590
3591 Reverse Case
3592 Historically, the ~ command ignored any associated count, and acted
3593 only on the characters in the current line. For consistency with other
3594 vi commands, IEEE Std 1003.1-2001 requires that an associated count act
3595 on the next count characters, and that the command move to subsequent
3596 lines if warranted by count, to make it possible to modify large pieces
3597 of text in a reasonably efficient manner. There exist vi implementa‐
3598 tions that optionally require an associated motion command for the ~
3599 command. Implementations supporting this functionality are encouraged
3600 to base it on the tildedop edit option and handle the text regions and
3601 cursor positioning identically to the yank command.
3602
3603 Append
3604 Historically, counts specified to the A, a, I, and i commands repeated
3605 the input of the first line count times, and did not repeat the subse‐
3606 quent lines of the input text. IEEE Std 1003.1-2001 requires that the
3607 entire text input be repeated count times.
3608
3609 Move Backward to Preceding Word
3610 Historically, vi became confused if word commands were used as motion
3611 commands in empty files. IEEE Std 1003.1-2001 requires that this be an
3612 error. Historical implementations of vi had a large number of bugs in
3613 the word movement commands, and they varied greatly in behavior in the
3614 presence of empty lines, "words" made up of a single character, and
3615 lines containing only <blank>s. For consistency and simplicity of spec‐
3616 ification, IEEE Std 1003.1-2001 does not permit this behavior.
3617
3618 Change to End-of-Line
3619 Some historical implementations of the C command did not behave as
3620 described by IEEE Std 1003.1-2001 when the $ key was remapped because
3621 they were implemented by pushing the $ key onto the input queue and
3622 reprocessing it. IEEE Std 1003.1-2001 does not permit this behavior.
3623 Historically, the C, S, and s commands did not copy replaced text into
3624 the numeric buffers. For consistency and simplicity of specification,
3625 IEEE Std 1003.1-2001 requires that they behave like their respective c
3626 commands in all respects.
3627
3628 Delete
3629 Historically, lines in open mode that were deleted were scrolled up,
3630 and an @ glyph written over the beginning of the line. In the case of
3631 terminals that are incapable of the necessary cursor motions, the edi‐
3632 tor erased the deleted line from the screen. IEEE Std 1003.1-2001
3633 requires conformance to historical practice; that is, if the terminal
3634 cannot display the '@' character, the line cannot remain on the screen.
3635
3636 Delete to End-of-Line
3637 Some historical implementations of the D command did not behave as
3638 described by IEEE Std 1003.1-2001 when the $ key was remapped because
3639 they were implemented by pushing the $ key onto the input queue and
3640 reprocessing it. IEEE Std 1003.1-2001 does not permit this behavior.
3641
3642 Join
3643 An historical oddity of vi is that the commands J, 1J, and 2J are all
3644 equivalent. IEEE Std 1003.1-2001 requires conformance to historical
3645 practice. The vi J command is specified in terms of the ex join com‐
3646 mand with an ex command count value. The address correction for a count
3647 that is past the end of the edit buffer is necessary for historical
3648 compatibility for both ex and vi.
3649
3650 Mark Position
3651 Historical practice is that only lowercase letters, plus '`' and '",
3652 could be used to mark a cursor position. IEEE Std 1003.1-2001 requires
3653 conformance to historical practice, but encourages implementations to
3654 support other characters as marks as well.
3655
3656 Repeat Regular Expression Find (Forward and Reverse)
3657 Historically, the N and n commands could not be used as motion compo‐
3658 nents for the c command. With the exception of the cN command, which
3659 worked if the search crossed a line boundary, the text region would be
3660 discarded, and the user would not be in text input mode. For consis‐
3661 tency and simplicity of specification, IEEE Std 1003.1-2001 does not
3662 permit this behavior.
3663
3664 Insert Empty Line (Below and Above)
3665 Historically, counts to the O and o commands were used as the number of
3666 physical lines to open, if the terminal was dumb and the slowopen
3667 option was not set. This was intended to minimize traffic over slow
3668 connections and repainting for dumb terminals. IEEE Std 1003.1-2001
3669 does not permit this behavior, requiring that a count to the open com‐
3670 mand behave as for other text input commands. This change to historical
3671 practice was made for consistency, and because a superset of the func‐
3672 tionality is provided by the slowopen edit option.
3673
3674 Put from Buffer (Following and Before)
3675 Historically, counts to the p and P commands were ignored if the buffer
3676 was a line mode buffer, but were (mostly) implemented as described in
3677 IEEE Std 1003.1-2001 if the buffer was a character mode buffer. Because
3678 implementations exist that do not have this limitation, and because
3679 pasting lines multiple times is generally useful, IEEE Std 1003.1-2001
3680 requires that count be supported for all p and P commands.
3681
3682 Historical implementations of vi were widely known to have major prob‐
3683 lems in the p and P commands, particularly when unusual regions of text
3684 were copied into the edit buffer. The standard developers viewed these
3685 as bugs, and they are not permitted for consistency and simplicity of
3686 specification.
3687
3688 Historically, a P or p command (or an ex put command executed from open
3689 or visual mode) executed in an empty file, left an empty line as the
3690 first line of the file. For consistency and simplicity of specifica‐
3691 tion, IEEE Std 1003.1-2001 does not permit this behavior.
3692
3693 Replace Character
3694 Historically, the r command did not correctly handle the erase and word
3695 erase characters as arguments, nor did it handle an associated count
3696 greater than 1 with a <carriage-return> argument, for which it replaced
3697 count characters with a single <newline>. IEEE Std 1003.1-2001 does not
3698 permit these inconsistencies.
3699
3700 Historically, the r command permitted the <control>-V escaping of
3701 entered characters, such as <ESC> and the <carriage-return>; however,
3702 it required two leading <control>-V characters instead of one.
3703 IEEE Std 1003.1-2001 requires that this be changed for consistency with
3704 the other text input commands of vi.
3705
3706 Historically, it is an error to enter the r command if there are less
3707 than count characters at or after the cursor in the line. While a rea‐
3708 sonable and unambiguous extension would be to permit the r command on
3709 empty lines, it would require that too large a count be adjusted to
3710 match the number of characters at or after the cursor for consistency,
3711 which is sufficiently different from historical practice to be avoided.
3712 IEEE Std 1003.1-2001 requires conformance to historical practice.
3713
3714 Replace Characters
3715 Historically, if there were autoindent characters in the line on which
3716 the R command was run, and autoindent was set, the first <newline>
3717 would be properly indented and no characters would be replaced by the
3718 <newline>. Each additional <newline> would replace n characters, where
3719 n was the number of characters that were needed to indent the rest of
3720 the line to the proper indentation level. This behavior is a bug and is
3721 not permitted by IEEE Std 1003.1-2001.
3722
3723 Undo
3724 Historical practice for cursor positioning after undoing commands was
3725 mixed. In most cases, when undoing commands that affected a single
3726 line, the cursor was moved to the start of added or changed text, or
3727 immediately after deleted text. However, if the user had moved from the
3728 line being changed, the column was either set to the first non-
3729 <blank>, returned to the origin of the command, or remained unchanged.
3730 When undoing commands that affected multiple lines or entire lines, the
3731 cursor was moved to the first character in the first line restored. As
3732 an example of how inconsistent this was, a search, followed by an o
3733 text input command, followed by an undo would return the cursor to the
3734 location where the o command was entered, but a cw command followed by
3735 an o command followed by an undo would return the cursor to the first
3736 non- <blank> of the line. IEEE Std 1003.1-2001 requires the most useful
3737 of these behaviors, and discards the least useful, in the interest of
3738 consistency and simplicity of specification.
3739
3740 Yank
3741 Historically, the yank command did not move to the end of the motion if
3742 the motion was in the forward direction. It moved to the end of the
3743 motion if the motion was in the backward direction, except for the _
3744 command, or for the G and ' commands when the end of the motion was on
3745 the current line. This was further complicated by the fact that for a
3746 number of motion commands, the yank command moved the cursor but did
3747 not update the screen; for example, a subsequent command would move the
3748 cursor from the end of the motion, even though the cursor on the screen
3749 had not reflected the cursor movement for the yank command.
3750 IEEE Std 1003.1-2001 requires that all yank commands associated with
3751 backward motions move the cursor to the end of the motion for consis‐
3752 tency, and specifically, to make ' commands as motions consistent with
3753 search patterns as motions.
3754
3755 Yank Current Line
3756 Some historical implementations of the Y command did not behave as
3757 described by IEEE Std 1003.1-2001 when the '_' key was remapped because
3758 they were implemented by pushing the '_' key onto the input queue and
3759 reprocessing it. IEEE Std 1003.1-2001 does not permit this behavior.
3760
3761 Redraw Window
3762 Historically, the z command always redrew the screen. This is permitted
3763 but not required by IEEE Std 1003.1-2001, because of the frequent use
3764 of the z command in macros such as map n nz. for screen positioning,
3765 instead of its use to change the screen size. The standard developers
3766 believed that expanding or scrolling the screen offered a better inter‐
3767 face for users. The ability to redraw the screen is preserved if the
3768 optional new window size is specified, and in the <control>-L and <con‐
3769 trol>-R commands.
3770
3771 The semantics of z^ are confusing at best. Historical practice is that
3772 the screen before the screen that ended with the specified line is dis‐
3773 played. IEEE Std 1003.1-2001 requires conformance to historical prac‐
3774 tice.
3775
3776 Historically, the z command would not display a partial line at the top
3777 or bottom of the screen. If the partial line would normally have been
3778 displayed at the bottom of the screen, the command worked, but the par‐
3779 tial line was replaced with '@' characters. If the partial line would
3780 normally have been displayed at the top of the screen, the command
3781 would fail. For consistency and simplicity of specification,
3782 IEEE Std 1003.1-2001 does not permit this behavior.
3783
3784 Historically, the z command with a line specification of 1 ignored the
3785 command. For consistency and simplicity of specification,
3786 IEEE Std 1003.1-2001 does not permit this behavior.
3787
3788 Historically, the z command did not set the cursor column to the first
3789 non- <blank> for the character if the first screen was to be displayed,
3790 and was already displayed. For consistency and simplicity of specifica‐
3791 tion, IEEE Std 1003.1-2001 does not permit this behavior.
3792
3793 Input Mode Commands in vi
3794 Historical implementations of vi did not permit the user to erase more
3795 than a single line of input, or to use normal erase characters such as
3796 line erase, worderase, and erase to erase autoindent characters. As
3797 there exist implementations of vi that do not have these limitations,
3798 both behaviors are permitted, but only historical practice is required.
3799 In the case of these extensions, vi is required to pause at the autoin‐
3800 dent and previous line boundaries.
3801
3802 Historical implementations of vi updated only the portion of the screen
3803 where the current cursor character was displayed. For example, con‐
3804 sider the vi input keystrokes:
3805
3806
3807 iabcd<escape>0C<tab>
3808
3809 Historically, the <tab> would overwrite the characters "abcd" when it
3810 was displayed. Other implementations replace only the 'a' character
3811 with the <tab>, and then push the rest of the characters ahead of the
3812 cursor. Both implementations have problems. The historical implementa‐
3813 tion is probably visually nicer for the above example; however, for the
3814 keystrokes:
3815
3816
3817 iabcd<ESC>0R<tab><ESC>
3818
3819 the historical implementation results in the string "bcd" disappearing
3820 and then magically reappearing when the <ESC> character is entered.
3821 IEEE Std 1003.1-2001 requires the former behavior when overwriting
3822 erase-columns-that is, overwriting characters that are no longer logi‐
3823 cally part of the edit buffer-and the latter behavior otherwise.
3824
3825 Historical implementations of vi discarded the <control>-D and <con‐
3826 trol>-T characters when they were entered at places where their command
3827 functionality was not appropriate. IEEE Std 1003.1-2001 requires that
3828 the <control>-T functionality always be available, and that <control>-D
3829 be treated as any other key when not operating on autoindent charac‐
3830 ters.
3831
3832 NUL
3833 Some historical implementations of vi limited the number of characters
3834 entered using the NUL input character to 256 bytes.
3835 IEEE Std 1003.1-2001 permits this limitation; however, implementations
3836 are encouraged to remove this limit.
3837
3838 <control>-D
3839 See also Rationale for the input mode command <newline>. The hidden
3840 assumptions in the <control>-D command (and in the vi autoindent speci‐
3841 fication in general) is that <space>s take up a single column on the
3842 screen and that <tab>s are comprised of an integral number of <space>s.
3843
3844 <newline>
3845 Implementations are permitted to rewrite autoindent characters in the
3846 line when <newline>, <carriage-return>, <control>-D, and <control>-T
3847 are entered, or when the shift commands are used, because historical
3848 implementations have both done so and found it necessary to do so. For
3849 example, a <control>-D when the cursor is preceded by a single <tab>,
3850 with tabstop set to 8, and shiftwidth set to 3, will result in the
3851 <tab> being replaced by several <space>s.
3852
3853 <control>-T
3854 See also the Rationale for the input mode command <newline>. Histori‐
3855 cally, <control>-T only worked if no non- <blank>s had yet been input
3856 in the current input line. In addition, the characters inserted by
3857 <control>-T were treated as autoindent characters, and could not be
3858 erased using normal user erase characters. Because implementations
3859 exist that do not have these limitations, and as moving to a column
3860 boundary is generally useful, IEEE Std 1003.1-2001 requires that both
3861 limitations be removed.
3862
3863 <control>-V
3864 Historically, vi used ^V, regardless of the value of the literal-next
3865 character of the terminal. IEEE Std 1003.1-2001 requires conformance
3866 to historical practice.
3867
3868 The uses described for <control>-V can also be accomplished with <con‐
3869 trol>-Q, which is useful on terminals that use <control>-V for the
3870 down-arrow function. However, most historical implementations use <con‐
3871 trol>-Q for the termios START character, so the editor will generally
3872 not receive the <control>-Q unless stty ixon mode is set to off. (In
3873 addition, some historical implementations of vi explicitly set ixon
3874 mode to on, so it was difficult for the user to set it to off.) Any of
3875 the command characters described in IEEE Std 1003.1-2001 can be made
3876 ineffective by their selection as termios control characters, using the
3877 stty utility or other methods described in the System Interfaces volume
3878 of IEEE Std 1003.1-2001.
3879
3880 <ESC>
3881 Historically, SIGINT alerted the terminal when used to end input mode.
3882 This behavior is permitted, but not required, by IEEE Std 1003.1-2001.
3883
3885 None.
3886
3888 ed, ex, stty
3889
3891 Portions of this text are reprinted and reproduced in electronic form
3892 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
3893 -- Portable Operating System Interface (POSIX), The Open Group Base
3894 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
3895 Electrical and Electronics Engineers, Inc and The Open Group. In the
3896 event of any discrepancy between this version and the original IEEE and
3897 The Open Group Standard, the original IEEE and The Open Group Standard
3898 is the referee document. The original Standard can be obtained online
3899 at http://www.opengroup.org/unix/online.html .
3900
3901
3902
3903IEEE/The Open Group 2003 VI(1P)