1EX(1P) POSIX Programmer's Manual EX(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
11
13 ex — text editor
14
16 ex [−rR] [−s|−v] [−c command] [−t tagstring] [−w size] [file...]
17
19 The ex utility is a line-oriented text editor. There are two other
20 modes of the editor—open and visual—in which screen-oriented editing is
21 available. This is described more fully by the ex open and visual com‐
22 mands and in vi.
23
24 If an operand is '−', the results are unspecified.
25
26 This section uses the term edit buffer to describe the current working
27 text. No specific implementation is implied by this term. All editing
28 changes are performed on the edit buffer, and no changes to it shall
29 affect any file until an editor command writes the file.
30
31 Certain terminals do not have all the capabilities necessary to support
32 the complete ex definition, such as the full-screen editing commands
33 (visual mode or open mode). When these commands cannot be supported on
34 such terminals, this condition shall not produce an error message such
35 as ``not an editor command'' or report a syntax error. The implementa‐
36 tion may either accept the commands and produce results on the screen
37 that are the result of an unsuccessful attempt to meet the requirements
38 of this volume of POSIX.1‐2008 or report an error describing the termi‐
39 nal-related deficiency.
40
42 The ex utility shall conform to the Base Definitions volume of
43 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines, except for the
44 unspecified usage of '−', and that '+' may be recognized as an option
45 delimiter as well as '−'.
46
47 The following options shall be supported:
48
49 −c command
50 Specify an initial command to be executed in the first edit
51 buffer loaded from an existing file (see the EXTENDED
52 DESCRIPTION section). Implementations may support more than
53 a single −c option. In such implementations, the specified
54 commands shall be executed in the order specified on the com‐
55 mand line.
56
57 −r Recover the named files (see the EXTENDED DESCRIPTION sec‐
58 tion). Recovery information for a file shall be saved during
59 an editor or system crash (for example, when the editor is
60 terminated by a signal which the editor can catch), or after
61 the use of an ex preserve command.
62
63 A crash in this context is an unexpected failure of the sys‐
64 tem or utility that requires restarting the failed system or
65 utility. A system crash implies that any utilities running at
66 the time also crash. In the case of an editor or system
67 crash, the number of changes to the edit buffer (since the
68 most recent preserve command) that will be recovered is
69 unspecified.
70
71 If no file operands are given and the −t option is not speci‐
72 fied, all other options, the EXINIT variable, and any .exrc
73 files shall be ignored; a list of all recoverable files
74 available to the invoking user shall be written, and the edi‐
75 tor shall exit normally without further action.
76
77 −R Set readonly edit option.
78
79 −s Prepare ex for batch use by taking the following actions:
80
81 * Suppress writing prompts and informational (but not diag‐
82 nostic) messages.
83
84 * Ignore the value of TERM and any implementation default
85 terminal type and assume the terminal is a type incapable
86 of supporting open or visual modes; see the visual com‐
87 mand and the description of vi.
88
89 * Suppress the use of the EXINIT environment variable and
90 the reading of any .exrc file; see the EXTENDED DESCRIP‐
91 TION section.
92
93 * Suppress autoindentation, ignoring the value of the
94 autoindent edit option.
95
96 −t tagstring
97 Edit the file containing the specified tagstring; see ctags.
98 The tags feature represented by −t tagstring and the tag com‐
99 mand is optional. It shall be provided on any system that
100 also provides a conforming implementation of ctags; other‐
101 wise, the use of −t produces undefined results. On any sys‐
102 tem, it shall be an error to specify more than a single −t
103 option.
104
105 −v Begin in visual mode (see vi).
106
107 −w size Set the value of the window editor option to size.
108
110 The following operand shall be supported:
111
112 file A pathname of a file to be edited.
113
115 The standard input consists of a series of commands and input text, as
116 described in the EXTENDED DESCRIPTION section. The implementation may
117 limit each line of standard input to a length of {LINE_MAX}.
118
119 If the standard input is not a terminal device, it shall be as if the
120 −s option had been specified.
121
122 If a read from the standard input returns an error, or if the editor
123 detects an end-of-file condition from the standard input, it shall be
124 equivalent to a SIGHUP asynchronous event.
125
127 Input files shall be text files or files that would be text files
128 except for an incomplete last line that is not longer than {LINE_MAX}−1
129 bytes in length and contains no NUL characters. By default, any incom‐
130 plete last line shall be treated as if it had a trailing <newline>.
131 The editing of other forms of files may optionally be allowed by ex
132 implementations.
133
134 The .exrc files and source files shall be text files consisting of ex
135 commands; see the EXTENDED DESCRIPTION section.
136
137 By default, the editor shall read lines from the files to be edited
138 without interpreting any of those lines as any form of editor command.
139
141 The following environment variables shall affect the execution of ex:
142
143 COLUMNS Override the system-selected horizontal screen size. See the
144 Base Definitions volume of POSIX.1‐2008, Chapter 8, Environ‐
145 ment Variables for valid values and results when it is unset
146 or null.
147
148 EXINIT Determine a list of ex commands that are executed on editor
149 start-up. See the EXTENDED DESCRIPTION section for more
150 details of the initialization phase.
151
152 HOME Determine a pathname of a directory that shall be searched
153 for an editor start-up file named .exrc; see the EXTENDED
154 DESCRIPTION section.
155
156 LANG Provide a default value for the internationalization vari‐
157 ables that are unset or null. (See the Base Definitions vol‐
158 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
159 ables for the precedence of internationalization variables
160 used to determine the values of locale categories.)
161
162 LC_ALL If set to a non-empty string value, override the values of
163 all the other internationalization variables.
164
165 LC_COLLATE
166 Determine the locale for the behavior of ranges, equivalence
167 classes, and multi-character collating elements within regu‐
168 lar expressions.
169
170 LC_CTYPE Determine the locale for the interpretation of sequences of
171 bytes of text data as characters (for example, single-byte as
172 opposed to multi-byte characters in arguments and input
173 files), the behavior of character classes within regular
174 expressions, the classification of characters as uppercase or
175 lowercase letters, the case conversion of letters, and the
176 detection of word boundaries.
177
178 LC_MESSAGES
179 Determine the locale that should be used to affect the format
180 and contents of diagnostic messages written to standard
181 error.
182
183 LINES Override the system-selected vertical screen size, used as
184 the number of lines in a screenful and the vertical screen
185 size in visual mode. See the Base Definitions volume of
186 POSIX.1‐2008, Chapter 8, Environment Variables for valid val‐
187 ues and results when it is unset or null.
188
189 NLSPATH Determine the location of message catalogs for the processing
190 of LC_MESSAGES.
191
192 PATH Determine the search path for the shell command specified in
193 the ex editor commands !, shell, read, and write, and the
194 open and visual mode command !; see the description of com‐
195 mand search and execution in Section 2.9.1.1, Command Search
196 and Execution.
197
198 SHELL Determine the preferred command line interpreter for use as
199 the default value of the shell edit option.
200
201 TERM Determine the name of the terminal type. If this variable is
202 unset or null, an unspecified default terminal type shall be
203 used.
204
206 The following term is used in this and following sections to specify
207 command and asynchronous event actions:
208
209 complete write
210 A complete write is a write of the entire contents of the
211 edit buffer to a file of a type other than a terminal device,
212 or the saving of the edit buffer caused by the user executing
213 the ex preserve command. Writing the contents of the edit
214 buffer to a temporary file that will be removed when the edi‐
215 tor exits shall not be considered a complete write.
216
217 The following actions shall be taken upon receipt of signals:
218
219 SIGINT If the standard input is not a terminal device, ex shall not
220 write the file or return to command or text input mode, and
221 shall exit with a non-zero exit status.
222
223 Otherwise, if executing an open or visual text input mode
224 command, ex in receipt of SIGINT shall behave identically to
225 its receipt of the <ESC> character.
226
227 Otherwise:
228
229 1. If executing an ex text input mode command, all input
230 lines that have been completely entered shall be resolved
231 into the edit buffer, and any partially entered line
232 shall be discarded.
233
234 2. If there is a currently executing command, it shall be
235 aborted and a message displayed. Unless otherwise speci‐
236 fied by the ex or vi command descriptions, it is unspeci‐
237 fied whether any lines modified by the executing command
238 appear modified, or as they were before being modified by
239 the executing command, in the buffer.
240
241 If the currently executing command was a motion command,
242 its associated command shall be discarded.
243
244 3. If in open or visual command mode, the terminal shall be
245 alerted.
246
247 4. The editor shall then return to command mode.
248
249 SIGCONT The screen shall be refreshed if in open or visual mode.
250
251 SIGHUP If the edit buffer has been modified since the last complete
252 write, ex shall attempt to save the edit buffer so that it
253 can be recovered later using the −r option or the ex recover
254 command. The editor shall not write the file or return to
255 command or text input mode, and shall terminate with a non-
256 zero exit status.
257
258 SIGTERM Refer to SIGHUP.
259
260 The action taken for all other signals is unspecified.
261
263 The standard output shall be used only for writing prompts to the user,
264 for informational messages, and for writing lines from the file.
265
267 The standard error shall be used only for diagnostic messages.
268
270 The output from ex shall be text files.
271
273 Only the ex mode of the editor is described in this section. See vi for
274 additional editing capabilities available in ex.
275
276 When an error occurs, ex shall write a message. If the terminal sup‐
277 ports a standout mode (such as inverse video), the message shall be
278 written in standout mode. If the terminal does not support a standout
279 mode, and the edit option errorbells is set, an alert action shall pre‐
280 cede the error message.
281
282 By default, ex shall start in command mode, which shall be indicated by
283 a : prompt; see the prompt command. Text input mode can be entered by
284 the append, insert, or change commands; it can be exited (and command
285 mode re-entered) by typing a <period> ('.') alone at the beginning of
286 a line.
287
288 Initialization in ex and vi
289 The following symbols are used in this and following sections to spec‐
290 ify locations in the edit buffer:
291
292 alternate and current pathnames
293 Two pathnames, named current and alternate, are maintained by the
294 editor. Any ex commands that take filenames as arguments shall
295 set them as follows:
296
297 1. If a file argument is specified to the ex edit, ex, or
298 recover commands, or if an ex tag command replaces the con‐
299 tents of the edit buffer.
300
301 a. If the command replaces the contents of the edit buffer,
302 the current pathname shall be set to the file argument or
303 the file indicated by the tag, and the alternate pathname
304 shall be set to the previous value of the current path‐
305 name.
306
307 b. Otherwise, the alternate pathname shall be set to the
308 file argument.
309
310 2. If a file argument is specified to the ex next command:
311
312 a. If the command replaces the contents of the edit buffer,
313 the current pathname shall be set to the first file argu‐
314 ment, and the alternate pathname shall be set to the pre‐
315 vious value of the current pathname.
316
317 3. If a file argument is specified to the ex file command, the
318 current pathname shall be set to the file argument, and the
319 alternate pathname shall be set to the previous value of the
320 current pathname.
321
322 4. If a file argument is specified to the ex read and write com‐
323 mands (that is, when reading or writing a file, and not to
324 the program named by the shell edit option), or a file argu‐
325 ment is specified to the ex xit command:
326
327 a. If the current pathname has no value, the current path‐
328 name shall be set to the file argument.
329
330 b. Otherwise, the alternate pathname shall be set to the
331 file argument.
332
333 If the alternate pathname is set to the previous value of the
334 current pathname when the current pathname had no previous value,
335 then the alternate pathname shall have no value as a result.
336
337 current line
338 The line of the edit buffer referenced by the cursor. Each com‐
339 mand description specifies the current line after the command has
340 been executed, as the current line value. When the edit buffer
341 contains no lines, the current line shall be zero; see Addressing
342 in ex.
343
344 current column
345 The current display line column occupied by the cursor. (The col‐
346 umns shall be numbered beginning at 1.) Each command description
347 specifies the current column after the command has been executed,
348 as the current column value. This column is an ideal column that
349 is remembered over the lifetime of the editor. The actual display
350 line column upon which the cursor rests may be different from the
351 current column; see the cursor positioning discussion in Command
352 Descriptions in vi.
353
354 set to non-<blank>
355 A description for a current column value, meaning that the cur‐
356 rent column shall be set to the last display line column on which
357 is displayed any part of the first non-<blank> of the line. If
358 the line has no non-<blank> non-<newline> characters, the current
359 column shall be set to the last display line column on which is
360 displayed any part of the last non-<newline> character in the
361 line. If the line is empty, the current column shall be set to
362 column position 1.
363
364 The length of lines in the edit buffer may be limited to {LINE_MAX}
365 bytes. In open and visual mode, the length of lines in the edit buffer
366 may be limited to the number of characters that will fit in the dis‐
367 play. If either limit is exceeded during editing, an error message
368 shall be written. If either limit is exceeded by a line read in from a
369 file, an error message shall be written and the edit session may be
370 terminated.
371
372 If the editor stops running due to any reason other than a user com‐
373 mand, and the edit buffer has been modified since the last complete
374 write, it shall be equivalent to a SIGHUP asynchronous event. If the
375 system crashes, it shall be equivalent to a SIGHUP asynchronous event.
376
377 During initialization (before the first file is copied into the edit
378 buffer or any user commands from the terminal are processed) the fol‐
379 lowing shall occur:
380
381 1. If the environment variable EXINIT is set, the editor shall execute
382 the ex commands contained in that variable.
383
384 2. If the EXINIT variable is not set, and all of the following are
385 true:
386
387 a. The HOME environment variable is not null and not empty.
388
389 b. The file .exrc in the directory referred to by the HOME envi‐
390 ronment variable:
391
392 i. Exists
393
394 ii. Is owned by the same user ID as the real user ID of the
395 process or the process has appropriate privileges
396
397 iii. Is not writable by anyone other than the owner
398
399 the editor shall execute the ex commands contained in that file.
400
401 3. If and only if all of the following are true:
402
403 a. The current directory is not referred to by the HOME environ‐
404 ment variable.
405
406 b. A command in the EXINIT environment variable or a command in
407 the .exrc file in the directory referred to by the HOME envi‐
408 ronment variable sets the editor option exrc.
409
410 c. The .exrc file in the current directory:
411
412 i. Exists
413
414 ii. Is owned by the same user ID as the real user ID of the
415 process, or by one of a set of implementation-defined user
416 IDs
417
418 iii. Is not writable by anyone other than the owner
419
420 the editor shall attempt to execute the ex commands contained in
421 that file.
422
423 Lines in any .exrc file that are blank lines shall be ignored. If any
424 .exrc file exists, but is not read for ownership or permission reasons,
425 it shall be an error.
426
427 After the EXINIT variable and any .exrc files are processed, the first
428 file specified by the user shall be edited, as follows:
429
430 1. If the user specified the −t option, the effect shall be as if the
431 ex tag command was entered with the specified argument, with the
432 exception that if tag processing does not result in a file to edit,
433 the effect shall be as described in step 3. below.
434
435 2. Otherwise, if the user specified any command line file arguments,
436 the effect shall be as if the ex edit command was entered with the
437 first of those arguments as its file argument.
438
439 3. Otherwise, the effect shall be as if the ex edit command was
440 entered with a nonexistent filename as its file argument. It is
441 unspecified whether this action shall set the current pathname. In
442 an implementation where this action does not set the current path‐
443 name, any editor command using the current pathname shall fail
444 until an editor command sets the current pathname.
445
446 If the −r option was specified, the first time a file in the initial
447 argument list or a file specified by the −t option is edited, if recov‐
448 ery information has previously been saved about it, that information
449 shall be recovered and the editor shall behave as if the contents of
450 the edit buffer have already been modified. If there are multiple
451 instances of the file to be recovered, the one most recently saved
452 shall be recovered, and an informational message that there are previ‐
453 ous versions of the file that can be recovered shall be written. If no
454 recovery information about a file is available, an informational mes‐
455 sage to this effect shall be written, and the edit shall proceed as
456 usual.
457
458 If the −c option was specified, the first time a file that already
459 exists (including a file that might not exist but for which recovery
460 information is available, when the −r option is specified) replaces or
461 initializes the contents of the edit buffer, the current line shall be
462 set to the last line of the edit buffer, the current column shall be
463 set to non-<blank>, and the ex commands specified with the −c option
464 shall be executed. In this case, the current line and current column
465 shall not be set as described for the command associated with the
466 replacement or initialization of the edit buffer contents. However, if
467 the −t option or a tag command is associated with this action, the −c
468 option commands shall be executed and then the movement to the tag
469 shall be performed.
470
471 The current argument list shall initially be set to the filenames spec‐
472 ified by the user on the command line. If no filenames are specified by
473 the user, the current argument list shall be empty. If the −t option
474 was specified, it is unspecified whether any filename resulting from
475 tag processing shall be prepended to the current argument list. In the
476 case where the filename is added as a prefix to the current argument
477 list, the current argument list reference shall be set to that file‐
478 name. In the case where the filename is not added as a prefix to the
479 current argument list, the current argument list reference shall logi‐
480 cally be located before the first of the filenames specified on the
481 command line (for example, a subsequent ex next command shall edit the
482 first filename from the command line). If the −t option was not speci‐
483 fied, the current argument list reference shall be to the first of the
484 filenames on the command line.
485
486 Addressing in ex
487 Addressing in ex relates to the current line and the current column;
488 the address of a line is its 1-based line number, the address of a col‐
489 umn is its 1-based count from the beginning of the line. Generally, the
490 current line is the last line affected by a command. The current line
491 number is the address of the current line. In each command description,
492 the effect of the command on the current line number and the current
493 column is described.
494
495 Addresses are constructed as follows:
496
497 1. The character '.' (period) shall address the current line.
498
499 2. The character '$' shall address the last line of the edit buffer.
500
501 3. The positive decimal number n shall address the nth line of the
502 edit buffer.
503
504 4. The address "'x" refers to the line marked with the mark name char‐
505 acter 'x', which shall be a lowercase letter from the portable
506 character set, the backquote character, or the single-quote charac‐
507 ter. It shall be an error if the line that was marked is not cur‐
508 rently present in the edit buffer or the mark has not been set.
509 Lines can be marked with the ex mark or k commands, or the vi m
510 command.
511
512 5. A regular expression enclosed by <slash> characters ('/') shall
513 address the first line found by searching forwards from the line
514 following the current line toward the end of the edit buffer and
515 stopping at the first line for which the line excluding the termi‐
516 nating <newline> matches the regular expression. As stated in Regu‐
517 lar Expressions in ex, an address consisting of a null regular
518 expression delimited by <slash> characters ("//") shall address the
519 next line for which the line excluding the terminating <newline>
520 matches the last regular expression encountered. In addition, the
521 second <slash> can be omitted at the end of a command line. If the
522 wrapscan edit option is set, the search shall wrap around to the
523 beginning of the edit buffer and continue up to and including the
524 current line, so that the entire edit buffer is searched. Within
525 the regular expression, the sequence "\/" shall represent a literal
526 <slash> instead of the regular expression delimiter.
527
528 6. A regular expression enclosed in <question-mark> characters ('?')
529 shall address the first line found by searching backwards from the
530 line preceding the current line toward the beginning of the edit
531 buffer and stopping at the first line for which the line excluding
532 the terminating <newline> matches the regular expression. An
533 address consisting of a null regular expression delimited by <ques‐
534 tion-mark> characters ("??") shall address the previous line for
535 which the line excluding the terminating <newline> matches the last
536 regular expression encountered. In addition, the second <question-
537 mark> can be omitted at the end of a command line. If the wrapscan
538 edit option is set, the search shall wrap around from the beginning
539 of the edit buffer to the end of the edit buffer and continue up to
540 and including the current line, so that the entire edit buffer is
541 searched. Within the regular expression, the sequence "\?" shall
542 represent a literal <question-mark> instead of the RE delimiter.
543
544 7. A <plus-sign> ('+') or a minus-sign ('−') followed by a decimal
545 number shall address the current line plus or minus the number. A
546 '+' or '−' not followed by a decimal number shall address the cur‐
547 rent line plus or minus 1.
548
549 Addresses can be followed by zero or more address offsets, optionally
550 <blank>-separated. Address offsets are constructed as follows:
551
552 1. A '+' or '−' immediately followed by a decimal number shall add
553 (subtract) the indicated number of lines to (from) the address. A
554 '+' or '−' not followed by a decimal number shall add (subtract) 1
555 to (from) the address.
556
557 2. A decimal number shall add the indicated number of lines to the
558 address.
559
560 It shall not be an error for an intermediate address value to be less
561 than zero or greater than the last line in the edit buffer. It shall be
562 an error for the final address value to be less than zero or greater
563 than the last line in the edit buffer.
564
565 Commands take zero, one, or two addresses; see the descriptions of
566 1addr and 2addr in Command Descriptions in ex. If more than the
567 required number of addresses are provided to a command that requires
568 zero addresses, it shall be an error. Otherwise, if more than the
569 required number of addresses are provided to a command, the addresses
570 specified first shall be evaluated and then discarded until the maximum
571 number of valid addresses remain.
572
573 Addresses shall be separated from each other by a <comma> (',') or a
574 <semicolon> (';'). If no address is specified before or after a
575 <comma> or <semicolon> separator, it shall be as if the address of the
576 current line was specified before or after the separator. In the case
577 of a <semicolon> separator, the current line ('.') shall be set to the
578 first address, and only then will the next address be calculated. This
579 feature can be used to determine the starting line for forwards and
580 backwards searches (see rules 5. and 6.).
581
582 A <percent-sign> ('%') shall be equivalent to entering the two
583 addresses "1,$".
584
585 Any delimiting <blank> characters between addresses, address separa‐
586 tors, or address offsets shall be discarded.
587
588 Command Line Parsing in ex
589 The following symbol is used in this and following sections to describe
590 parsing behavior:
591
592 escape If a character is referred to as ``<backslash>-escaped'' or
593 ``<control>‐V-escaped'', it shall mean that the character
594 acquired or lost a special meaning by virtue of being pre‐
595 ceded, respectively, by a <backslash> or <control>‐V charac‐
596 ter. Unless otherwise specified, the escaping character shall
597 be discarded at that time and shall not be further considered
598 for any purpose.
599
600 Command-line parsing shall be done in the following steps. For each
601 step, characters already evaluated shall be ignored; that is, the
602 phrase ``leading character'' refers to the next character that has not
603 yet been evaluated.
604
605 1. Leading <colon> characters shall be skipped.
606
607 2. Leading <blank> characters shall be skipped.
608
609 3. If the leading character is a double-quote character, the charac‐
610 ters up to and including the next non-<backslash>-escaped <newline>
611 shall be discarded, and any subsequent characters shall be parsed
612 as a separate command.
613
614 4. Leading characters that can be interpreted as addresses shall be
615 evaluated; see Addressing in ex.
616
617 5. Leading <blank> characters shall be skipped.
618
619 6. If the next character is a <vertical-line> character or a <new‐
620 line>:
621
622 a. If the next character is a <newline>:
623
624 i. If ex is in open or visual mode, the current line shall be
625 set to the last address specified, if any.
626
627 ii. Otherwise, if the last command was terminated by a <verti‐
628 cal-line> character, no action shall be taken; for exam‐
629 ple, the command "||<newline>" shall execute two implied
630 commands, not three.
631
632 iii. Otherwise, step 6.b. shall apply.
633
634 b. Otherwise, the implied command shall be the print command. The
635 last #, p, and l flags specified to any ex command shall be
636 remembered and shall apply to this implied command. Executing
637 the ex number, print, or list command shall set the remembered
638 flags to #, nothing, and l, respectively, plus any other flags
639 specified for that execution of the number, print, or list com‐
640 mand.
641
642 If ex is not currently performing a global or v command, and no
643 address or count is specified, the current line shall be incre‐
644 mented by 1 before the command is executed. If incrementing the
645 current line would result in an address past the last line in
646 the edit buffer, the command shall fail, and the increment
647 shall not happen.
648
649 c. The <newline> or <vertical-line> character shall be discarded
650 and any subsequent characters shall be parsed as a separate
651 command.
652
653 7. The command name shall be comprised of the next character (if the
654 character is not alphabetic), or the next character and any subse‐
655 quent alphabetic characters (if the character is alphabetic), with
656 the following exceptions:
657
658 a. Commands that consist of any prefix of the characters in the
659 command name delete, followed immediately by any of the charac‐
660 ters 'l', 'p', '+', '−', or '#' shall be interpreted as a
661 delete command, followed by a <blank>, followed by the charac‐
662 ters that were not part of the prefix of the delete command.
663 The maximum number of characters shall be matched to the com‐
664 mand name delete; for example, "del" shall not be treated as
665 "de" followed by the flag l.
666
667 b. Commands that consist of the character 'k', followed by a char‐
668 acter that can be used as the name of a mark, shall be equiva‐
669 lent to the mark command followed by a <blank>, followed by the
670 character that followed the 'k'.
671
672 c. Commands that consist of the character 's', followed by charac‐
673 ters that could be interpreted as valid options to the s com‐
674 mand, shall be the equivalent of the s command, without any
675 pattern or replacement values, followed by a <blank>, followed
676 by the characters after the 's'.
677
678 8. The command name shall be matched against the possible command
679 names, and a command name that contains a prefix matching the char‐
680 acters specified by the user shall be the executed command. In the
681 case of commands where the characters specified by the user could
682 be ambiguous, the executed command shall be as follows:
683
684 ┌───┬────────┬┬───┬───────┬┬───┬───────┐
685 │a │ append ││n │ next ││t │ t │
686 │c │ change ││p │ print ││u │ undo │
687 │ch │ change ││pr │ print ││un │ undo │
688 │e │ edit ││r │ read ││v │ v │
689 │m │ move ││re │ read ││w │ write │
690 │ma │ mark ││s │ s ││ │ │
691 └───┴────────┴┴───┴───────┴┴───┴───────┘
692 Implementation extensions with names causing similar ambiguities
693 shall not be checked for a match until all possible matches for
694 commands specified by POSIX.1‐2008 have been checked.
695
696 9. If the command is a ! command, or if the command is a read command
697 followed by zero or more <blank> characters and a !, or if the com‐
698 mand is a write command followed by one or more <blank> characters
699 and a !, the rest of the command shall include all characters up to
700 a non-<backslash>-escaped <newline>. The <newline> shall be dis‐
701 carded and any subsequent characters shall be parsed as a separate
702 ex command.
703
704 10. Otherwise, if the command is an edit, ex, or next command, or a
705 visual command while in open or visual mode, the next part of the
706 command shall be parsed as follows:
707
708 a. Any '!' character immediately following the command shall be
709 skipped and be part of the command.
710
711 b. Any leading <blank> characters shall be skipped and be part of
712 the command.
713
714 c. If the next character is a '+', characters up to the first
715 non-<backslash>-escaped <newline> or non-<backslash>-escaped
716 <blank> shall be skipped and be part of the command.
717
718 d. The rest of the command shall be determined by the steps speci‐
719 fied in paragraph 12.
720
721 11. Otherwise, if the command is a global, open, s, or v command, the
722 next part of the command shall be parsed as follows:
723
724 a. Any leading <blank> characters shall be skipped and be part of
725 the command.
726
727 b. If the next character is not an alphanumeric, double-quote,
728 <newline>, <backslash>, or <vertical-line> character:
729
730 i. The next character shall be used as a command delimiter.
731
732 ii. If the command is a global, open, or v command, characters
733 up to the first non-<backslash>-escaped <newline>, or
734 first non-<backslash>-escaped delimiter character, shall
735 be skipped and be part of the command.
736
737 iii. If the command is an s command, characters up to the first
738 non-<backslash>-escaped <newline>, or second non-<back‐
739 slash>-escaped delimiter character, shall be skipped and
740 be part of the command.
741
742 c. If the command is a global or v command, characters up to the
743 first non-<backslash>-escaped <newline> shall be skipped and be
744 part of the command.
745
746 d. Otherwise, the rest of the command shall be determined by the
747 steps specified in paragraph 12.
748
749 12. Otherwise:
750
751 a. If the command was a map, unmap, abbreviate, or unabbreviate
752 command, characters up to the first non-<control>‐V-escaped
753 <newline>, <vertical-line>, or double-quote character shall be
754 skipped and be part of the command.
755
756 b. Otherwise, characters up to the first non-<backslash>-escaped
757 <newline>, <vertical-line>, or double-quote character shall be
758 skipped and be part of the command.
759
760 c. If the command was an append, change, or insert command, and
761 the step 12.b. ended at a <vertical-line> character, any subse‐
762 quent characters, up to the next non-<backslash>-escaped <new‐
763 line> shall be used as input text to the command.
764
765 d. If the command was ended by a double-quote character, all sub‐
766 sequent characters, up to the next non-<backslash>-escaped
767 <newline>, shall be discarded.
768
769 e. The terminating <newline> or <vertical-line> character shall be
770 discarded and any subsequent characters shall be parsed as a
771 separate ex command.
772
773 Command arguments shall be parsed as described by the Synopsis and
774 Description of each individual ex command. This parsing shall not be
775 <blank>-sensitive, except for the ! argument, which must follow the
776 command name without intervening <blank> characters, and where it would
777 otherwise be ambiguous. For example, count and flag arguments need not
778 be <blank>-separated because "d22p" is not ambiguous, but file argu‐
779 ments to the ex next command must be separated by one or more <blank>
780 characters. Any <blank> in command arguments for the abbreviate, unab‐
781 breviate, map, and unmap commands can be <control>‐V-escaped, in which
782 case the <blank> shall not be used as an argument delimiter. Any
783 <blank> in the command argument for any other command can be <back‐
784 slash>-escaped, in which case that <blank> shall not be used as an
785 argument delimiter.
786
787 Within command arguments for the abbreviate, unabbreviate, map, and
788 unmap commands, any character can be <control>‐V-escaped. All such
789 escaped characters shall be treated literally and shall have no special
790 meaning. Within command arguments for all other ex commands that are
791 not regular expressions or replacement strings, any character that
792 would otherwise have a special meaning can be <backslash>-escaped.
793 Escaped characters shall be treated literally, without special meaning
794 as shell expansion characters or '!', '%', and '#' expansion charac‐
795 ters. See Regular Expressions in ex and Replacement Strings in ex for
796 descriptions of command arguments that are regular expressions or
797 replacement strings.
798
799 Non-<backslash>-escaped '%' characters appearing in file arguments to
800 any ex command shall be replaced by the current pathname; unescaped '#'
801 characters shall be replaced by the alternate pathname. It shall be an
802 error if '%' or '#' characters appear unescaped in an argument and
803 their corresponding values are not set.
804
805 Non-<backslash>-escaped '!' characters in the arguments to either the
806 ex ! command or the open and visual mode ! command, or in the argu‐
807 ments to the ex read command, where the first non-<blank> after the
808 command name is a '!' character, or in the arguments to the ex write
809 command where the command name is followed by one or more <blank> char‐
810 acters and the first non-<blank> after the command name is a '!' char‐
811 acter, shall be replaced with the arguments to the last of those three
812 commands as they appeared after all unescaped '%', '#', and '!' char‐
813 acters were replaced. It shall be an error if '!' characters appear
814 unescaped in one of these commands and there has been no previous exe‐
815 cution of one of these commands.
816
817 If an error occurs during the parsing or execution of an ex command:
818
819 * An informational message to this effect shall be written. Execution
820 of the ex command shall stop, and the cursor (for example, the cur‐
821 rent line and column) shall not be further modified.
822
823 * If the ex command resulted from a map expansion, all characters
824 from that map expansion shall be discarded, except as otherwise
825 specified by the map command.
826
827 * Otherwise, if the ex command resulted from the processing of an
828 EXINIT environment variable, a .exrc file, a :source command, a −c
829 option, or a +command specified to an ex edit, ex, next, or visual
830 command, no further commands from the source of the commands shall
831 be executed.
832
833 * Otherwise, if the ex command resulted from the execution of a buf‐
834 fer or a global or v command, no further commands caused by the
835 execution of the buffer or the global or v command shall be exe‐
836 cuted.
837
838 * Otherwise, if the ex command was not terminated by a <newline>, all
839 characters up to and including the next non-<backslash>-escaped
840 <newline> shall be discarded.
841
842 Input Editing in ex
843 The following symbol is used in this and the following sections to
844 specify command actions:
845
846 word In the POSIX locale, a word consists of a maximal sequence of
847 letters, digits, and underscores, delimited at both ends by
848 characters other than letters, digits, or underscores, or by
849 the beginning or end of a line or the edit buffer.
850
851 When accepting input characters from the user, in either ex command
852 mode or ex text input mode, ex shall enable canonical mode input pro‐
853 cessing, as defined in the System Interfaces volume of POSIX.1‐2008.
854
855 If in ex text input mode:
856
857 1. If the number edit option is set, ex shall prompt for input using
858 the line number that would be assigned to the line if it is
859 entered, in the format specified for the ex number command.
860
861 2. If the autoindent edit option is set, ex shall prompt for input
862 using autoindent characters, as described by the autoindent edit
863 option. autoindent characters shall follow the line number, if
864 any.
865
866 If in ex command mode:
867
868 1. If the prompt edit option is set, input shall be prompted for using
869 a single ':' character; otherwise, there shall be no prompt.
870
871 The input characters in the following sections shall have the following
872 effects on the input line.
873
874 Scroll
875 Synopsis:
876 eof
877
878 See the description of the stty eof character in stty.
879
880 If in ex command mode:
881
882 If the eof character is the first character entered on the line,
883 the line shall be evaluated as if it contained two characters: a
884 <control>‐D and a <newline>.
885
886 Otherwise, the eof character shall have no special meaning.
887
888 If in ex text input mode:
889
890 If the cursor follows an autoindent character, the autoindent
891 characters in the line shall be modified so that a part of the
892 next text input character will be displayed on the first column
893 in the line after the previous shiftwidth edit option column
894 boundary, and the user shall be prompted again for input for the
895 same line.
896
897 Otherwise, if the cursor follows a '0', which follows an autoin‐
898 dent character, and the '0' was the previous text input charac‐
899 ter, the '0' and all autoindent characters in the line shall be
900 discarded, and the user shall be prompted again for input for
901 the same line.
902
903 Otherwise, if the cursor follows a '^', which follows an autoin‐
904 dent character, and the '^' was the previous text input charac‐
905 ter, the '^' and all autoindent characters in the line shall be
906 discarded, and the user shall be prompted again for input for
907 the same line. In addition, the autoindent level for the next
908 input line shall be derived from the same line from which the
909 autoindent level for the current input line was derived.
910
911 Otherwise, if there are no autoindent or text input characters
912 in the line, the eof character shall be discarded.
913
914 Otherwise, the eof character shall have no special meaning.
915
916 <newline>
917 Synopsis:
918 <newline>
919 <control>-J
920
921 If in ex command mode:
922
923 Cause the command line to be parsed; <control>‐J shall be mapped
924 to the <newline> for this purpose.
925
926 If in ex text input mode:
927
928 Terminate the current line. If there are no characters other
929 than autoindent characters on the line, all characters on the
930 line shall be discarded.
931
932 Prompt for text input on a new line after the current line. If
933 the autoindent edit option is set, an appropriate number of
934 autoindent characters shall be added as a prefix to the line as
935 described by the ex autoindent edit option.
936
937 <backslash>
938 Synopsis:
939 <backslash>
940
941 Allow the entry of a subsequent <newline> or <control>‐J as a literal
942 character, removing any special meaning that it may have to the editor
943 during text input mode. The <backslash> character shall be retained and
944 evaluated when the command line is parsed, or retained and included
945 when the input text becomes part of the edit buffer.
946
947 <control>‐V
948 Synopsis:
949 <control>-V
950
951 Allow the entry of any subsequent character as a literal character,
952 removing any special meaning that it may have to the editor during text
953 input mode. The <control>‐V character shall be discarded before the
954 command line is parsed or the input text becomes part of the edit buf‐
955 fer.
956
957 If the ``literal next'' functionality is performed by the underlying
958 system, it is implementation-defined whether a character other than
959 <control>‐V performs this function.
960
961 <control>‐W
962 Synopsis:
963 <control>-W
964
965 Discard the <control>‐W, and the word previous to it in the input line,
966 including any <blank> characters following the word and preceding the
967 <control>‐W. If the ``word erase'' functionality is performed by the
968 underlying system, it is implementation-defined whether a character
969 other than <control>‐W performs this function.
970
971 Command Descriptions in ex
972 The following symbols are used in this section to represent command
973 modifiers. Some of these modifiers can be omitted, in which case the
974 specified defaults shall be used.
975
976 1addr A single line address, given in any of the forms described in
977 Addressing in ex; the default shall be the current line
978 ('.'), unless otherwise specified.
979
980 If the line address is zero, it shall be an error, unless
981 otherwise specified in the following command descriptions.
982
983 If the edit buffer is empty, and the address is specified
984 with a command other than =, append, insert, open, put, read,
985 or visual, or the address is not zero, it shall be an error.
986
987 2addr Two addresses specifying an inclusive range of lines. If no
988 addresses are specified, the default for 2addr shall be the
989 current line only (".,."), unless otherwise specified in the
990 following command descriptions. If one address is specified,
991 2addr shall specify that line only, unless otherwise speci‐
992 fied in the following command descriptions.
993
994 It shall be an error if the first address is greater than the
995 second address.
996
997 If the edit buffer is empty, and the two addresses are speci‐
998 fied with a command other than the !, write, wq, or xit com‐
999 mands, or either address is not zero, it shall be an error.
1000
1001 count A positive decimal number. If count is specified, it shall be
1002 equivalent to specifying an additional address to the com‐
1003 mand, unless otherwise specified by the following command
1004 descriptions. The additional address shall be equal to the
1005 last address specified to the command (either explicitly or
1006 by default) plus count−1.
1007
1008 If this would result in an address greater than the last line
1009 of the edit buffer, it shall be corrected to equal the last
1010 line of the edit buffer.
1011
1012 flags One or more of the characters '+', '−', '#', 'p', or 'l'
1013 (ell). The flag characters can be <blank>-separated, and in
1014 any order or combination. The characters '#', 'p', and 'l'
1015 shall cause lines to be written in the format specified by
1016 the print command with the specified flags.
1017
1018 The lines to be written are as follows:
1019
1020 1. All edit buffer lines written during the execution of the
1021 ex &, ~, list, number, open, print, s, visual, and z com‐
1022 mands shall be written as specified by flags.
1023
1024 2. After the completion of an ex command with a flag as an
1025 argument, the current line shall be written as specified
1026 by flags, unless the current line was the last line writ‐
1027 ten by the command.
1028
1029 The characters '+' and '−' cause the value of the current
1030 line after the execution of the ex command to be adjusted by
1031 the offset address as described in Addressing in ex. This
1032 adjustment shall occur before the current line is written as
1033 described in 2. above.
1034
1035 The default for flags shall be none.
1036
1037 buffer One of a number of named areas for holding text. The named
1038 buffers are specified by the alphanumeric characters of the
1039 POSIX locale. There shall also be one ``unnamed'' buffer.
1040 When no buffer is specified for editor commands that use a
1041 buffer, the unnamed buffer shall be used. Commands that
1042 store text into buffers shall store the text as it was before
1043 the command took effect, and shall store text occurring ear‐
1044 lier in the file before text occurring later in the file,
1045 regardless of how the text region was specified. Commands
1046 that store text into buffers shall store the text into the
1047 unnamed buffer as well as any specified buffer.
1048
1049 In ex commands, buffer names are specified as the name by
1050 itself. In open or visual mode commands the name is preceded
1051 by a double-quote ('"') character.
1052
1053 If the specified buffer name is an uppercase character, and
1054 the buffer contents are to be modified, the buffer shall be
1055 appended to rather than being overwritten. If the buffer is
1056 not being modified, specifying the buffer name in lowercase
1057 and uppercase shall have identical results.
1058
1059 There shall also be buffers named by the numbers 1 through 9.
1060 In open and visual mode, if a region of text including char‐
1061 acters from more than a single line is being modified by the
1062 vi c or d commands, the motion character associated with the
1063 c or d commands specifies that the buffer text shall be in
1064 line mode, or the commands %, `, /, ?, (, ), N, n, {, or }
1065 are used to define a region of text for the c or d commands,
1066 the contents of buffers 1 through 8 shall be moved into the
1067 buffer named by the next numerically greater value, the con‐
1068 tents of buffer 9 shall be discarded, and the region of text
1069 shall be copied into buffer 1. This shall be in addition to
1070 copying the text into a user-specified buffer or unnamed buf‐
1071 fer, or both. Numeric buffers can be specified as a source
1072 buffer for open and visual mode commands; however, specifying
1073 a numeric buffer as the write target of an open or visual
1074 mode command shall have unspecified results.
1075
1076 The text of each buffer shall have the characteristic of
1077 being in either line or character mode. Appending text to a
1078 non-empty buffer shall set the mode to match the characteris‐
1079 tic of the text being appended. Appending text to a buffer
1080 shall cause the creation of at least one additional line in
1081 the buffer. All text stored into buffers by ex commands shall
1082 be in line mode. The ex commands that use buffers as the
1083 source of text specify individually how buffers of different
1084 modes are handled. Each open or visual mode command that uses
1085 buffers for any purpose specifies individually the mode of
1086 the text stored into the buffer and how buffers of different
1087 modes are handled.
1088
1089 file Command text used to derive a pathname. The default shall be
1090 the current pathname, as defined previously, in which case,
1091 if no current pathname has yet been established it shall be
1092 an error, except where specifically noted in the individual
1093 command descriptions that follow. If the command text con‐
1094 tains any of the characters '~', '{', '[', '*', '?', '$',
1095 '"', backquote, single-quote, and <backslash>, it shall be
1096 subjected to the process of ``shell expansions'', as
1097 described below; if more than a single pathname results and
1098 the command expects only one, it shall be an error.
1099
1100 The process of shell expansions in the editor shall be done
1101 as follows. The ex utility shall pass two arguments to the
1102 program named by the shell edit option; the first shall be
1103 −c, and the second shall be the string "echo" and the command
1104 text as a single argument. The standard output and standard
1105 error of that command shall replace the command text.
1106
1107 ! A character that can be appended to the command name to mod‐
1108 ify its operation, as detailed in the individual command
1109 descriptions. With the exception of the ex read, write, and !
1110 commands, the '!' character shall only act as a modifier if
1111 there are no <blank> characters between it and the command
1112 name.
1113
1114 remembered search direction
1115 The vi commands N and n begin searching in a forwards or
1116 backwards direction in the edit buffer based on a remembered
1117 search direction, which is initially unset, and is set by the
1118 ex global, v, s, and tag commands, and the vi / and ? com‐
1119 mands.
1120
1121 Abbreviate
1122 Synopsis:
1123 ab[breviate][lhs rhs]
1124
1125 If lhs and rhs are not specified, write the current list of abbrevia‐
1126 tions and do nothing more.
1127
1128 Implementations may restrict the set of characters accepted in lhs or
1129 rhs, except that printable characters and <blank> characters shall not
1130 be restricted. Additional restrictions shall be implementation-defined.
1131
1132 In both lhs and rhs, any character may be escaped with a <control>‐V,
1133 in which case the character shall not be used to delimit lhs from rhs,
1134 and the escaping <control>‐V shall be discarded.
1135
1136 In open and visual text input mode, if a non-word or <ESC> character
1137 that is not escaped by a <control>‐V character is entered after a word
1138 character, a check shall be made for a set of characters matching lhs,
1139 in the text input entered during this command. If it is found, the
1140 effect shall be as if rhs was entered instead of lhs.
1141
1142 The set of characters that are checked is defined as follows:
1143
1144 1. If there are no characters inserted before the word and non-word or
1145 <ESC> characters that triggered the check, the set of characters
1146 shall consist of the word character.
1147
1148 2. If the character inserted before the word and non-word or <ESC>
1149 characters that triggered the check is a word character, the set of
1150 characters shall consist of the characters inserted immediately
1151 before the triggering characters that are word characters, plus the
1152 triggering word character.
1153
1154 3. If the character inserted before the word and non-word or <ESC>
1155 characters that triggered the check is not a word character, the
1156 set of characters shall consist of the characters that were
1157 inserted before the triggering characters that are neither <blank>
1158 characters nor word characters, plus the triggering word character.
1159
1160 It is unspecified whether the lhs argument entered for the ex abbrevi‐
1161 ate and unabbreviate commands is replaced in this fashion. Regardless
1162 of whether or not the replacement occurs, the effect of the command
1163 shall be as if the replacement had not occurred.
1164
1165 Current line: Unchanged.
1166
1167 Current column: Unchanged.
1168
1169 Append
1170 Synopsis:
1171 [1addr] a[ppend][!]
1172
1173 Enter ex text input mode; the input text shall be placed after the
1174 specified line. If line zero is specified, the text shall be placed at
1175 the beginning of the edit buffer.
1176
1177 This command shall be affected by the number and autoindent edit
1178 options; following the command name with '!' shall cause the autoin‐
1179 dent edit option setting to be toggled for the duration of this command
1180 only.
1181
1182 Current line: Set to the last input line; if no lines were input, set
1183 to the specified line, or to the first line of the edit buffer if a
1184 line of zero was specified, or zero if the edit buffer is empty.
1185
1186 Current column: Set to non-<blank>.
1187
1188 Arguments
1189 Synopsis:
1190 ar[gs]
1191
1192 Write the current argument list, with the current argument-list entry,
1193 if any, between '[' and ']' characters.
1194
1195 Current line: Unchanged.
1196
1197 Current column: Unchanged.
1198
1199 Change
1200 Synopsis:
1201 [2addr] c[hange][!][count]
1202
1203 Enter ex text input mode; the input text shall replace the specified
1204 lines. The specified lines shall be copied into the unnamed buffer,
1205 which shall become a line mode buffer.
1206
1207 This command shall be affected by the number and autoindent edit
1208 options; following the command name with '!' shall cause the autoin‐
1209 dent edit option setting to be toggled for the duration of this command
1210 only.
1211
1212 Current line: Set to the last input line; if no lines were input, set
1213 to the line before the first address, or to the first line of the edit
1214 buffer if there are no lines preceding the first address, or to zero if
1215 the edit buffer is empty.
1216
1217 Current column: Set to non-<blank>.
1218
1219 Change Directory
1220 Synopsis:
1221 chd[ir][!][directory]
1222 cd[!][directory]
1223
1224 Change the current working directory to directory.
1225
1226 If no directory argument is specified, and the HOME environment vari‐
1227 able is set to a non-null and non-empty value, directory shall default
1228 to the value named in the HOME environment variable. If the HOME envi‐
1229 ronment variable is empty or is undefined, the default value of direc‐
1230 tory is implementation-defined.
1231
1232 If no '!' is appended to the command name, and the edit buffer has
1233 been modified since the last complete write, and the current pathname
1234 does not begin with a '/', it shall be an error.
1235
1236 Current line: Unchanged.
1237
1238 Current column: Unchanged.
1239
1240 Copy
1241 Synopsis:
1242 [2addr] co[py] 1addr [flags]
1243 [2addr] t 1addr [flags]
1244
1245 Copy the specified lines after the specified destination line; line
1246 zero specifies that the lines shall be placed at the beginning of the
1247 edit buffer.
1248
1249 Current line: Set to the last line copied.
1250
1251 Current column: Set to non-<blank>.
1252
1253 Delete
1254 Synopsis:
1255 [2addr] d[elete][buffer][count][flags]
1256
1257 Delete the specified lines into a buffer (defaulting to the unnamed
1258 buffer), which shall become a line-mode buffer.
1259
1260 Flags can immediately follow the command name; see Command Line Parsing
1261 in ex.
1262
1263 Current line: Set to the line following the deleted lines, or to the
1264 last line in the edit buffer if that line is past the end of the edit
1265 buffer, or to zero if the edit buffer is empty.
1266
1267 Current column: Set to non-<blank>.
1268
1269 Edit
1270 Synopsis:
1271 e[dit][!][+command][file]
1272 ex[!][+command][file]
1273
1274 If no '!' is appended to the command name, and the edit buffer has
1275 been modified since the last complete write, it shall be an error.
1276
1277 If file is specified, replace the current contents of the edit buffer
1278 with the current contents of file, and set the current pathname to
1279 file. If file is not specified, replace the current contents of the
1280 edit buffer with the current contents of the file named by the current
1281 pathname. If for any reason the current contents of the file cannot be
1282 accessed, the edit buffer shall be empty.
1283
1284 The +command option shall be <blank>-delimited; <blank> characters
1285 within the +command can be escaped by preceding them with a <backslash>
1286 character. The +command shall be interpreted as an ex command immedi‐
1287 ately after the contents of the edit buffer have been replaced and the
1288 current line and column have been set.
1289
1290 If the edit buffer is empty:
1291
1292 Current line: Set to 0.
1293
1294 Current column: Set to 1.
1295
1296 Otherwise, if executed while in ex command mode or if the +command
1297 argument is specified:
1298
1299 Current line: Set to the last line of the edit buffer.
1300
1301 Current column: Set to non-<blank>.
1302
1303 Otherwise, if file is omitted or results in the current pathname:
1304
1305 Current line: Set to the first line of the edit buffer.
1306
1307 Current column: Set to non-<blank>.
1308
1309 Otherwise, if file is the same as the last file edited, the line and
1310 column shall be set as follows; if the file was previously edited, the
1311 line and column may be set as follows:
1312
1313 Current line: Set to the last value held when that file was last
1314 edited. If this value is not a valid line in the new edit buffer, set
1315 to the first line of the edit buffer.
1316
1317 Current column: If the current line was set to the last value held when
1318 the file was last edited, set to the last value held when the file was
1319 last edited. Otherwise, or if the last value is not a valid column in
1320 the new edit buffer, set to non-<blank>.
1321
1322 Otherwise:
1323
1324 Current line: Set to the first line of the edit buffer.
1325
1326 Current column: Set to non-<blank>.
1327
1328 File
1329 Synopsis:
1330 f[ile][file]
1331
1332 If a file argument is specified, the alternate pathname shall be set to
1333 the current pathname, and the current pathname shall be set to file.
1334
1335 Write an informational message. If the file has a current pathname, it
1336 shall be included in this message; otherwise, the message shall indi‐
1337 cate that there is no current pathname. If the edit buffer contains
1338 lines, the current line number and the number of lines in the edit buf‐
1339 fer shall be included in this message; otherwise, the message shall
1340 indicate that the edit buffer is empty. If the edit buffer has been
1341 modified since the last complete write, this fact shall be included in
1342 this message. If the readonly edit option is set, this fact shall be
1343 included in this message. The message may contain other unspecified
1344 information.
1345
1346 Current line: Unchanged.
1347
1348 Current column: Unchanged.
1349
1350 Global
1351 Synopsis:
1352 [2addr] g[lobal] /pattern/ [commands]
1353 [2addr] v /pattern/ [commands]
1354
1355 The optional '!' character after the global command shall be the same
1356 as executing the v command.
1357
1358 If pattern is empty (for example, "//") or not specified, the last reg‐
1359 ular expression used in the editor command shall be used as the pat‐
1360 tern. The pattern can be delimited by <slash> characters (shown in the
1361 Synopsis), as well as any non-alphanumeric or non-<blank> other than
1362 <backslash>, <vertical-line>, <newline>, or double-quote.
1363
1364 If no lines are specified, the lines shall default to the entire file.
1365
1366 The global and v commands are logically two-pass operations. First,
1367 mark the lines within the specified lines for which the line excluding
1368 the terminating <newline> matches (global) or does not match (v or
1369 global!) the specified pattern. Second, execute the ex commands given
1370 by commands, with the current line ('.') set to each marked line. If
1371 an error occurs during this process, or the contents of the edit buffer
1372 are replaced (for example, by the ex :edit command) an error message
1373 shall be written and no more commands resulting from the execution of
1374 this command shall be processed.
1375
1376 Multiple ex commands can be specified by entering multiple commands on
1377 a single line using a <vertical-line> to delimit them, or one per line,
1378 by escaping each <newline> with a <backslash>.
1379
1380 If no commands are specified:
1381
1382 1. If in ex command mode, it shall be as if the print command were
1383 specified.
1384
1385 2. Otherwise, no command shall be executed.
1386
1387 For the append, change, and insert commands, the input text shall be
1388 included as part of the command, and the terminating <period> can be
1389 omitted if the command ends the list of commands. The open and visual
1390 commands can be specified as one of the commands, in which case each
1391 marked line shall cause the editor to enter open or visual mode. If
1392 open or visual mode is exited using the vi Q command, the current line
1393 shall be set to the next marked line, and open or visual mode reen‐
1394 tered, until the list of marked lines is exhausted.
1395
1396 The global, v, and undo commands cannot be used in commands. Marked
1397 lines may be deleted by commands executed for lines occurring earlier
1398 in the file than the marked lines. In this case, no commands shall be
1399 executed for the deleted lines.
1400
1401 If the remembered search direction is not set, the global and v com‐
1402 mands shall set it to forward.
1403
1404 The autoprint and autoindent edit options shall be inhibited for the
1405 duration of the g or v command.
1406
1407 Current line: If no commands executed, set to the last marked line.
1408 Otherwise, as specified for the executed ex commands.
1409
1410 Current column: If no commands are executed, set to non-<blank>; other‐
1411 wise, as specified for the individual ex commands.
1412
1413 Insert
1414 Synopsis:
1415 [1addr] i[nsert][!]
1416
1417 Enter ex text input mode; the input text shall be placed before the
1418 specified line. If the line is zero or 1, the text shall be placed at
1419 the beginning of the edit buffer.
1420
1421 This command shall be affected by the number and autoindent edit
1422 options; following the command name with '!' shall cause the autoin‐
1423 dent edit option setting to be toggled for the duration of this command
1424 only.
1425
1426 Current line: Set to the last input line; if no lines were input, set
1427 to the line before the specified line, or to the first line of the edit
1428 buffer if there are no lines preceding the specified line, or zero if
1429 the edit buffer is empty.
1430
1431 Current column: Set to non-<blank>.
1432
1433 Join
1434 Synopsis:
1435 [2addr] j[oin][!][count][flags]
1436
1437 If count is specified:
1438
1439 If no address was specified, the join command shall behave as if
1440 2addr were the current line and the current line plus count (.,.
1441 + count).
1442
1443 If one address was specified, the join command shall behave as
1444 if 2addr were the specified address and the specified address
1445 plus count (addr,addr + count).
1446
1447 If two addresses were specified, the join command shall behave
1448 as if an additional address, equal to the last address plus
1449 count −1 (addr1,addr2,addr2 + count −1), was specified.
1450
1451 If this would result in a second address greater than the last
1452 line of the edit buffer, it shall be corrected to be equal to
1453 the last line of the edit buffer.
1454
1455 If no count is specified:
1456
1457 If no address was specified, the join command shall behave as if
1458 2addr were the current line and the next line (.,. +1).
1459
1460 If one address was specified, the join command shall behave as
1461 if 2addr were the specified address and the next line (addr,addr
1462 +1).
1463
1464 Join the text from the specified lines together into a single line,
1465 which shall replace the specified lines.
1466
1467 If a '!' character is appended to the command name, the join shall be
1468 without modification of any line, independent of the current locale.
1469
1470 Otherwise, in the POSIX locale, set the current line to the first of
1471 the specified lines, and then, for each subsequent line, proceed as
1472 follows:
1473
1474 1. Discard leading <space> characters from the line to be joined.
1475
1476 2. If the line to be joined is now empty, delete it, and skip steps 3
1477 through 5.
1478
1479 3. If the current line ends in a <blank>, or the first character of
1480 the line to be joined is a ')' character, join the lines without
1481 further modification.
1482
1483 4. If the last character of the current line is a '.', join the lines
1484 with two <space> characters between them.
1485
1486 5. Otherwise, join the lines with a single <space> between them.
1487
1488 Current line: Set to the first line specified.
1489
1490 Current column: Set to non-<blank>.
1491
1492 List
1493 Synopsis:
1494 [2addr] l[ist][count][flags]
1495
1496 This command shall be equivalent to the ex command:
1497
1498 [2addr] p[rint][count] l[flags]
1499
1500 See Print.
1501
1502 Map
1503 Synopsis:
1504 map[!][lhs rhs]
1505
1506 If lhs and rhs are not specified:
1507
1508 1. If '!' is specified, write the current list of text input mode
1509 maps.
1510
1511 2. Otherwise, write the current list of command mode maps.
1512
1513 3. Do nothing more.
1514
1515 Implementations may restrict the set of characters accepted in lhs or
1516 rhs, except that printable characters and <blank> characters shall not
1517 be restricted. Additional restrictions shall be implementation-defined.
1518 In both lhs and rhs, any character can be escaped with a <control>‐V,
1519 in which case the character shall not be used to delimit lhs from rhs,
1520 and the escaping <control>‐V shall be discarded.
1521
1522 If the character '!' is appended to the map command name, the mapping
1523 shall be effective during open or visual text input mode rather than
1524 open or visual command mode. This allows lhs to have two different map
1525 definitions at the same time: one for command mode and one for text
1526 input mode.
1527
1528 For command mode mappings:
1529
1530 When the lhs is entered as any part of a vi command in open or
1531 visual mode (but not as part of the arguments to the command),
1532 the action shall be as if the corresponding rhs had been
1533 entered.
1534
1535 If any character in the command, other than the first, is
1536 escaped using a <control>‐V character, that character shall not
1537 be part of a match to an lhs.
1538
1539 It is unspecified whether implementations shall support map com‐
1540 mands where the lhs is more than a single character in length,
1541 where the first character of the lhs is printable.
1542
1543 If lhs contains more than one character and the first character
1544 is '#', followed by a sequence of digits corresponding to a num‐
1545 bered function key, then when this function key is typed it
1546 shall be mapped to rhs. Characters other than digits following
1547 a '#' character also represent the function key named by the
1548 characters in the lhs following the '#' and may be mapped to
1549 rhs. It is unspecified how function keys are named or what
1550 function keys are supported.
1551
1552 For text input mode mappings:
1553
1554 When the lhs is entered as any part of text entered in open or
1555 visual text input modes, the action shall be as if the corre‐
1556 sponding rhs had been entered.
1557
1558 If any character in the input text is escaped using a <con‐
1559 trol>‐V character, that character shall not be part of a match
1560 to an lhs.
1561
1562 It is unspecified whether the lhs text entered for subsequent
1563 map or unmap commands is replaced with the rhs text for the pur‐
1564 poses of the screen display; regardless of whether or not the
1565 display appears as if the corresponding rhs text was entered,
1566 the effect of the command shall be as if the lhs text was
1567 entered.
1568
1569 If only part of the lhs is entered, it is unspecified how long the edi‐
1570 tor will wait for additional, possibly matching characters before
1571 treating the already entered characters as not matching the lhs.
1572
1573 The rhs characters shall themselves be subject to remapping, unless
1574 otherwise specified by the remap edit option, except that if the char‐
1575 acters in lhs occur as prefix characters in rhs, those characters shall
1576 not be remapped.
1577
1578 On block-mode terminals, the mapping need not occur immediately (for
1579 example, it may occur after the terminal transmits a group of charac‐
1580 ters to the system), but it shall achieve the same results as if it
1581 occurred immediately.
1582
1583 Current line: Unchanged.
1584
1585 Current column: Unchanged.
1586
1587 Mark
1588 Synopsis:
1589 [1addr] ma[rk] character
1590 [1addr] k character
1591
1592 Implementations shall support character values of a single lowercase
1593 letter of the POSIX locale and the backquote and single-quote charac‐
1594 ters; support of other characters is implementation-defined.
1595
1596 If executing the vi m command, set the specified mark to the current
1597 line and 1-based numbered character referenced by the current column,
1598 if any; otherwise, column position 1.
1599
1600 Otherwise, set the specified mark to the specified line and 1-based
1601 numbered first non-<blank> non-<newline> in the line, if any; other‐
1602 wise, the last non-<newline> in the line, if any; otherwise, column
1603 position 1.
1604
1605 The mark shall remain associated with the line until the mark is reset
1606 or the line is deleted. If a deleted line is restored by a subsequent
1607 undo command, any marks previously associated with the line, which have
1608 not been reset, shall be restored as well. Any use of a mark not asso‐
1609 ciated with a current line in the edit buffer shall be an error.
1610
1611 The marks ` and ' shall be set as described previously, immediately
1612 before the following events occur in the editor:
1613
1614 1. The use of '$' as an ex address
1615
1616 2. The use of a positive decimal number as an ex address
1617
1618 3. The use of a search command as an ex address
1619
1620 4. The use of a mark reference as an ex address
1621
1622 5. The use of the following open and visual mode commands: <con‐
1623 trol>‐], %, (, ), [, ], {, }
1624
1625 6. The use of the following open and visual mode commands: ', G, H, L,
1626 M, z if the current line will change as a result of the command
1627
1628 7. The use of the open and visual mode commands: /, ?, N, `, n if the
1629 current line or column will change as a result of the command
1630
1631 8. The use of the ex mode commands: z, undo, global, v
1632
1633 For rules 1., 2., 3., and 4., the ` and ' marks shall not be set if the
1634 ex command is parsed as specified by rule 6.a. in Command Line Parsing
1635 in ex.
1636
1637 For rules 5., 6., and 7., the ` and ' marks shall not be set if the
1638 commands are used as motion commands in open and visual mode.
1639
1640 For rules 1., 2., 3., 4., 5., 6., 7., and 8., the ` and ' marks shall
1641 not be set if the command fails.
1642
1643 The ` and ' marks shall be set as described previously, each time the
1644 contents of the edit buffer are replaced (including the editing of the
1645 initial buffer), if in open or visual mode, or if in ex mode and the
1646 edit buffer is not empty, before any commands or movements (including
1647 commands or movements specified by the −c or −t options or the +command
1648 argument) are executed on the edit buffer. If in open or visual mode,
1649 the marks shall be set as if executing the vi m command; otherwise, as
1650 if executing the ex mark command.
1651
1652 When changing from ex mode to open or visual mode, if the ` and ' marks
1653 are not already set, the ` and ' marks shall be set as described previ‐
1654 ously.
1655
1656 Current line: Unchanged.
1657
1658 Current column: Unchanged.
1659
1660 Move
1661 Synopsis:
1662 [2addr] m[ove] 1addr [flags]
1663
1664 Move the specified lines after the specified destination line. A desti‐
1665 nation of line zero specifies that the lines shall be placed at the
1666 beginning of the edit buffer. It shall be an error if the destination
1667 line is within the range of lines to be moved.
1668
1669 Current line: Set to the last of the moved lines.
1670
1671 Current column: Set to non-<blank>.
1672
1673 Next
1674 Synopsis:
1675 n[ext][!][+command][file ...]
1676
1677 If no '!' is appended to the command name, and the edit buffer has
1678 been modified since the last complete write, it shall be an error,
1679 unless the file is successfully written as specified by the autowrite
1680 option.
1681
1682 If one or more files is specified:
1683
1684 1. Set the argument list to the specified filenames.
1685
1686 2. Set the current argument list reference to be the first entry in
1687 the argument list.
1688
1689 3. Set the current pathname to the first filename specified.
1690
1691 Otherwise:
1692
1693 1. It shall be an error if there are no more filenames in the argument
1694 list after the filename currently referenced.
1695
1696 2. Set the current pathname and the current argument list reference to
1697 the filename after the filename currently referenced in the argu‐
1698 ment list.
1699
1700 Replace the contents of the edit buffer with the contents of the file
1701 named by the current pathname. If for any reason the contents of the
1702 file cannot be accessed, the edit buffer shall be empty.
1703
1704 This command shall be affected by the autowrite and writeany edit
1705 options.
1706
1707 The +command option shall be <blank>-delimited; <blank> characters can
1708 be escaped by preceding them with a <backslash> character. The +command
1709 shall be interpreted as an ex command immediately after the contents of
1710 the edit buffer have been replaced and the current line and column have
1711 been set.
1712
1713 Current line: Set as described for the edit command.
1714
1715 Current column: Set as described for the edit command.
1716
1717 Number
1718 Synopsis:
1719 [2addr] nu[mber][count][flags]
1720 [2addr] #[count][flags]
1721
1722 These commands shall be equivalent to the ex command:
1723
1724 [2addr] p[rint][count] #[flags]
1725
1726 See Print.
1727
1728 Open
1729 Synopsis:
1730 [1addr] o[pen] /pattern/ [flags]
1731
1732 This command need not be supported on block-mode terminals or terminals
1733 with insufficient capabilities. If standard input, standard output, or
1734 standard error are not terminal devices, the results are unspecified.
1735
1736 Enter open mode.
1737
1738 The trailing delimiter can be omitted from pattern at the end of the
1739 command line. If pattern is empty (for example, "//") or not specified,
1740 the last regular expression used in the editor shall be used as the
1741 pattern. The pattern can be delimited by <slash> characters (shown in
1742 the Synopsis), as well as any alphanumeric, or non-<blank> other than
1743 <backslash>, <vertical-line>, <newline>, or double-quote.
1744
1745 Current line: Set to the specified line.
1746
1747 Current column: Set to non-<blank>.
1748
1749 Preserve
1750 Synopsis:
1751 pre[serve]
1752
1753 Save the edit buffer in a form that can later be recovered by using the
1754 −r option or by using the ex recover command. After the file has been
1755 preserved, a mail message shall be sent to the user. This message shall
1756 be readable by invoking the mailx utility. The message shall contain
1757 the name of the file, the time of preservation, and an ex command that
1758 could be used to recover the file. Additional information may be
1759 included in the mail message.
1760
1761 Current line: Unchanged.
1762
1763 Current column: Unchanged.
1764
1765 Print
1766 Synopsis:
1767 [2addr] p[rint][count][flags]
1768
1769 Write the addressed lines. The behavior is unspecified if the number of
1770 columns on the display is less than the number of columns required to
1771 write any single character in the lines being written.
1772
1773 Non-printable characters, except for the <tab>, shall be written as
1774 implementation-defined multi-character sequences.
1775
1776 If the # flag is specified or the number edit option is set, each line
1777 shall be preceded by its line number in the following format:
1778
1779 "%6d ", <line number>
1780
1781 If the l flag is specified or the list edit option is set:
1782
1783 1. The characters listed in the Base Definitions volume of
1784 POSIX.1‐2008, Table 5-1, Escape Sequences and Associated Actions
1785 shall be written as the corresponding escape sequence.
1786
1787 2. Non-printable characters not in the Base Definitions volume of
1788 POSIX.1‐2008, Table 5-1, Escape Sequences and Associated Actions
1789 shall be written as one three-digit octal number (with a preceding
1790 <backslash>) for each byte in the character (most significant byte
1791 first).
1792
1793 3. The end of each line shall be marked with a '$', and literal '$'
1794 characters within the line shall be written with a preceding <back‐
1795 slash>.
1796
1797 Long lines shall be folded; the length at which folding occurs is
1798 unspecified, but should be appropriate for the output terminal, consid‐
1799 ering the number of columns of the terminal.
1800
1801 If a line is folded, and the l flag is not specified and the list edit
1802 option is not set, it is unspecified whether a multi-column character
1803 at the folding position is separated; it shall not be discarded.
1804
1805 Current line: Set to the last written line.
1806
1807 Current column: Unchanged if the current line is unchanged; otherwise,
1808 set to non-<blank>.
1809
1810 Put
1811 Synopsis:
1812 [1addr] pu[t][buffer]
1813
1814 Append text from the specified buffer (by default, the unnamed buffer)
1815 to the specified line; line zero specifies that the text shall be
1816 placed at the beginning of the edit buffer. Each portion of a line in
1817 the buffer shall become a new line in the edit buffer, regardless of
1818 the mode of the buffer.
1819
1820 Current line: Set to the last line entered into the edit buffer.
1821
1822 Current column: Set to non-<blank>.
1823
1824 Quit
1825 Synopsis:
1826 q[uit][!]
1827
1828 If no '!' is appended to the command name:
1829
1830 1. If the edit buffer has been modified since the last complete write,
1831 it shall be an error.
1832
1833 2. If there are filenames in the argument list after the filename cur‐
1834 rently referenced, and the last command was not a quit, wq, xit, or
1835 ZZ (see Exit) command, it shall be an error.
1836
1837 Otherwise, terminate the editing session.
1838
1839 Read
1840 Synopsis:
1841 [1addr] r[ead][!][file]
1842
1843 If '!' is not the first non-<blank> to follow the command name, a copy
1844 of the specified file shall be appended into the edit buffer after the
1845 specified line; line zero specifies that the copy shall be placed at
1846 the beginning of the edit buffer. The number of lines and bytes read
1847 shall be written. If no file is named, the current pathname shall be
1848 the default. If there is no current pathname, then file shall become
1849 the current pathname. If there is no current pathname or file operand,
1850 it shall be an error. Specifying a file that is not of type regular
1851 shall have unspecified results.
1852
1853 Otherwise, if file is preceded by '!', the rest of the line after the
1854 '!' shall have '%', '#', and '!' characters expanded as described in
1855 Command Line Parsing in ex.
1856
1857 The ex utility shall then pass two arguments to the program named by
1858 the shell edit option; the first shall be −c and the second shall be
1859 the expanded arguments to the read command as a single argument. The
1860 standard input of the program shall be set to the standard input of the
1861 ex program when it was invoked. The standard error and standard output
1862 of the program shall be appended into the edit buffer after the speci‐
1863 fied line.
1864
1865 Each line in the copied file or program output (as delimited by <new‐
1866 line> characters or the end of the file or output if it is not immedi‐
1867 ately preceded by a <newline>), shall be a separate line in the edit
1868 buffer. Any occurrences of <carriage-return> and <newline> pairs in the
1869 output shall be treated as single <newline> characters.
1870
1871 The special meaning of the '!' following the read command can be over‐
1872 ridden by escaping it with a <backslash> character.
1873
1874 Current line: If no lines are added to the edit buffer, unchanged. Oth‐
1875 erwise, if in open or visual mode, set to the first line entered into
1876 the edit buffer. Otherwise, set to the last line entered into the edit
1877 buffer.
1878
1879 Current column: Set to non-<blank>.
1880
1881 Recover
1882 Synopsis:
1883 rec[over][!] file
1884
1885 If no '!' is appended to the command name, and the edit buffer has
1886 been modified since the last complete write, it shall be an error.
1887
1888 If no file operand is specified, then the current pathname shall be
1889 used. If there is no current pathname or file operand, it shall be an
1890 error.
1891
1892 If no recovery information has previously been saved about file, the
1893 recover command shall behave identically to the edit command, and an
1894 informational message to this effect shall be written.
1895
1896 Otherwise, set the current pathname to file, and replace the current
1897 contents of the edit buffer with the recovered contents of file. If
1898 there are multiple instances of the file to be recovered, the one most
1899 recently saved shall be recovered, and an informational message that
1900 there are previous versions of the file that can be recovered shall be
1901 written. The editor shall behave as if the contents of the edit buffer
1902 have already been modified.
1903
1904 Current file: Set as described for the edit command.
1905
1906 Current column: Set as described for the edit command.
1907
1908 Rewind
1909 Synopsis:
1910 rew[ind][!]
1911
1912 If no '!' is appended to the command name, and the edit buffer has
1913 been modified since the last complete write, it shall be an error,
1914 unless the file is successfully written as specified by the autowrite
1915 option.
1916
1917 If the argument list is empty, it shall be an error.
1918
1919 The current argument list reference and the current pathname shall be
1920 set to the first filename in the argument list.
1921
1922 Replace the contents of the edit buffer with the contents of the file
1923 named by the current pathname. If for any reason the contents of the
1924 file cannot be accessed, the edit buffer shall be empty.
1925
1926 This command shall be affected by the autowrite and writeany edit
1927 options.
1928
1929 Current line: Set as described for the edit command.
1930
1931 Current column: Set as described for the edit command.
1932
1933 Set
1934 Synopsis:
1935 se[t][option[=[value]] ...][nooption ...][option? ...][all]
1936
1937 When no arguments are specified, write the value of the term edit
1938 option and those options whose values have been changed from the
1939 default settings; when the argument all is specified, write all of the
1940 option values.
1941
1942 Giving an option name followed by the character '?' shall cause the
1943 current value of that option to be written. The '?' can be separated
1944 from the option name by zero or more <blank> characters. The '?' shall
1945 be necessary only for Boolean valued options. Boolean options can be
1946 given values by the form set option to turn them on or set nooption to
1947 turn them off; string and numeric options can be assigned by the form
1948 set option=value. Any <blank> characters in strings can be included as
1949 is by preceding each <blank> with an escaping <backslash>. More than
1950 one option can be set or listed by a single set command by specifying
1951 multiple arguments, each separated from the next by one or more <blank>
1952 characters.
1953
1954 See Edit Options in ex for details about specific options.
1955
1956 Current line: Unchanged.
1957
1958 Current column: Unchanged.
1959
1960 Shell
1961 Synopsis:
1962 sh[ell]
1963
1964 Invoke the program named in the shell edit option with the single argu‐
1965 ment −i (interactive mode). Editing shall be resumed when the program
1966 exits.
1967
1968 Current line: Unchanged.
1969
1970 Current column: Unchanged.
1971
1972 Source
1973 Synopsis:
1974 so[urce] file
1975
1976 Read and execute ex commands from file. Lines in the file that are
1977 blank lines shall be ignored.
1978
1979 Current line: As specified for the individual ex commands.
1980
1981 Current column: As specified for the individual ex commands.
1982
1983 Substitute
1984 Synopsis:
1985 [2addr] s[ubstitute][/pattern/repl/[options][count][flags]]
1986 [2addr] &[options][count][flags]]
1987 [2addr] ~[options][count][flags]]
1988
1989 Replace the first instance of the pattern pattern by the string repl on
1990 each specified line. (See Regular Expressions in ex and Replacement
1991 Strings in ex.) Any non-alphabetic, non-<blank> delimiter other than
1992 <backslash>, '|', <newline>, or double-quote can be used instead of
1993 '/'. <backslash> characters can be used to escape delimiters, <back‐
1994 slash> characters, and other special characters.
1995
1996 The trailing delimiter can be omitted from pattern or from repl at the
1997 end of the command line. If both pattern and repl are not specified or
1998 are empty (for example, "//"), the last s command shall be repeated. If
1999 only pattern is not specified or is empty, the last regular expression
2000 used in the editor shall be used as the pattern. If only repl is not
2001 specified or is empty, the pattern shall be replaced by nothing. If
2002 the entire replacement pattern is '%', the last replacement pattern to
2003 an s command shall be used.
2004
2005 Entering a <carriage-return> in repl (which requires an escaping <back‐
2006 slash> in ex mode and an escaping <control>‐V in open or vi mode) shall
2007 split the line at that point, creating a new line in the edit buffer.
2008 The <carriage-return> shall be discarded.
2009
2010 If options includes the letter 'g' (global), all non-overlapping
2011 instances of the pattern in the line shall be replaced.
2012
2013 If options includes the letter 'c' (confirm), then before each substi‐
2014 tution the line shall be written; the written line shall reflect all
2015 previous substitutions. On the following line, <space> characters shall
2016 be written beneath the characters from the line that are before the
2017 pattern to be replaced, and '^' characters written beneath the charac‐
2018 ters included in the pattern to be replaced. The ex utility shall then
2019 wait for a response from the user. An affirmative response shall cause
2020 the substitution to be done, while any other input shall not make the
2021 substitution. An affirmative response shall consist of a line with the
2022 affirmative response (as defined by the current locale) at the begin‐
2023 ning of the line. This line shall be subject to editing in the same way
2024 as the ex command line.
2025
2026 If interrupted (see the ASYNCHRONOUS EVENTS section), any modifications
2027 confirmed by the user shall be preserved in the edit buffer after the
2028 interrupt.
2029
2030 If the remembered search direction is not set, the s command shall set
2031 it to forward.
2032
2033 In the second Synopsis, the & command shall repeat the previous substi‐
2034 tution, as if the & command were replaced by:
2035
2036 s/pattern/repl/
2037
2038 where pattern and repl are as specified in the previous s, &, or ~ com‐
2039 mand.
2040
2041 In the third Synopsis, the ~ command shall repeat the previous substi‐
2042 tution, as if the '~' were replaced by:
2043
2044 s/pattern/repl/
2045
2046 where pattern shall be the last regular expression specified to the
2047 editor, and repl shall be from the previous substitution (including &
2048 and ~) command.
2049
2050 These commands shall be affected by the LC_MESSAGES environment vari‐
2051 able.
2052
2053 Current line: Set to the last line in which a substitution occurred,
2054 or, unchanged if no substitution occurred.
2055
2056 Current column: Set to non-<blank>.
2057
2058 Suspend
2059 Synopsis:
2060 su[spend][!]
2061 st[op][!]
2062
2063 Allow control to return to the invoking process; ex shall suspend
2064 itself as if it had received the SIGTSTP signal. The suspension shall
2065 occur only if job control is enabled in the invoking shell (see the
2066 description of set −m).
2067
2068 These commands shall be affected by the autowrite and writeany edit
2069 options.
2070
2071 The current susp character (see stty) shall be equivalent to the sus‐
2072 pend command.
2073
2074 Tag
2075 Synopsis:
2076 ta[g][!] tagstring
2077
2078 The results are unspecified if the format of a tags file is not as
2079 specified by the ctags utility (see ctags) description.
2080
2081 The tag command shall search for tagstring in the tag files referred to
2082 by the tag edit option, in the order they are specified, until a refer‐
2083 ence to tagstring is found. Files shall be searched from beginning to
2084 end. If no reference is found, it shall be an error and an error mes‐
2085 sage to this effect shall be written. If the reference is not found, or
2086 if an error occurs while processing a file referred to in the tag edit
2087 option, it shall be an error, and an error message shall be written at
2088 the first occurrence of such an error.
2089
2090 Otherwise, if the tags file contained a pattern, the pattern shall be
2091 treated as a regular expression used in the editor; for example, for
2092 the purposes of the s command.
2093
2094 If the tagstring is in a file with a different name than the current
2095 pathname, set the current pathname to the name of that file, and
2096 replace the contents of the edit buffer with the contents of that file.
2097 In this case, if no '!' is appended to the command name, and the edit
2098 buffer has been modified since the last complete write, it shall be an
2099 error, unless the file is successfully written as specified by the
2100 autowrite option.
2101
2102 This command shall be affected by the autowrite, tag, taglength, and
2103 writeany edit options.
2104
2105 Current line: If the tags file contained a line number, set to that
2106 line number. If the line number is larger than the last line in the
2107 edit buffer, an error message shall be written and the current line
2108 shall be set as specified for the edit command.
2109
2110 If the tags file contained a pattern, set to the first occurrence of
2111 the pattern in the file. If no matching pattern is found, an error mes‐
2112 sage shall be written and the current line shall be set as specified
2113 for the edit command.
2114
2115 Current column: If the tags file contained a line-number reference and
2116 that line-number was not larger than the last line in the edit buffer,
2117 or if the tags file contained a pattern and that pattern was found, set
2118 to non-<blank>. Otherwise, set as specified for the edit command.
2119
2120 Unabbreviate
2121 Synopsis:
2122 una[bbrev] lhs
2123
2124 If lhs is not an entry in the current list of abbreviations (see Abbre‐
2125 viate), it shall be an error. Otherwise, delete lhs from the list of
2126 abbreviations.
2127
2128 Current line: Unchanged.
2129
2130 Current column: Unchanged.
2131
2132 Undo
2133 Synopsis:
2134 u[ndo]
2135
2136 Reverse the changes made by the last command that modified the contents
2137 of the edit buffer, including undo. For this purpose, the global, v,
2138 open, and visual commands, and commands resulting from buffer execu‐
2139 tions and mapped character expansions, are considered single commands.
2140
2141 If no action that can be undone preceded the undo command, it shall be
2142 an error.
2143
2144 If the undo command restores lines that were marked, the mark shall
2145 also be restored unless it was reset subsequent to the deletion of the
2146 lines.
2147
2148 Current line:
2149
2150 1. If lines are added or changed in the file, set to the first line
2151 added or changed.
2152
2153 2. Set to the line before the first line deleted, if it exists.
2154
2155 3. Set to 1 if the edit buffer is not empty.
2156
2157 4. Set to zero.
2158
2159 Current column: Set to non-<blank>.
2160
2161 Unmap
2162 Synopsis:
2163 unm[ap][!] lhs
2164
2165 If '!' is appended to the command name, and if lhs is not an entry in
2166 the list of text input mode map definitions, it shall be an error. Oth‐
2167 erwise, delete lhs from the list of text input mode map definitions.
2168
2169 If no '!' is appended to the command name, and if lhs is not an entry
2170 in the list of command mode map definitions, it shall be an error. Oth‐
2171 erwise, delete lhs from the list of command mode map definitions.
2172
2173 Current line: Unchanged.
2174
2175 Current column: Unchanged.
2176
2177 Version
2178 Synopsis:
2179 ve[rsion]
2180
2181 Write a message containing version information for the editor. The for‐
2182 mat of the message is unspecified.
2183
2184 Current line: Unchanged.
2185
2186 Current column: Unchanged.
2187
2188 Visual
2189 Synopsis:
2190 [1addr] vi[sual][type][count][flags]
2191
2192 If ex is currently in open or visual mode, the Synopsis and behavior of
2193 the visual command shall be the same as the edit command, as specified
2194 by Edit.
2195
2196 Otherwise, this command need not be supported on block-mode terminals
2197 or terminals with insufficient capabilities. If standard input, stan‐
2198 dard output, or standard error are not terminal devices, the results
2199 are unspecified.
2200
2201 If count is specified, the value of the window edit option shall be set
2202 to count (as described in window). If the '^' type character was also
2203 specified, the window edit option shall be set before being used by the
2204 type character.
2205
2206 Enter visual mode. If type is not specified, it shall be as if a type
2207 of '+' was specified. The type shall cause the following effects:
2208
2209 + Place the beginning of the specified line at the top of the dis‐
2210 play.
2211
2212 - Place the end of the specified line at the bottom of the display.
2213
2214 . Place the beginning of the specified line in the middle of the
2215 display.
2216
2217 ^ If the specified line is less than or equal to the value of the
2218 window edit option, set the line to 1; otherwise, decrement the
2219 line by the value of the window edit option minus 1. Place the
2220 beginning of this line as close to the bottom of the displayed
2221 lines as possible, while still displaying the value of the window
2222 edit option number of lines.
2223
2224 Current line: Set to the specified line.
2225
2226 Current column: Set to non-<blank>.
2227
2228 Write
2229 Synopsis:
2230 [2addr] w[rite][!][>>][file]
2231 [2addr] w[rite][!][file]
2232 [2addr] wq[!][>>][file]
2233
2234 If no lines are specified, the lines shall default to the entire file.
2235
2236 The command wq shall be equivalent to a write command followed by a
2237 quit command; wq! shall be equivalent to write! followed by quit. In
2238 both cases, if the write command fails, the quit shall not be
2239 attempted.
2240
2241 If the command name is not followed by one or more <blank> characters,
2242 or file is not preceded by a '!' character, the write shall be to a
2243 file.
2244
2245 1. If the >> argument is specified, and the file already exists, the
2246 lines shall be appended to the file instead of replacing its con‐
2247 tents. If the >> argument is specified, and the file does not
2248 already exist, it is unspecified whether the write shall proceed as
2249 if the >> argument had not been specified or if the write shall
2250 fail.
2251
2252 2. If the readonly edit option is set (see readonly), the write shall
2253 fail.
2254
2255 3. If file is specified, and is not the current pathname, and the file
2256 exists, the write shall fail.
2257
2258 4. If file is not specified, the current pathname shall be used. If
2259 there is no current pathname, the write command shall fail.
2260
2261 5. If the current pathname is used, and the current pathname has been
2262 changed by the file or read commands, and the file exists, the
2263 write shall fail. If the write is successful, subsequent writes
2264 shall not fail for this reason (unless the current pathname is
2265 changed again).
2266
2267 6. If the whole edit buffer is not being written, and the file to be
2268 written exists, the write shall fail.
2269
2270 For rules 1., 2., 3., and 5., the write can be forced by appending the
2271 character '!' to the command name.
2272
2273 For rules 2., 3., and 5., the write can be forced by setting the
2274 writeany edit option.
2275
2276 Additional, implementation-defined tests may cause the write to fail.
2277
2278 If the edit buffer is empty, a file without any contents shall be writ‐
2279 ten.
2280
2281 An informational message shall be written noting the number of lines
2282 and bytes written.
2283
2284 Otherwise, if the command is followed by one or more <blank> charac‐
2285 ters, and the file is preceded by '!', the rest of the line after the
2286 '!' shall have '%', '#', and '!' characters expanded as described in
2287 Command Line Parsing in ex.
2288
2289 The ex utility shall then pass two arguments to the program named by
2290 the shell edit option; the first shall be −c and the second shall be
2291 the expanded arguments to the write command as a single argument. The
2292 specified lines shall be written to the standard input of the command.
2293 The standard error and standard output of the program, if any, shall be
2294 written as described for the print command. If the last character in
2295 that output is not a <newline>, a <newline> shall be written at the end
2296 of the output.
2297
2298 The special meaning of the '!' following the write command can be
2299 overridden by escaping it with a <backslash> character.
2300
2301 Current line: Unchanged.
2302
2303 Current column: Unchanged.
2304
2305 Write and Exit
2306 Synopsis:
2307 [2addr] x[it][!][file]
2308
2309 If the edit buffer has not been modified since the last complete write,
2310 xit shall be equivalent to the quit command, or if a '!' is appended
2311 to the command name, to quit!.
2312
2313 Otherwise, xit shall be equivalent to the wq command, or if a '!' is
2314 appended to the command name, to wq!.
2315
2316 Current line: Unchanged.
2317
2318 Current column: Unchanged.
2319
2320 Yank
2321 Synopsis:
2322 [2addr] ya[nk][buffer][count]
2323
2324 Copy the specified lines to the specified buffer (by default, the
2325 unnamed buffer), which shall become a line-mode buffer.
2326
2327 Current line: Unchanged.
2328
2329 Current column: Unchanged.
2330
2331 Adjust Window
2332 Synopsis:
2333 [1addr] z[!][type ...][count][flags]
2334
2335 If no line is specified, the current line shall be the default; if type
2336 is omitted as well, the current line value shall first be incremented
2337 by 1. If incrementing the current line would cause it to be greater
2338 than the last line in the edit buffer, it shall be an error.
2339
2340 If there are <blank> characters between the type argument and the pre‐
2341 ceding z command name or optional '!' character, it shall be an error.
2342
2343 If count is specified, the value of the window edit option shall be set
2344 to count (as described in window). If count is omitted, it shall
2345 default to 2 times the value of the scroll edit option, or if ! was
2346 specified, the number of lines in the display minus 1.
2347
2348 If type is omitted, then count lines starting with the specified line
2349 shall be written. Otherwise, count lines starting with the line speci‐
2350 fied by the type argument shall be written.
2351
2352 The type argument shall change the lines to be written. The possible
2353 values of type are as follows:
2354
2355 − The specified line shall be decremented by the following value:
2356
2357 (((number of ``−'' characters) x count) −1)
2358
2359 If the calculation would result in a number less than 1, it shall
2360 be an error. Write lines from the edit buffer, starting at the
2361 new value of line, until count lines or the last line in the edit
2362 buffer has been written.
2363
2364 + The specified line shall be incremented by the following value:
2365
2366 (((number of ``+'' characters) −1) x count) +1
2367
2368 If the calculation would result in a number greater than the last
2369 line in the edit buffer, it shall be an error. Write lines from
2370 the edit buffer, starting at the new value of line, until count
2371 lines or the last line in the edit buffer has been written.
2372
2373 =,. If more than a single '.' or '=' is specified, it shall be an
2374 error. The following steps shall be taken:
2375
2376 1. If count is zero, nothing shall be written.
2377
2378 2. Write as many of the N lines before the current line in the
2379 edit buffer as exist. If count or '!' was specified, N shall
2380 be:
2381
2382 (count −1) /2
2383
2384 Otherwise, N shall be:
2385
2386 (count −3) /2
2387
2388 If N is a number less than 3, no lines shall be written.
2389
2390 3. If '=' was specified as the type character, write a line con‐
2391 sisting of the smaller of the number of columns in the dis‐
2392 play divided by two, or 40 '−' characters.
2393
2394 4. Write the current line.
2395
2396 5. Repeat step 3.
2397
2398 6. Write as many of the N lines after the current line in the
2399 edit buffer as exist. N shall be defined as in step 2. If N
2400 is a number less than 3, no lines shall be written. If count
2401 is less than 3, no lines shall be written.
2402
2403 ^ The specified line shall be decremented by the following value:
2404
2405 (((number of ``^'' characters) +1) x count) −1
2406
2407 If the calculation would result in a number less than 1, it shall
2408 be an error. Write lines from the edit buffer, starting at the
2409 new value of line, until count lines or the last line in the edit
2410 buffer has been written.
2411
2412 Current line: Set to the last line written, unless the type is =, in
2413 which case, set to the specified line.
2414
2415 Current column: Set to non-<blank>.
2416
2417 Escape
2418 Synopsis:
2419 ! command
2420 [addr]! command
2421
2422 The contents of the line after the '!' shall have '%', '#', and '!'
2423 characters expanded as described in Command Line Parsing in ex. If the
2424 expansion causes the text of the line to change, it shall be redis‐
2425 played, preceded by a single '!' character.
2426
2427 The ex utility shall execute the program named by the shell edit
2428 option. It shall pass two arguments to the program; the first shall be
2429 −c, and the second shall be the expanded arguments to the ! command as
2430 a single argument.
2431
2432 If no lines are specified, the standard input, standard output, and
2433 standard error of the program shall be set to the standard input, stan‐
2434 dard output, and standard error of the ex program when it was invoked.
2435 In addition, a warning message shall be written if the edit buffer has
2436 been modified since the last complete write, and the warn edit option
2437 is set.
2438
2439 If lines are specified, they shall be passed to the program as standard
2440 input, and the standard output and standard error of the program shall
2441 replace those lines in the edit buffer. Each line in the program output
2442 (as delimited by <newline> characters or the end of the output if it is
2443 not immediately preceded by a <newline>), shall be a separate line in
2444 the edit buffer. Any occurrences of <carriage-return> and <newline>
2445 pairs in the output shall be treated as single <newline> characters.
2446 The specified lines shall be copied into the unnamed buffer before they
2447 are replaced, and the unnamed buffer shall become a line-mode buffer.
2448
2449 If in ex mode, a single '!' character shall be written when the pro‐
2450 gram completes.
2451
2452 This command shall be affected by the shell and warn edit options. If
2453 no lines are specified, this command shall be affected by the autowrite
2454 and writeany edit options. If lines are specified, this command shall
2455 be affected by the autoprint edit option.
2456
2457 Current line:
2458
2459 1. If no lines are specified, unchanged.
2460
2461 2. Otherwise, set to the last line read in, if any lines are read in.
2462
2463 3. Otherwise, set to the line before the first line of the lines spec‐
2464 ified, if that line exists.
2465
2466 4. Otherwise, set to the first line of the edit buffer if the edit
2467 buffer is not empty.
2468
2469 5. Otherwise, set to zero.
2470
2471 Current column: If no lines are specified, unchanged. Otherwise, set to
2472 non-<blank>.
2473
2474 Shift Left
2475 Synopsis:
2476 [2addr] <[< ...][count][flags]
2477
2478 Shift the specified lines to the start of the line; the number of col‐
2479 umn positions to be shifted shall be the number of command characters
2480 times the value of the shiftwidth edit option. Only leading <blank>
2481 characters shall be deleted or changed into other <blank> characters in
2482 shifting; other characters shall not be affected.
2483
2484 Lines to be shifted shall be copied into the unnamed buffer, which
2485 shall become a line-mode buffer.
2486
2487 This command shall be affected by the autoprint edit option.
2488
2489 Current line: Set to the last line in the lines specified.
2490
2491 Current column: Set to non-<blank>.
2492
2493 Shift Right
2494 Synopsis:
2495 [2addr] >[> ...][count][flags]
2496
2497 Shift the specified lines away from the start of the line; the number
2498 of column positions to be shifted shall be the number of command char‐
2499 acters times the value of the shiftwidth edit option. The shift shall
2500 be accomplished by adding <blank> characters as a prefix to the line or
2501 changing leading <blank> characters into other <blank> characters.
2502 Empty lines shall not be changed.
2503
2504 Lines to be shifted shall be copied into the unnamed buffer, which
2505 shall become a line-mode buffer.
2506
2507 This command shall be affected by the autoprint edit option.
2508
2509 Current line: Set to the last line in the lines specified.
2510
2511 Current column: Set to non-<blank>.
2512
2513 <control>‐D
2514 Synopsis:
2515 <control>-D
2516
2517 Write the next n lines, where n is the minimum of the values of the
2518 scroll edit option and the number of lines after the current line in
2519 the edit buffer. If the current line is the last line of the edit buf‐
2520 fer it shall be an error.
2521
2522 Current line: Set to the last line written.
2523
2524 Current column: Set to non-<blank>.
2525
2526 Write Line Number
2527 Synopsis:
2528 [1addr] = [flags]
2529
2530 If line is not specified, it shall default to the last line in the edit
2531 buffer. Write the line number of the specified line.
2532
2533 Current line: Unchanged.
2534
2535 Current column: Unchanged.
2536
2537 Execute
2538 Synopsis:
2539 [2addr] @ buffer
2540 [2addr] * buffer
2541
2542 If no buffer is specified or is specified as '@' or '*', the last buf‐
2543 fer executed shall be used. If no previous buffer has been executed, it
2544 shall be an error.
2545
2546 For each line specified by the addresses, set the current line ('.')
2547 to the specified line, and execute the contents of the named buffer (as
2548 they were at the time the @ command was executed) as ex commands. For
2549 each line of a line-mode buffer, and all but the last line of a charac‐
2550 ter-mode buffer, the ex command parser shall behave as if the line was
2551 terminated by a <newline>.
2552
2553 If an error occurs during this process, or a line specified by the
2554 addresses does not exist when the current line would be set to it, or
2555 more than a single line was specified by the addresses, and the con‐
2556 tents of the edit buffer are replaced (for example, by the ex :edit
2557 command) an error message shall be written, and no more commands
2558 resulting from the execution of this command shall be processed.
2559
2560 Current line: As specified for the individual ex commands.
2561
2562 Current column: As specified for the individual ex commands.
2563
2564 Regular Expressions in ex
2565 The ex utility shall support regular expressions that are a superset of
2566 the basic regular expressions described in the Base Definitions volume
2567 of POSIX.1‐2008, Section 9.3, Basic Regular Expressions. A null regu‐
2568 lar expression ("//") shall be equivalent to the last regular expres‐
2569 sion encountered.
2570
2571 Regular expressions can be used in addresses to specify lines and, in
2572 some commands (for example, the substitute command), to specify por‐
2573 tions of a line to be substituted.
2574
2575 The following constructs can be used to enhance the basic regular
2576 expressions:
2577
2578 \< Match the beginning of a word. (See the definition of word at
2579 the beginning of Command Descriptions in ex.)
2580
2581 \> Match the end of a word.
2582
2583 ~ Match the replacement part of the last substitute command. The
2584 <tilde> ('~') character can be escaped in a regular expression to
2585 become a normal character with no special meaning. The <back‐
2586 slash> shall be discarded.
2587
2588 When the editor option magic is not set, the only characters with spe‐
2589 cial meanings shall be '^' at the beginning of a pattern, '$' at the
2590 end of a pattern, and <backslash>. The characters '.', '*', '[', and
2591 '~' shall be treated as ordinary characters unless preceded by a <back‐
2592 slash>; when preceded by a <backslash> they shall regain their special
2593 meaning, or in the case of <backslash>, be handled as a single <back‐
2594 slash>. <backslash> characters used to escape other characters shall
2595 be discarded.
2596
2597 Replacement Strings in ex
2598 The character '&' ('\&' if the editor option magic is not set) in the
2599 replacement string shall stand for the text matched by the pattern to
2600 be replaced. The character '~' ('\~' if magic is not set) shall be
2601 replaced by the replacement part of the previous substitute command.
2602 The sequence '\n', where n is an integer, shall be replaced by the text
2603 matched by the corresponding back-reference expression. If the corre‐
2604 sponding back-reference expression does not match, then the characters
2605 '\n' shall be replaced by the empty string.
2606
2607 The strings '\l', '\u', '\L', and '\U' can be used to modify the case
2608 of elements in the replacement string (using the '\&' or "\"digit)
2609 notation. The string '\l' ('\u') shall cause the character that follows
2610 to be converted to lowercase (uppercase). The string '\L' ('\U') shall
2611 cause all characters subsequent to it to be converted to lowercase
2612 (uppercase) as they are inserted by the substitution until the string
2613 '\e' or '\E', or the end of the replacement string, is encountered.
2614
2615 Otherwise, any character following a <backslash> shall be treated as
2616 that literal character, and the escaping <backslash> shall be dis‐
2617 carded.
2618
2619 An example of case conversion with the s command is as follows:
2620
2621 :p
2622 The cat sat on the mat.
2623 :s/\<.at\>/\u&/gp
2624 The Cat Sat on the Mat.
2625 :s/S\(.*\)M/S\U\1\eM/p
2626 The Cat SAT ON THE Mat.
2627
2628 Edit Options in ex
2629 The ex utility has a number of options that modify its behavior. These
2630 options have default settings, which can be changed using the set com‐
2631 mand.
2632
2633 Options are Boolean unless otherwise specified.
2634
2635 autoindent, ai
2636 [Default unset]
2637
2638 If autoindent is set, each line in input mode shall be indented (using
2639 first as many <tab> characters as possible, as determined by the editor
2640 option tabstop, and then using <space> characters) to align with
2641 another line, as follows:
2642
2643 1. If in open or visual mode and the text input is part of a line-ori‐
2644 ented command (see the EXTENDED DESCRIPTION in vi), align to the
2645 first column.
2646
2647 2. Otherwise, if in open or visual mode, indentation for each line
2648 shall be set as follows:
2649
2650 a. If a line was previously inserted as part of this command, it
2651 shall be set to the indentation of the last inserted line by
2652 default, or as otherwise specified for the <control>‐D charac‐
2653 ter in Input Mode Commands in vi.
2654
2655 b. Otherwise, it shall be set to the indentation of the previous
2656 current line, if any; otherwise, to the first column.
2657
2658 3. For the ex a, i, and c commands, indentation for each line shall be
2659 set as follows:
2660
2661 a. If a line was previously inserted as part of this command, it
2662 shall be set to the indentation of the last inserted line by
2663 default, or as otherwise specified for the eof character in
2664 Scroll.
2665
2666 b. Otherwise, if the command is the ex a command, it shall be set
2667 to the line appended after, if any; otherwise to the first col‐
2668 umn.
2669
2670 c. Otherwise, if the command is the ex i command, it shall be set
2671 to the line inserted before, if any; otherwise to the first
2672 column.
2673
2674 d. Otherwise, if the command is the ex c command, it shall be set
2675 to the indentation of the line replaced.
2676
2677 autoprint, ap
2678 [Default set]
2679
2680 If autoprint is set, the current line shall be written after each ex
2681 command that modifies the contents of the current edit buffer, and
2682 after each tag command for which the tag search pattern was found or
2683 tag line number was valid, unless:
2684
2685 1. The command was executed while in open or visual mode.
2686
2687 2. The command was executed as part of a global or v command or @ buf‐
2688 fer execution.
2689
2690 3. The command was the form of the read command that reads a file into
2691 the edit buffer.
2692
2693 4. The command was the append, change, or insert command.
2694
2695 5. The command was not terminated by a <newline>.
2696
2697 6. The current line shall be written by a flag specified to the com‐
2698 mand; for example, delete # shall write the current line as speci‐
2699 fied for the flag modifier to the delete command, and not as speci‐
2700 fied by the autoprint edit option.
2701
2702 autowrite, aw
2703 [Default unset]
2704
2705 If autowrite is set, and the edit buffer has been modified since it was
2706 last completely written to any file, the contents of the edit buffer
2707 shall be written as if the ex write command had been specified without
2708 arguments, before each command affected by the autowrite edit option is
2709 executed. Appending the character '!' to the command name of any of
2710 the ex commands except '!' shall prevent the write. If the write
2711 fails, it shall be an error and the command shall not be executed.
2712
2713 beautify, bf
2714 [Default unset]
2715
2716 If beautify is set, all non-printable characters, other than <tab>,
2717 <newline>, and <form-feed> characters, shall be discarded from text
2718 read in from files.
2719
2720 directory, dir
2721 [Default implementation-defined]
2722
2723 The value of this option specifies the directory in which the editor
2724 buffer is to be placed. If this directory is not writable by the user,
2725 the editor shall quit.
2726
2727 edcompatible, ed
2728 [Default unset]
2729
2730 Causes the presence of g and c suffixes on substitute commands to be
2731 remembered, and toggled by repeating the suffixes.
2732
2733 errorbells, eb
2734 [Default unset]
2735
2736 If the editor is in ex mode, and the terminal does not support a stand‐
2737 out mode (such as inverse video), and errorbells is set, error messages
2738 shall be preceded by alerting the terminal.
2739
2740 exrc
2741 [Default unset]
2742
2743 If exrc is set, ex shall access any .exrc file in the current direc‐
2744 tory, as described in Initialization in ex and vi. If exrc is not set,
2745 ex shall ignore any .exrc file in the current directory during initial‐
2746 ization, unless the current directory is that named by the HOME envi‐
2747 ronment variable.
2748
2749 ignorecase, ic
2750 [Default unset]
2751
2752 If ignorecase is set, characters that have uppercase and lowercase rep‐
2753 resentations shall have those representations considered as equivalent
2754 for purposes of regular expression comparison.
2755
2756 The ignorecase edit option shall affect all remembered regular expres‐
2757 sions; for example, unsetting the ignorecase edit option shall cause a
2758 subsequent vi n command to search for the last basic regular expression
2759 in a case-sensitive fashion.
2760
2761 list
2762 [Default unset]
2763
2764 If list is set, edit buffer lines written while in ex command mode
2765 shall be written as specified for the print command with the l flag
2766 specified. In open or visual mode, each edit buffer line shall be dis‐
2767 played as specified for the ex print command with the l flag specified.
2768 In open or visual text input mode, when the cursor does not rest on any
2769 character in the line, it shall rest on the '$' marking the end of the
2770 line.
2771
2772 magic
2773 [Default set]
2774
2775 If magic is set, modify the interpretation of characters in regular
2776 expressions and substitution replacement strings (see Regular Expres‐
2777 sions in ex and Replacement Strings in ex).
2778
2779 mesg
2780 [Default set]
2781
2782 If mesg is set, the permission for others to use the write or talk com‐
2783 mands to write to the terminal shall be turned on while in open or vis‐
2784 ual mode. The shell-level command mesg n shall take precedence over any
2785 setting of the ex mesg option; that is, if mesg y was issued before the
2786 editor started (or in a shell escape), such as:
2787
2788 :!mesg y
2789
2790 the mesg option in ex shall suppress incoming messages, but the mesg
2791 option shall not enable incoming messages if mesg n was issued.
2792
2793 number, nu
2794 [Default unset]
2795
2796 If number is set, edit buffer lines written while in ex command mode
2797 shall be written with line numbers, in the format specified by the
2798 print command with the # flag specified. In ex text input mode, each
2799 line shall be preceded by the line number it will have in the file.
2800
2801 In open or visual mode, each edit buffer line shall be displayed with a
2802 preceding line number, in the format specified by the ex print command
2803 with the # flag specified. This line number shall not be considered
2804 part of the line for the purposes of evaluating the current column;
2805 that is, column position 1 shall be the first column position after the
2806 format specified by the print command.
2807
2808 paragraphs, para
2809 [Default in the POSIX locale IPLPPPQPP LIpplpipbp]
2810
2811 The paragraphs edit option shall define additional paragraph boundaries
2812 for the open and visual mode commands. The paragraphs edit option can
2813 be set to a character string consisting of zero or more character
2814 pairs. It shall be an error to set it to an odd number of characters.
2815
2816 prompt
2817 [Default set]
2818
2819 If prompt is set, ex command mode input shall be prompted for with a
2820 <colon> (':'); when unset, no prompt shall be written.
2821
2822 readonly
2823 [Default see text]
2824
2825 If the readonly edit option is set, read-only mode shall be enabled
2826 (see Write). The readonly edit option shall be initialized to set if
2827 either of the following conditions are true:
2828
2829 * The command-line option −R was specified.
2830
2831 * Performing actions equivalent to the access() function called with
2832 the following arguments indicates that the file lacks write permis‐
2833 sion:
2834
2835 1. The current pathname is used as the path argument.
2836
2837 2. The constant W_OK is used as the amode argument.
2838
2839 The readonly edit option may be initialized to set for other, implemen‐
2840 tation-defined reasons. The readonly edit option shall not be initial‐
2841 ized to unset based on any special privileges of the user or process.
2842 The readonly edit option shall be reinitialized each time that the con‐
2843 tents of the edit buffer are replaced (for example, by an edit or next
2844 command) unless the user has explicitly set it, in which case it shall
2845 remain set until the user explicitly unsets it. Once unset, it shall
2846 again be reinitialized each time that the contents of the edit buffer
2847 are replaced.
2848
2849 redraw
2850 [Default unset]
2851
2852 The editor simulates an intelligent terminal on a dumb terminal.
2853 (Since this is likely to require a large amount of output to the termi‐
2854 nal, it is useful only at high transmission speeds.)
2855
2856 remap
2857 [Default set]
2858
2859 If remap is set, map translation shall allow for maps defined in terms
2860 of other maps; translation shall continue until a final product is
2861 obtained. If unset, only a one-step translation shall be done.
2862
2863 report
2864 [Default 5]
2865
2866 The value of this report edit option specifies what number of lines
2867 being added, copied, deleted, or modified in the edit buffer will cause
2868 an informational message to be written to the user. The following con‐
2869 ditions shall cause an informational message. The message shall contain
2870 the number of lines added, copied, deleted, or modified, but is other‐
2871 wise unspecified.
2872
2873 * An ex or vi editor command, other than open, undo, or visual, that
2874 modifies at least the value of the report edit option number of
2875 lines, and which is not part of an ex global or v command, or ex or
2876 vi buffer execution, shall cause an informational message to be
2877 written.
2878
2879 * An ex yank or vi y or Y command, that copies at least the value of
2880 the report edit option plus 1 number of lines, and which is not
2881 part of an ex global or v command, or ex or vi buffer execution,
2882 shall cause an informational message to be written.
2883
2884 * An ex global, v, open, undo, or visual command or ex or vi buffer
2885 execution, that adds or deletes a total of at least the value of
2886 the report edit option number of lines, and which is not part of an
2887 ex global or v command, or ex or vi buffer execution, shall cause
2888 an informational message to be written. (For example, if 3 lines
2889 were added and 8 lines deleted during an ex visual command, 5 would
2890 be the number compared against the report edit option after the
2891 command completed.)
2892
2893 scroll, scr
2894 [Default (number of lines in the display −1)/2]
2895
2896 The value of the scroll edit option shall determine the number of lines
2897 scrolled by the ex <control>‐D and z commands. For the vi <control>‐D
2898 and <control>‐U commands, it shall be the initial number of lines to
2899 scroll when no previous <control>‐D or <control>‐U command has been
2900 executed.
2901
2902 sections
2903 [Default in the POSIX locale NHSHH HUnhsh]
2904
2905 The sections edit option shall define additional section boundaries for
2906 the open and visual mode commands. The sections edit option can be set
2907 to a character string consisting of zero or more character pairs; it
2908 shall be an error to set it to an odd number of characters.
2909
2910 shell, sh
2911 [Default from the environment variable SHELL]
2912
2913 The value of this option shall be a string. The default shall be taken
2914 from the SHELL environment variable. If the SHELL environment variable
2915 is null or empty, the sh (see sh) utility shall be the default.
2916
2917 shiftwidth, sw
2918 [Default 8]
2919
2920 The value of this option shall give the width in columns of an indenta‐
2921 tion level used during autoindentation and by the shift commands (< and
2922 >).
2923
2924 showmatch, sm
2925 [Default unset]
2926
2927 The functionality described for the showmatch edit option need not be
2928 supported on block-mode terminals or terminals with insufficient capa‐
2929 bilities.
2930
2931 If showmatch is set, in open or visual mode, when a ')' or '}' is
2932 typed, if the matching '(' or '{' is currently visible on the display,
2933 the matching '(' or '{' shall be flagged moving the cursor to its loca‐
2934 tion for an unspecified amount of time.
2935
2936 showmode
2937 [Default unset]
2938
2939 If showmode is set, in open or visual mode, the current mode that the
2940 editor is in shall be displayed on the last line of the display. Com‐
2941 mand mode and text input mode shall be differentiated; other unspeci‐
2942 fied modes and implementation-defined information may be displayed.
2943
2944 slowopen
2945 [Default unset]
2946
2947 If slowopen is set during open and visual text input modes, the editor
2948 shall not update portions of the display other than those display line
2949 columns that display the characters entered by the user (see Input Mode
2950 Commands in vi).
2951
2952 tabstop, ts
2953 [Default 8]
2954
2955 The value of this edit option shall specify the column boundary used by
2956 a <tab> in the display (see autoprint, ap and Input Mode Commands in
2957 vi).
2958
2959 taglength, tl
2960 [Default zero]
2961
2962 The value of this edit option shall specify the maximum number of char‐
2963 acters that are considered significant in the user-specified tag name
2964 and in the tag name from the tags file. If the value is zero, all char‐
2965 acters in both tag names shall be significant.
2966
2967 tags
2968 [Default see text]
2969
2970 The value of this edit option shall be a string of <blank>-delimited
2971 pathnames of files used by the tag command. The default value is
2972 unspecified.
2973
2974 term
2975 [Default from the environment variable TERM]
2976
2977 The value of this edit option shall be a string. The default shall be
2978 taken from the TERM variable in the environment. If the TERM environ‐
2979 ment variable is empty or null, the default is unspecified. The editor
2980 shall use the value of this edit option to determine the type of the
2981 display device.
2982
2983 The results are unspecified if the user changes the value of the term
2984 edit option after editor initialization.
2985
2986 terse
2987 [Default unset]
2988
2989 If terse is set, error messages may be less verbose. However, except
2990 for this caveat, error messages are unspecified. Furthermore, not all
2991 error messages need change for different settings of this option.
2992
2993 warn
2994 [Default set]
2995
2996 If warn is set, and the contents of the edit buffer have been modified
2997 since they were last completely written, the editor shall write a warn‐
2998 ing message before certain ! commands (see Escape).
2999
3000 window
3001 [Default see text]
3002
3003 A value used in open and visual mode, by the <control>‐B and <con‐
3004 trol>‐F commands, and, in visual mode, to specify the number of lines
3005 displayed when the screen is repainted.
3006
3007 If the −w command-line option is not specified, the default value shall
3008 be set to the value of the LINES environment variable. If the LINES
3009 environment variable is empty or null, the default shall be the number
3010 of lines in the display minus 1.
3011
3012 Setting the window edit option to zero or to a value greater than the
3013 number of lines in the display minus 1 (either explicitly or based on
3014 the −w option or the LINES environment variable) shall cause the window
3015 edit option to be set to the number of lines in the display minus 1.
3016
3017 The baud rate of the terminal line may change the default in an imple‐
3018 mentation-defined manner.
3019
3020 wrapmargin, wm
3021 [Default 0]
3022
3023 If the value of this edit option is zero, it shall have no effect.
3024
3025 If not in the POSIX locale, the effect of this edit option is implemen‐
3026 tation-defined.
3027
3028 Otherwise, it shall specify a number of columns from the ending margin
3029 of the terminal.
3030
3031 During open and visual text input modes, for each character for which
3032 any part of the character is displayed in a column that is less than
3033 wrapmargin columns from the ending margin of the display line, the edi‐
3034 tor shall behave as follows:
3035
3036 1. If the character triggering this event is a <blank>, it, and all
3037 immediately preceding <blank> characters on the current line
3038 entered during the execution of the current text input command,
3039 shall be discarded, and the editor shall behave as if the user had
3040 entered a single <newline> instead. In addition, if the next user-
3041 entered character is a <space>, it shall be discarded as well.
3042
3043 2. Otherwise, if there are one or more <blank> characters on the cur‐
3044 rent line immediately preceding the last group of inserted
3045 non-<blank> characters which was entered during the execution of
3046 the current text input command, the <blank> characters shall be
3047 replaced as if the user had entered a single <newline> instead.
3048
3049 If the autoindent edit option is set, and the events described in 1. or
3050 2. are performed, any <blank> characters at or after the cursor in the
3051 current line shall be discarded.
3052
3053 The ending margin shall be determined by the system or overridden by
3054 the user, as described for COLUMNS in the ENVIRONMENT VARIABLES section
3055 and the Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment
3056 Variables.
3057
3058 wrapscan, ws
3059 [Default set]
3060
3061 If wrapscan is set, searches (the ex / or ? addresses, or open and
3062 visual mode /, ?, N, and n commands) shall wrap around the beginning or
3063 end of the edit buffer; when unset, searches shall stop at the begin‐
3064 ning or end of the edit buffer.
3065
3066 writeany, wa
3067 [Default unset]
3068
3069 If writeany is set, some of the checks performed when executing the ex
3070 write commands shall be inhibited, as described in editor option
3071 autowrite.
3072
3074 The following exit values shall be returned:
3075
3076 0 Successful completion.
3077
3078 >0 An error occurred.
3079
3081 When any error is encountered and the standard input is not a terminal
3082 device file, ex shall not write the file or return to command or text
3083 input mode, and shall terminate with a non-zero exit status.
3084
3085 Otherwise, when an unrecoverable error is encountered, it shall be
3086 equivalent to a SIGHUP asynchronous event.
3087
3088 Otherwise, when an error is encountered, the editor shall behave as
3089 specified in Command Line Parsing in ex.
3090
3091 The following sections are informative.
3092
3094 If a SIGSEGV signal is received while ex is saving a file, the file
3095 might not be successfully saved.
3096
3097 The next command can accept more than one file, so usage such as:
3098
3099 next `ls [abc]*`
3100
3101 is valid; it would not be valid for the edit or read commands, for
3102 example, because they expect only one file and unspecified results
3103 occur.
3104
3106 None.
3107
3109 The ex/vi specification is based on the historical practice found in
3110 the 4 BSD and System V implementations of ex and vi.
3111
3112 A restricted editor (both the historical red utility and modifications
3113 to ex) were considered and rejected for inclusion. Neither option pro‐
3114 vided the level of security that users might expect.
3115
3116 It is recognized that ex visual mode and related features would be dif‐
3117 ficult, if not impossible, to implement satisfactorily on a block-mode
3118 terminal, or a terminal without any form of cursor addressing; thus, it
3119 is not a mandatory requirement that such features should work on all
3120 terminals. It is the intention, however, that an ex implementation
3121 should provide the full set of capabilities on all terminals capable of
3122 supporting them.
3123
3124 Options
3125 The −c replacement for +command was inspired by the −e option of sed.
3126 Historically, all such commands (see edit and next as well) were exe‐
3127 cuted from the last line of the edit buffer. This meant, for example,
3128 that "+/pattern" would fail unless the wrapscan option was set.
3129 POSIX.1‐2008 requires conformance to historical practice. The +command
3130 option is no longer specified by POSIX.1‐2008 but may be present in
3131 some implementations. Historically, some implementations restricted the
3132 ex commands that could be listed as part of the command line arguments.
3133 For consistency, POSIX.1‐2008 does not permit these restrictions.
3134
3135 In historical implementations of the editor, the −R option (and the
3136 readonly edit option) only prevented overwriting of files; appending to
3137 files was still permitted, mapping loosely into the csh noclobber vari‐
3138 able. Some implementations, however, have not followed this semantic,
3139 and readonly does not permit appending either. POSIX.1‐2008 follows the
3140 latter practice, believing that it is a more obvious and intuitive
3141 meaning of readonly.
3142
3143 The −s option suppresses all interactive user feedback and is useful
3144 for editing scripts in batch jobs. The list of specific effects is his‐
3145 torical practice. The terminal type ``incapable of supporting open and
3146 visual modes'' has historically been named ``dumb''.
3147
3148 The −t option was required because the ctags utility appears in
3149 POSIX.1‐2008 and the option is available in all historical implementa‐
3150 tions of ex.
3151
3152 Historically, the ex and vi utilities accepted a −x option, which did
3153 encryption based on the algorithm found in the historical crypt util‐
3154 ity. The −x option for encryption, and the associated crypt utility,
3155 were omitted because the algorithm used was not specifiable and the
3156 export control laws of some nations make it difficult to export crypto‐
3157 graphic technology. In addition, it did not historically provide the
3158 level of security that users might expect.
3159
3160 Standard Input
3161 An end-of-file condition is not equivalent to an end-of-file character.
3162 A common end-of-file character, <control>‐D, is historically an ex com‐
3163 mand.
3164
3165 There was no maximum line length in historical implementations of ex.
3166 Specifically, as it was parsed in chunks, the addresses had a different
3167 maximum length than the filenames. Further, the maximum line buffer
3168 size was declared as BUFSIZ, which was different lengths on different
3169 systems. This version selected the value of {LINE_MAX} to impose a rea‐
3170 sonable restriction on portable usage of ex and to aid test suite writ‐
3171 ers in their development of realistic tests that exercise this limit.
3172
3173 Input Files
3174 It was an explicit decision by the standard developers that a <newline>
3175 be added to any file lacking one. It was believed that this feature of
3176 ex and vi was relied on by users in order to make text files lacking a
3177 trailing <newline> more portable. It is recognized that this will
3178 require a user-specified option or extension for implementations that
3179 permit ex and vi to edit files of type other than text if such files
3180 are not otherwise identified by the system. It was agreed that the
3181 ability to edit files of arbitrary type can be useful, but it was not
3182 considered necessary to mandate that an ex or vi implementation be
3183 required to handle files other than text files.
3184
3185 The paragraph in the INPUT FILES section, ``By default, ...'', is
3186 intended to close a long-standing security problem in ex and vi; that
3187 of the ``modeline'' or ``modelines'' edit option. This feature allows
3188 any line in the first or last five lines of the file containing the
3189 strings "ex:" or "vi:" (and, apparently, "ei:" or "vx:") to be a line
3190 containing editor commands, and ex interprets all the text up to the
3191 next ':' or <newline> as a command. Consider the consequences, for
3192 example, of an unsuspecting user using ex or vi as the editor when
3193 replying to a mail message in which a line such as:
3194
3195 ex:! rm −rf :
3196
3197 appeared in the signature lines. The standard developers believed
3198 strongly that an editor should not by default interpret any lines of a
3199 file. Vendors are strongly urged to delete this feature from their
3200 implementations of ex and vi.
3201
3202 Asynchronous Events
3203 The intention of the phrase ``complete write'' is that the entire edit
3204 buffer be written to stable storage. The note regarding temporary files
3205 is intended for implementations that use temporary files to back edit
3206 buffers unnamed by the user.
3207
3208 Historically, SIGQUIT was ignored by ex, but was the equivalent of the
3209 Q command in visual mode; that is, it exited visual mode and entered ex
3210 mode. POSIX.1‐2008 permits, but does not require, this behavior. His‐
3211 torically, SIGINT was often used by vi users to terminate text input
3212 mode (<control>‐C is often easier to enter than <ESC>). Some implemen‐
3213 tations of vi alerted the terminal on this event, and some did not.
3214 POSIX.1‐2008 requires that SIGINT behave identically to <ESC>, and that
3215 the terminal not be alerted.
3216
3217 Historically, suspending the ex editor during text input mode was simi‐
3218 lar to SIGINT, as completed lines were retained, but any partial line
3219 discarded, and the editor returned to command mode. POSIX.1‐2008 is
3220 silent on this issue; implementations are encouraged to follow histori‐
3221 cal practice, where possible.
3222
3223 Historically, the vi editor did not treat SIGTSTP as an asynchronous
3224 event, and it was therefore impossible to suspend the editor in visual
3225 text input mode. There are two major reasons for this. The first is
3226 that SIGTSTP is a broadcast signal on UNIX systems, and the chain of
3227 events where the shell execs an application that then execs vi usually
3228 caused confusion for the terminal state if SIGTSTP was delivered to the
3229 process group in the default manner. The second was that most implemen‐
3230 tations of the UNIX curses package did not handle SIGTSTP safely, and
3231 the receipt of SIGTSTP at the wrong time would cause them to crash.
3232 POSIX.1‐2008 is silent on this issue; implementations are encouraged to
3233 treat suspension as an asynchronous event if possible.
3234
3235 Historically, modifications to the edit buffer made before SIGINT
3236 interrupted an operation were retained; that is, anywhere from zero to
3237 all of the lines to be modified might have been modified by the time
3238 the SIGINT arrived. These changes were not discarded by the arrival of
3239 SIGINT. POSIX.1‐2008 permits this behavior, noting that the undo com‐
3240 mand is required to be able to undo these partially completed commands.
3241
3242 The action taken for signals other than SIGINT, SIGCONT, SIGHUP, and
3243 SIGTERM is unspecified because some implementations attempt to save the
3244 edit buffer in a useful state when other signals are received.
3245
3246 Standard Error
3247 For ex/vi, diagnostic messages are those messages reported as a result
3248 of a failed attempt to invoke ex or vi, such as invalid options or
3249 insufficient resources, or an abnormal termination condition. Diagnos‐
3250 tic messages should not be confused with the error messages generated
3251 by inappropriate or illegal user commands.
3252
3253 Initialization in ex and vi
3254 If an ex command (other than cd, chdir, or source) has a filename argu‐
3255 ment, one or both of the alternate and current pathnames will be set.
3256 Informally, they are set as follows:
3257
3258 1. If the ex command is one that replaces the contents of the edit
3259 buffer, and it succeeds, the current pathname will be set to the
3260 filename argument (the first filename argument in the case of the
3261 next command) and the alternate pathname will be set to the previ‐
3262 ous current pathname, if there was one.
3263
3264 2. In the case of the file read/write forms of the read and write com‐
3265 mands, if there is no current pathname, the current pathname will
3266 be set to the filename argument.
3267
3268 3. Otherwise, the alternate pathname will be set to the filename argu‐
3269 ment.
3270
3271 For example, :edit foo and :recover foo, when successful, set the cur‐
3272 rent pathname, and, if there was a previous current pathname, the
3273 alternate pathname. The commands :write, !command, and :edit set nei‐
3274 ther the current or alternate pathnames. If the :edit foo command were
3275 to fail for some reason, the alternate pathname would be set. The read
3276 and write commands set the alternate pathname to their file argument,
3277 unless the current pathname is not set, in which case they set the cur‐
3278 rent pathname to their file arguments. The alternate pathname was not
3279 historically set by the :source command. POSIX.1‐2008 requires confor‐
3280 mance to historical practice. Implementations adding commands that
3281 take filenames as arguments are encouraged to set the alternate path‐
3282 name as described here.
3283
3284 Historically, ex and vi read the .exrc file in the $HOME directory
3285 twice, if the editor was executed in the $HOME directory. POSIX.1‐2008
3286 prohibits this behavior.
3287
3288 Historically, the 4 BSD ex and vi read the $HOME and local .exrc files
3289 if they were owned by the real ID of the user, or the sourceany option
3290 was set, regardless of other considerations. This was a security prob‐
3291 lem because it is possible to put normal UNIX system commands inside a
3292 .exrc file. POSIX.1‐2008 does not specify the sourceany option, and
3293 historical implementations are encouraged to delete it.
3294
3295 The .exrc files must be owned by the real ID of the user, and not
3296 writable by anyone other than the owner. The appropriate privileges
3297 exception is intended to permit users to acquire special privileges,
3298 but continue to use the .exrc files in their home directories.
3299
3300 System V Release 3.2 and later vi implementations added the option
3301 [no]exrc. The behavior is that local .exrc files are read-only if the
3302 exrc option is set. The default for the exrc option was off, so by
3303 default, local .exrc files were not read. The problem this was intended
3304 to solve was that System V permitted users to give away files, so there
3305 is no possible ownership or writeability test to ensure that the file
3306 is safe. This is still a security problem on systems where users can
3307 give away files, but there is nothing additional that POSIX.1‐2008 can
3308 do. The implementation-defined exception is intended to permit groups
3309 to have local .exrc files that are shared by users, by creating pseudo-
3310 users to own the shared files.
3311
3312 POSIX.1‐2008 does not mention system-wide ex and vi start-up files.
3313 While they exist in several implementations of ex and vi, they are not
3314 present in any implementations considered historical practice by
3315 POSIX.1‐2008. Implementations that have such files should use them only
3316 if they are owned by the real user ID or an appropriate user (for exam‐
3317 ple, root on UNIX systems) and if they are not writable by any user
3318 other than their owner. System-wide start-up files should be read
3319 before the EXINIT variable, $HOME/.exrc, or local .exrc files are eval‐
3320 uated.
3321
3322 Historically, any ex command could be entered in the EXINIT variable or
3323 the .exrc file, although ones requiring that the edit buffer already
3324 contain lines of text generally caused historical implementations of
3325 the editor to drop core. POSIX.1‐2008 requires that any ex command be
3326 permitted in the EXINIT variable and .exrc files, for simplicity of
3327 specification and consistency, although many of them will obviously
3328 fail under many circumstances.
3329
3330 The initialization of the contents of the edit buffer uses the phrase
3331 ``the effect shall be'' with regard to various ex commands. The intent
3332 of this phrase is that edit buffer contents loaded during the initial‐
3333 ization phase not be lost; that is, loading the edit buffer should fail
3334 if the .exrc file read in the contents of a file and did not subse‐
3335 quently write the edit buffer. An additional intent of this phrase is
3336 to specify that the initial current line and column is set as specified
3337 for the individual ex commands.
3338
3339 Historically, the −t option behaved as if the tag search were a +com‐
3340 mand; that is, it was executed from the last line of the file specified
3341 by the tag. This resulted in the search failing if the pattern was a
3342 forward search pattern and the wrapscan edit option was not set.
3343 POSIX.1‐2008 does not permit this behavior, requiring that the search
3344 for the tag pattern be performed on the entire file, and, if not found,
3345 that the current line be set to a more reasonable location in the file.
3346
3347 Historically, the empty edit buffer presented for editing when a file
3348 was not specified by the user was unnamed. This is permitted by
3349 POSIX.1‐2008; however, implementations are encouraged to provide users
3350 a temporary filename for this buffer because it permits them the use of
3351 ex commands that use the current pathname during temporary edit ses‐
3352 sions.
3353
3354 Historically, the file specified using the −t option was not part of
3355 the current argument list. This practice is permitted by POSIX.1‐2008;
3356 however, implementations are encouraged to include its name in the cur‐
3357 rent argument list for consistency.
3358
3359 Historically, the −c command was generally not executed until a file
3360 that already exists was edited. POSIX.1‐2008 requires conformance to
3361 this historical practice. Commands that could cause the −c command to
3362 be executed include the ex commands edit, next, recover, rewind, and
3363 tag, and the vi commands <control>‐^ and <control>‐]. Historically,
3364 reading a file into an edit buffer did not cause the −c command to be
3365 executed (even though it might set the current pathname) with the
3366 exception that it did cause the −c command to be executed if: the edi‐
3367 tor was in ex mode, the edit buffer had no current pathname, the edit
3368 buffer was empty, and no read commands had yet been attempted. For con‐
3369 sistency and simplicity of specification, POSIX.1‐2008 does not permit
3370 this behavior.
3371
3372 Historically, the −r option was the same as a normal edit session if
3373 there was no recovery information available for the file. This allowed
3374 users to enter:
3375
3376 vi −r *.c
3377
3378 and recover whatever files were recoverable. In some implementations,
3379 recovery was attempted only on the first file named, and the file was
3380 not entered into the argument list; in others, recovery was attempted
3381 for each file named. In addition, some historical implementations
3382 ignored −r if −t was specified or did not support command line file
3383 arguments with the −t option. For consistency and simplicity of speci‐
3384 fication, POSIX.1‐2008 disallows these special cases, and requires that
3385 recovery be attempted the first time each file is edited.
3386
3387 Historically, vi initialized the ` and ' marks, but ex did not. This
3388 meant that if the first command in ex mode was visual or if an ex com‐
3389 mand was executed first (for example, vi +10 file), vi was entered
3390 without the marks being initialized. Because the standard developers
3391 believed the marks to be generally useful, and for consistency and sim‐
3392 plicity of specification, POSIX.1‐2008 requires that they always be
3393 initialized if in open or visual mode, or if in ex mode and the edit
3394 buffer is not empty. Not initializing it in ex mode if the edit buffer
3395 is empty is historical practice; however, it has always been possible
3396 to set (and use) marks in empty edit buffers in open and visual mode
3397 edit sessions.
3398
3399 Addressing
3400 Historically, ex and vi accepted the additional addressing forms '\/'
3401 and '\?'. They were equivalent to "//" and "??", respectively. They
3402 are not required by POSIX.1‐2008, mostly because nobody can remember
3403 whether they ever did anything different historically.
3404
3405 Historically, ex and vi permitted an address of zero for several com‐
3406 mands, and permitted the % address in empty files for others. For con‐
3407 sistency, POSIX.1‐2008 requires support for the former in the few com‐
3408 mands where it makes sense, and disallows it otherwise. In addition,
3409 because POSIX.1‐2008 requires that % be logically equivalent to "1,$",
3410 it is also supported where it makes sense and disallowed otherwise.
3411
3412 Historically, the % address could not be followed by further addresses.
3413 For consistency and simplicity of specification, POSIX.1‐2008 requires
3414 that additional addresses be supported.
3415
3416 All of the following are valid addresses:
3417
3418 +++ Three lines after the current line.
3419
3420 /re/− One line before the next occurrence of re.
3421
3422 −2 Two lines before the current line.
3423
3424 3 −−−− 2 Line one (note intermediate negative address).
3425
3426 1 2 3 Line six.
3427
3428 Any number of addresses can be provided to commands taking addresses;
3429 for example, "1,2,3,4,5p" prints lines 4 and 5, because two is the
3430 greatest valid number of addresses accepted by the print command. This,
3431 in combination with the <semicolon> delimiter, permits users to create
3432 commands based on ordered patterns in the file. For example, the com‐
3433 mand 3;/foo/;+2print will display the first line after line 3 that con‐
3434 tains the pattern foo, plus the next two lines. Note that the address
3435 3; must be evaluated before being discarded because the search origin
3436 for the /foo/ command depends on this.
3437
3438 Historically, values could be added to addresses by including them
3439 after one or more <blank> characters; for example, 3 − 5p wrote the
3440 seventh line of the file, and /foo/ 5 was the same as /foo/+5. How‐
3441 ever, only absolute values could be added; for example, 5 /foo/ was an
3442 error. POSIX.1‐2008 requires conformance to historical practice.
3443 Address offsets are separately specified from addresses because they
3444 could historically be provided to visual mode search commands.
3445
3446 Historically, any missing addresses defaulted to the current line. This
3447 was true for leading and trailing <comma>-delimited addresses, and for
3448 trailing <semicolon>-delimited addresses. For consistency, POSIX.1‐2008
3449 requires it for leading <semicolon> addresses as well.
3450
3451 Historically, ex and vi accepted the '^' character as both an address
3452 and as a flag offset for commands. In both cases it was identical to
3453 the '−' character. POSIX.1‐2008 does not require or prohibit this
3454 behavior.
3455
3456 Historically, the enhancements to basic regular expressions could be
3457 used in addressing; for example, '~', '\<', and '\>'. POSIX.1‐2008
3458 requires conformance to historical practice; that is, that regular
3459 expression usage be consistent, and that regular expression enhance‐
3460 ments be supported wherever regular expressions are used.
3461
3462 Command Line Parsing in ex
3463 Historical ex command parsing was even more complex than that described
3464 here. POSIX.1‐2008 requires the subset of the command parsing that the
3465 standard developers believed was documented and that users could rea‐
3466 sonably be expected to use in a portable fashion, and that was histori‐
3467 cally consistent between implementations. (The discarded functionality
3468 is obscure, at best.) Historical implementations will require changes
3469 in order to comply with POSIX.1‐2008; however, users are not expected
3470 to notice any of these changes. Most of the complexity in ex parsing
3471 is to handle three special termination cases:
3472
3473 1. The !, global, v, and the filter versions of the read and write
3474 commands are delimited by <newline> characters (they can contain
3475 <vertical-line> characters that are usually shell pipes).
3476
3477 2. The ex, edit, next, and visual in open and visual mode commands all
3478 take ex commands, optionally containing <vertical-line> characters,
3479 as their first arguments.
3480
3481 3. The s command takes a regular expression as its first argument, and
3482 uses the delimiting characters to delimit the command.
3483
3484 Historically, <vertical-line> characters in the +command argument of
3485 the ex, edit, next, vi, and visual commands, and in the pattern and
3486 replacement parts of the s command, did not delimit the command, and in
3487 the filter cases for read and write, and the !, global, and v commands,
3488 they did not delimit the command at all. For example, the following
3489 commands are all valid:
3490
3491 :edit +25 | s/abc/ABC/ file.c
3492 :s/ | /PIPE/
3493 :read !spell % | columnate
3494 :global/pattern/p | l
3495 :s/a/b/ | s/c/d | set
3496
3497 Historically, empty or <blank> filled lines in .exrc files and sourced
3498 files (as well as EXINIT variables and ex command scripts) were treated
3499 as default commands; that is, print commands. POSIX.1‐2008 specifically
3500 requires that they be ignored when encountered in .exrc and sourced
3501 files to eliminate a common source of new user error.
3502
3503 Historically, ex commands with multiple adjacent (or <blank>-separated)
3504 vertical lines were handled oddly when executed from ex mode. For exam‐
3505 ple, the command ||| <carriage-return>, when the cursor was on line 1,
3506 displayed lines 2, 3, and 5 of the file. In addition, the command |
3507 would only display the line after the next line, instead of the next
3508 two lines. The former worked more logically when executed from vi mode,
3509 and displayed lines 2, 3, and 4. POSIX.1‐2008 requires the vi behavior;
3510 that is, a single default command and line number increment for each
3511 command separator, and trailing <newline> characters after <vertical-
3512 line> separators are discarded.
3513
3514 Historically, ex permitted a single extra <colon> as a leading command
3515 character; for example, :g/pattern/:p was a valid command. POSIX.1‐2008
3516 generalizes this to require that any number of leading <colon> charac‐
3517 ters be stripped.
3518
3519 Historically, any prefix of the delete command could be followed with‐
3520 out intervening <blank> characters by a flag character because in the
3521 command d p, p is interpreted as the buffer p. POSIX.1‐2008 requires
3522 conformance to historical practice.
3523
3524 Historically, the k command could be followed by the mark name without
3525 intervening <blank> characters. POSIX.1‐2008 requires conformance to
3526 historical practice.
3527
3528 Historically, the s command could be immediately followed by flag and
3529 option characters; for example, s/e/E/|s|sgc3p was a valid command.
3530 However, flag characters could not stand alone; for example, the com‐
3531 mands sp and s l would fail, while the command sgp and s gl would suc‐
3532 ceed. (Obviously, the '#' flag character was used as a delimiter char‐
3533 acter if it followed the command.) Another issue was that option char‐
3534 acters had to precede flag characters even when the command was fully
3535 specified; for example, the command s/e/E/pg would fail, while the com‐
3536 mand s/e/E/gp would succeed. POSIX.1‐2008 requires conformance to his‐
3537 torical practice.
3538
3539 Historically, the first command name that had a prefix matching the
3540 input from the user was the executed command; for example, ve, ver, and
3541 vers all executed the version command. Commands were in a specific
3542 order, however, so that a matched append, not abbreviate. POSIX.1‐2008
3543 requires conformance to historical practice. The restriction on command
3544 search order for implementations with extensions is to avoid the addi‐
3545 tion of commands such that the historical prefixes would fail to work
3546 portably.
3547
3548 Historical implementations of ex and vi did not correctly handle multi‐
3549 ple ex commands, separated by <vertical-line> characters, that entered
3550 or exited visual mode or the editor. Because implementations of vi
3551 exist that do not exhibit this failure mode, POSIX.1‐2008 does not per‐
3552 mit it.
3553
3554 The requirement that alphabetic command names consist of all following
3555 alphabetic characters up to the next non-alphabetic character means
3556 that alphabetic command names must be separated from their arguments by
3557 one or more non-alphabetic characters, normally a <blank> or '!' char‐
3558 acter, except as specified for the exceptions, the delete, k, and s
3559 commands.
3560
3561 Historically, the repeated execution of the ex default print commands
3562 (<control>‐D, eof, <newline>, <carriage-return>) erased any prompting
3563 character and displayed the next lines without scrolling the terminal;
3564 that is, immediately below any previously displayed lines. This pro‐
3565 vided a cleaner presentation of the lines in the file for the user.
3566 POSIX.1‐2008 does not require this behavior because it may be impossi‐
3567 ble in some situations; however, implementations are strongly encour‐
3568 aged to provide this semantic if possible.
3569
3570 Historically, it was possible to change files in the middle of a com‐
3571 mand, and have the rest of the command executed in the new file; for
3572 example:
3573
3574 :edit +25 file.c | s/abc/ABC/ | 1
3575
3576 was a valid command, and the substitution was attempted in the newly
3577 edited file. POSIX.1‐2008 requires conformance to historical practice.
3578 The following commands are examples that exercise the ex parser:
3579
3580 echo 'foo | bar' > file1; echo 'foo/bar' > file2;
3581 vi
3582 :edit +1 | s/|/PIPE/ | w file1 | e file2 | 1 | s/\//SLASH/ | wq
3583
3584 Historically, there was no protection in editor implementations to
3585 avoid ex global, v, @, or * commands changing edit buffers during exe‐
3586 cution of their associated commands. Because this would almost invari‐
3587 ably result in catastrophic failure of the editor, and implementations
3588 exist that do exhibit these problems, POSIX.1‐2008 requires that chang‐
3589 ing the edit buffer during a global or v command, or during a @ or *
3590 command for which there will be more than a single execution, be an
3591 error. Implementations supporting multiple edit buffers simultaneously
3592 are strongly encouraged to apply the same semantics to switching
3593 between buffers as well.
3594
3595 The ex command quoting required by POSIX.1‐2008 is a superset of the
3596 quoting in historical implementations of the editor. For example, it
3597 was not historically possible to escape a <blank> in a filename; for
3598 example, :edit foo\\\ bar would report that too many filenames had been
3599 entered for the edit command, and there was no method of escaping a
3600 <blank> in the first argument of an edit, ex, next, or visual command
3601 at all. POSIX.1‐2008 extends historical practice, requiring that quot‐
3602 ing behavior be made consistent across all ex commands, except for the
3603 map, unmap, abbreviate, and unabbreviate commands, which historically
3604 used <control>‐V instead of <backslash> characters for quoting. For
3605 those four commands, POSIX.1‐2008 requires conformance to historical
3606 practice.
3607
3608 Backslash quoting in ex is non-intuitive. <backslash>-escapes are
3609 ignored unless they escape a special character; for example, when per‐
3610 forming file argument expansion, the string "\\%" is equivalent to
3611 '\%', not "\<current pathname>". This can be confusing for users
3612 because <backslash> is usually one of the characters that causes shell
3613 expansion to be performed, and therefore shell quoting rules must be
3614 taken into consideration. Generally, quoting characters are only con‐
3615 sidered if they escape a special character, and a quoting character
3616 must be provided for each layer of parsing for which the character is
3617 special. As another example, only a single <backslash> is necessary for
3618 the '\l' sequence in substitute replacement patterns, because the char‐
3619 acter 'l' is not special to any parsing layer above it.
3620
3621 <control>‐V quoting in ex is slightly different from backslash quoting.
3622 In the four commands where <control>‐V quoting applies (abbreviate,
3623 unabbreviate, map, and unmap), any character may be escaped by a <con‐
3624 trol>‐V whether it would have a special meaning or not. POSIX.1‐2008
3625 requires conformance to historical practice.
3626
3627 Historical implementations of the editor did not require delimiters
3628 within character classes to be escaped; for example, the command
3629 :s/[/]// on the string "xxx/yyy" would delete the '/' from the string.
3630 POSIX.1‐2008 disallows this historical practice for consistency and
3631 because it places a large burden on implementations by requiring that
3632 knowledge of regular expressions be built into the editor parser.
3633
3634 Historically, quoting <newline> characters in ex commands was handled
3635 inconsistently. In most cases, the <newline> character always termi‐
3636 nated the command, regardless of any preceding escape character,
3637 because <backslash> characters did not escape <newline> characters for
3638 most ex commands. However, some ex commands (for example, s, map, and
3639 abbreviation) permitted <newline> characters to be escaped (although in
3640 the case of map and abbreviation, <control>‐V characters escaped them
3641 instead of <backslash> characters). This was true in not only the com‐
3642 mand line, but also .exrc and sourced files. For example, the command:
3643
3644 map = foo<control-V><newline>bar
3645
3646 would succeed, although it was sometimes difficult to get the <con‐
3647 trol>‐V and the inserted <newline> passed to the ex parser. For consis‐
3648 tency and simplicity of specification, POSIX.1‐2008 requires that it be
3649 possible to escape <newline> characters in ex commands at all times,
3650 using <backslash> characters for most ex commands, and using <con‐
3651 trol>‐V characters for the map and abbreviation commands. For example,
3652 the command print<newline>list is required to be parsed as the single
3653 command print<newline>list. While this differs from historical prac‐
3654 tice, POSIX.1‐2008 developers believed it unlikely that any script or
3655 user depended on the historical behavior.
3656
3657 Historically, an error in a command specified using the −c option did
3658 not cause the rest of the −c commands to be discarded. POSIX.1‐2008
3659 disallows this for consistency with mapped keys, the @, global, source,
3660 and v commands, the EXINIT environment variable, and the .exrc files.
3661
3662 Input Editing in ex
3663 One of the common uses of the historical ex editor is over slow network
3664 connections. Editors that run in canonical mode can require far less
3665 traffic to and from, and far less processing on, the host machine, as
3666 well as more easily supporting block-mode terminals. For these reasons,
3667 POSIX.1‐2008 requires that ex be implemented using canonical mode input
3668 processing, as was done historically.
3669
3670 POSIX.1‐2008 does not require the historical 4 BSD input editing char‐
3671 acters ``word erase'' or ``literal next''. For this reason, it is
3672 unspecified how they are handled by ex, although they must have the
3673 required effect. Implementations that resolve them after the line has
3674 been ended using a <newline> or <control>‐M character, and implementa‐
3675 tions that rely on the underlying system terminal support for this pro‐
3676 cessing, are both conforming. Implementations are strongly urged to
3677 use the underlying system functionality, if at all possible, for com‐
3678 patibility with other system text input interfaces.
3679
3680 Historically, when the eof character was used to decrement the autoin‐
3681 dent level, the cursor moved to display the new end of the autoindent
3682 characters, but did not move the cursor to a new line, nor did it erase
3683 the <control>‐D character from the line. POSIX.1‐2008 does not specify
3684 that the cursor remain on the same line or that the rest of the line is
3685 erased; however, implementations are strongly encouraged to provide the
3686 best possible user interface; that is, the cursor should remain on the
3687 same line, and any <control>‐D character on the line should be erased.
3688
3689 POSIX.1‐2008 does not require the historical 4 BSD input editing char‐
3690 acter ``reprint'', traditionally <control>‐R, which redisplayed the
3691 current input from the user. For this reason, and because the function‐
3692 ality cannot be implemented after the line has been terminated by the
3693 user, POSIX.1‐2008 makes no requirements about this functionality.
3694 Implementations are strongly urged to make this historical functional‐
3695 ity available, if possible.
3696
3697 Historically, <control>‐Q did not perform a literal next function in
3698 ex, as it did in vi. POSIX.1‐2008 requires conformance to historical
3699 practice to avoid breaking historical ex scripts and .exrc files.
3700
3701 eof
3702 Whether the eof character immediately modifies the autoindent charac‐
3703 ters in the prompt is left unspecified so that implementations can con‐
3704 form in the presence of systems that do not support this functionality.
3705 Implementations are encouraged to modify the line and redisplay it
3706 immediately, if possible.
3707
3708 The specification of the handling of the eof character differs from
3709 historical practice only in that eof characters are not discarded if
3710 they follow normal characters in the text input. Historically, they
3711 were always discarded.
3712
3713 Command Descriptions in ex
3714 Historically, several commands (for example, global, v, visual, s,
3715 write, wq, yank, !, <, >, &, and ~) were executable in empty files
3716 (that is, the default address(es) were 0), or permitted explicit
3717 addresses of 0 (for example, 0 was a valid address, or 0,0 was a valid
3718 range). Addresses of 0, or command execution in an empty file, make
3719 sense only for commands that add new text to the edit buffer or write
3720 commands (because users may wish to write empty files). POSIX.1‐2008
3721 requires this behavior for such commands and disallows it otherwise,
3722 for consistency and simplicity of specification.
3723
3724 A count to an ex command has been historically corrected to be no
3725 greater than the last line in a file; for example, in a five-line file,
3726 the command 1,6print would fail, but the command 1print300 would suc‐
3727 ceed. POSIX.1‐2008 requires conformance to historical practice.
3728
3729 Historically, the use of flags in ex commands could be obscure. General
3730 historical practice was as described by POSIX.1‐2008, but there were
3731 some special cases. For instance, the list, number, and print commands
3732 ignored trailing address offsets; for example, 3p +++# would display
3733 line 3, and 3 would be the current line after the execution of the com‐
3734 mand. The open and visual commands ignored both the trailing offsets
3735 and the trailing flags. Also, flags specified to the open and visual
3736 commands interacted badly with the list edit option, and setting and
3737 then unsetting it during the open/visual session would cause vi to stop
3738 displaying lines in the specified format. For consistency and simplic‐
3739 ity of specification, POSIX.1‐2008 does not permit any of these excep‐
3740 tions to the general rule.
3741
3742 POSIX.1‐2008 uses the word copy in several places when discussing buf‐
3743 fers. This is not intended to imply implementation.
3744
3745 Historically, ex users could not specify numeric buffers because of the
3746 ambiguity this would cause; for example, in the command 3 delete 2, it
3747 is unclear whether 2 is a buffer name or a count. POSIX.1‐2008
3748 requires conformance to historical practice by default, but does not
3749 preclude extensions.
3750
3751 Historically, the contents of the unnamed buffer were frequently dis‐
3752 carded after commands that did not explicitly affect it; for example,
3753 when using the edit command to switch files. For consistency and sim‐
3754 plicity of specification, POSIX.1‐2008 does not permit this behavior.
3755
3756 The ex utility did not historically have access to the numeric buffers,
3757 and, furthermore, deleting lines in ex did not modify their contents.
3758 For example, if, after doing a delete in vi, the user switched to ex,
3759 did another delete, and then switched back to vi, the contents of the
3760 numeric buffers would not have changed. POSIX.1‐2008 requires confor‐
3761 mance to historical practice. Numeric buffers are described in the ex
3762 utility in order to confine the description of buffers to a single
3763 location in POSIX.1‐2008.
3764
3765 The metacharacters that trigger shell expansion in file arguments match
3766 historical practice, as does the method for doing shell expansion.
3767 Implementations wishing to provide users with the flexibility to alter
3768 the set of metacharacters are encouraged to provide a shellmeta string
3769 edit option.
3770
3771 Historically, ex commands executed from vi refreshed the screen when it
3772 did not strictly need to do so; for example, :!date > /dev/null does
3773 not require a screen refresh because the output of the UNIX date com‐
3774 mand requires only a single line of the screen. POSIX.1‐2008 requires
3775 that the screen be refreshed if it has been overwritten, but makes no
3776 requirements as to how an implementation should make that determina‐
3777 tion. Implementations may prompt and refresh the screen regardless.
3778
3779 Abbreviate
3780 Historical practice was that characters that were entered as part of an
3781 abbreviation replacement were subject to map expansions, the showmatch
3782 edit option, further abbreviation expansions, and so on; that is, they
3783 were logically pushed onto the terminal input queue, and were not a
3784 simple replacement. POSIX.1‐2008 requires conformance to historical
3785 practice. Historical practice was that whenever a non-word character
3786 (that had not been escaped by a <control>‐V) was entered after a word
3787 character, vi would check for abbreviations. The check was based on the
3788 type of the character entered before the word character of the
3789 word/non-word pair that triggered the check. The word character of the
3790 word/non-word pair that triggered the check and all characters entered
3791 before the trigger pair that were of that type were included in the
3792 check, with the exception of <blank> characters, which always delimited
3793 the abbreviation.
3794
3795 This means that, for the abbreviation to work, the lhs must end with a
3796 word character, there can be no transitions from word to non-word char‐
3797 acters (or vice versa) other than between the last and next-to-last
3798 characters in the lhs, and there can be no <blank> characters in the
3799 lhs. In addition, because of the historical quoting rules, it was
3800 impossible to enter a literal <control>‐V in the lhs. POSIX.1‐2008
3801 requires conformance to historical practice. Historical implementations
3802 did not inform users when abbreviations that could never be used were
3803 entered; implementations are strongly encouraged to do so.
3804
3805 For example, the following abbreviations will work:
3806
3807 :ab (p REPLACE
3808 :ab p REPLACE
3809 :ab ((p REPLACE
3810
3811 The following abbreviations will not work:
3812
3813 :ab ( REPLACE
3814 :ab (pp REPLACE
3815
3816 Historical practice is that words on the vi colon command line were
3817 subject to abbreviation expansion, including the arguments to the
3818 abbrev (and more interestingly) the unabbrev command. Because there are
3819 implementations that do not do abbreviation expansion for the first
3820 argument to those commands, this is permitted, but not required, by
3821 POSIX.1‐2008. However, the following sequence:
3822
3823 :ab foo bar
3824 :ab foo baz
3825
3826 resulted in the addition of an abbreviation of "baz" for the string
3827 "bar" in historical ex/vi, and the sequence:
3828
3829 :ab foo1 bar
3830 :ab foo2 bar
3831 :unabbreviate foo2
3832
3833 deleted the abbreviation "foo1", not "foo2". These behaviors are not
3834 permitted by POSIX.1‐2008 because they clearly violate the expectations
3835 of the user.
3836
3837 It was historical practice that <control>‐V, not <backslash>, charac‐
3838 ters be interpreted as escaping subsequent characters in the abbreviate
3839 command. POSIX.1‐2008 requires conformance to historical practice; how‐
3840 ever, it should be noted that an abbreviation containing a <blank> will
3841 never work.
3842
3843 Append
3844 Historically, any text following a <vertical-line> command separator
3845 after an append, change, or insert command became part of the insert
3846 text. For example, in the command:
3847
3848 :g/pattern/append|stuff1
3849
3850 a line containing the text "stuff1" would be appended to each line
3851 matching pattern. It was also historically valid to enter:
3852
3853 :append|stuff1
3854 stuff2
3855 .
3856
3857 and the text on the ex command line would be appended along with the
3858 text inserted after it. There was an historical bug, however, that the
3859 user had to enter two terminating lines (the '.' lines) to terminate
3860 text input mode in this case. POSIX.1‐2008 requires conformance to his‐
3861 torical practice, but disallows the historical need for multiple termi‐
3862 nating lines.
3863
3864 Change
3865 See the RATIONALE for the append command. Historical practice for cur‐
3866 sor positioning after the change command when no text is input, is as
3867 described in POSIX.1‐2008. However, one System V implementation is
3868 known to have been modified such that the cursor is positioned on the
3869 first address specified, and not on the line before the first address.
3870 POSIX.1‐2008 disallows this modification for consistency.
3871
3872 Historically, the change command did not support buffer arguments,
3873 although some implementations allow the specification of an optional
3874 buffer. This behavior is neither required nor disallowed by
3875 POSIX.1‐2008.
3876
3877 Change Directory
3878 A common extension in ex implementations is to use the elements of a
3879 cdpath edit option as prefix directories for path arguments to chdir
3880 that are relative pathnames and that do not have '.' or ".." as their
3881 first component. Elements in the cdpath edit option are <colon>-sepa‐
3882 rated. The initial value of the cdpath edit option is the value of the
3883 shell CDPATH environment variable. This feature was not included in
3884 POSIX.1‐2008 because it does not exist in any of the implementations
3885 considered historical practice.
3886
3887 Copy
3888 Historical implementations of ex permitted copies to lines inside of
3889 the specified range; for example, :2,5copy3 was a valid command.
3890 POSIX.1‐2008 requires conformance to historical practice.
3891
3892 Delete
3893 POSIX.1‐2008 requires support for the historical parsing of a delete
3894 command followed by flags, without any intervening <blank> characters.
3895 For example:
3896
3897 1dp Deletes the first line and prints the line that was second.
3898
3899 1delep As for 1dp.
3900
3901 1d Deletes the first line, saving it in buffer p.
3902
3903 1d p1l (Pee-one-ell.) Deletes the first line, saving it in buffer p,
3904 and listing the line that was second.
3905
3906 Edit
3907 Historically, any ex command could be entered as a +command argument to
3908 the edit command, although some (for example, insert and append) were
3909 known to confuse historical implementations. For consistency and sim‐
3910 plicity of specification, POSIX.1‐2008 requires that any command be
3911 supported as an argument to the edit command.
3912
3913 Historically, the command argument was executed with the current line
3914 set to the last line of the file, regardless of whether the edit com‐
3915 mand was executed from visual mode or not. POSIX.1‐2008 requires con‐
3916 formance to historical practice.
3917
3918 Historically, the +command specified to the edit and next commands was
3919 delimited by the first <blank>, and there was no way to quote them. For
3920 consistency, POSIX.1‐2008 requires that the usual ex backslash quoting
3921 be provided.
3922
3923 Historically, specifying the +command argument to the edit command
3924 required a filename to be specified as well; for example, :edit +100
3925 would always fail. For consistency and simplicity of specification,
3926 POSIX.1‐2008 does not permit this usage to fail for that reason.
3927
3928 Historically, only the cursor position of the last file edited was
3929 remembered by the editor. POSIX.1‐2008 requires that this be supported;
3930 however, implementations are permitted to remember and restore the cur‐
3931 sor position for any file previously edited.
3932
3933 File
3934 Historical versions of the ex editor file command displayed a current
3935 line and number of lines in the edit buffer of 0 when the file was
3936 empty, while the vi <control>‐G command displayed a current line and
3937 number of lines in the edit buffer of 1 in the same situation.
3938 POSIX.1‐2008 does not permit this discrepancy, instead requiring that a
3939 message be displayed indicating that the file is empty.
3940
3941 Global
3942 The two-pass operation of the global and v commands is not intended to
3943 imply implementation, only the required result of the operation.
3944
3945 The current line and column are set as specified for the individual ex
3946 commands. This requirement is cumulative; that is, the current line and
3947 column must track across all the commands executed by the global or v
3948 commands.
3949
3950 Insert
3951 See the RATIONALE for the append command.
3952
3953 Historically, insert could not be used with an address of zero; that
3954 is, not when the edit buffer was empty. POSIX.1‐2008 requires that this
3955 command behave consistently with the append command.
3956
3957 Join
3958 The action of the join command in relation to the special characters is
3959 only defined for the POSIX locale because the correct amount of white
3960 space after a period varies; in Japanese none is required, in French
3961 only a single space, and so on.
3962
3963 List
3964 The historical output of the list command was potentially ambiguous.
3965 The standard developers believed correcting this to be more important
3966 than adhering to historical practice, and POSIX.1‐2008 requires unam‐
3967 biguous output.
3968
3969 Map
3970 Historically, command mode maps only applied to command names; for
3971 example, if the character 'x' was mapped to 'y', the command fx
3972 searched for the 'x' character, not the 'y' character. POSIX.1‐2008
3973 requires this behavior. Historically, entering <control>‐V as the first
3974 character of a vi command was an error. Several implementations have
3975 extended the semantics of vi such that <control>‐V means that the sub‐
3976 sequent command character is not mapped. This is permitted, but not
3977 required, by POSIX.1‐2008. Regardless, using <control>‐V to escape the
3978 second or later character in a sequence of characters that might match
3979 a map command, or any character in text input mode, is historical prac‐
3980 tice, and stops the entered keys from matching a map. POSIX.1‐2008
3981 requires conformance to historical practice.
3982
3983 Historical implementations permitted digits to be used as a map command
3984 lhs, but then ignored the map. POSIX.1‐2008 requires that the mapped
3985 digits not be ignored.
3986
3987 The historical implementation of the map command did not permit map
3988 commands that were more than a single character in length if the first
3989 character was printable. This behavior is permitted, but not required,
3990 by POSIX.1‐2008.
3991
3992 Historically, mapped characters were remapped unless the remap edit
3993 option was not set, or the prefix of the mapped characters matched the
3994 mapping characters; for example, in the map:
3995
3996 :map ab abcd
3997
3998 the characters "ab" were used as is and were not remapped, but the
3999 characters "cd" were mapped if appropriate. This can cause infinite
4000 loops in the vi mapping mechanisms. POSIX.1‐2008 requires conformance
4001 to historical practice, and that such loops be interruptible.
4002
4003 Text input maps had the same problems with expanding the lhs for the ex
4004 map! and unmap! command as did the ex abbreviate and unabbreviate
4005 commands. See the RATIONALE for the ex abbreviate command. POSIX.1‐2008
4006 requires similar modification of some historical practice for the map
4007 and unmap commands, as described for the abbreviate and unabbreviate
4008 commands.
4009
4010 Historically, maps that were subsets of other maps behaved differently
4011 depending on the order in which they were defined. For example:
4012
4013 :map! ab short
4014 :map! abc long
4015
4016 would always translate the characters "ab" to "short", regardless of
4017 how fast the characters "abc" were entered. If the entry order was
4018 reversed:
4019
4020 :map! abc long
4021 :map! ab short
4022
4023 the characters "ab" would cause the editor to pause, waiting for the
4024 completing 'c' character, and the characters might never be mapped to
4025 "short". For consistency and simplicity of specification, POSIX.1‐2008
4026 requires that the shortest match be used at all times.
4027
4028 The length of time the editor spends waiting for the characters to com‐
4029 plete the lhs is unspecified because the timing capabilities of systems
4030 are often inexact and variable, and it may depend on other factors such
4031 as the speed of the connection. The time should be long enough for the
4032 user to be able to complete the sequence, but not long enough for the
4033 user to have to wait. Some implementations of vi have added a keytime
4034 option, which permits users to set the number of 0,1 seconds the editor
4035 waits for the completing characters. Because mapped terminal function
4036 and cursor keys tend to start with an <ESC> character, and <ESC> is the
4037 key ending vi text input mode, maps starting with <ESC> characters are
4038 generally exempted from this timeout period, or, at least timed out
4039 differently.
4040
4041 Mark
4042 Historically, users were able to set the ``previous context'' marks
4043 explicitly. In addition, the ex commands '' and '` and the vi commands
4044 '', ``, `', and '` all referred to the same mark. In addition, the pre‐
4045 vious context marks were not set if the command, with which the address
4046 setting the mark was associated, failed. POSIX.1‐2008 requires confor‐
4047 mance to historical practice. Historically, if marked lines were
4048 deleted, the mark was also deleted, but would reappear if the change
4049 was undone. POSIX.1‐2008 requires conformance to historical practice.
4050
4051 The description of the special events that set the ` and ' marks
4052 matches historical practice. For example, historically the command
4053 /a/,/b/ did not set the ` and ' marks, but the command /a/,/b/delete
4054 did.
4055
4056 Next
4057 Historically, any ex command could be entered as a +command argument to
4058 the next command, although some (for example, insert and append) were
4059 known to confuse historical implementations. POSIX.1‐2008 requires that
4060 any command be permitted and that it behave as specified. The next com‐
4061 mand can accept more than one file, so usage such as:
4062
4063 next `ls [abc] `
4064
4065 is valid; it need not be valid for the edit or read commands, for exam‐
4066 ple, because they expect only one filename.
4067
4068 Historically, the next command behaved differently from the :rewind
4069 command in that it ignored the force flag if the autowrite flag was
4070 set. For consistency, POSIX.1‐2008 does not permit this behavior.
4071
4072 Historically, the next command positioned the cursor as if the file had
4073 never been edited before, regardless. POSIX.1‐2008 does not permit this
4074 behavior, for consistency with the edit command.
4075
4076 Implementations wanting to provide a counterpart to the next command
4077 that edited the previous file have used the command prev[ious], which
4078 takes no file argument. POSIX.1‐2008 does not require this command.
4079
4080 Open
4081 Historically, the open command would fail if the open edit option was
4082 not set. POSIX.1‐2008 does not mention the open edit option and does
4083 not require this behavior. Some historical implementations do not per‐
4084 mit entering open mode from open or visual mode, only from ex mode. For
4085 consistency, POSIX.1‐2008 does not permit this behavior.
4086
4087 Historically, entering open mode from the command line (that is, vi
4088 +open) resulted in anomalous behaviors; for example, the ex file and
4089 set commands, and the vi command <control>‐G did not work. For consis‐
4090 tency, POSIX.1‐2008 does not permit this behavior.
4091
4092 Historically, the open command only permitted '/' characters to be used
4093 as the search pattern delimiter. For consistency, POSIX.1‐2008 requires
4094 that the search delimiters used by the s, global, and v commands be
4095 accepted as well.
4096
4097 Preserve
4098 The preserve command does not historically cause the file to be consid‐
4099 ered unmodified for the purposes of future commands that may exit the
4100 editor. POSIX.1‐2008 requires conformance to historical practice.
4101
4102 Historical documentation stated that mail was not sent to the user when
4103 preserve was executed; however, historical implementations did send
4104 mail in this case. POSIX.1‐2008 requires conformance to the historical
4105 implementations.
4106
4107 Print
4108 The writing of NUL by the print command is not specified as a special
4109 case because the standard developers did not want to require ex to sup‐
4110 port NUL characters. Historically, characters were displayed using the
4111 ARPA standard mappings, which are as follows:
4112
4113 1. Printable characters are left alone.
4114
4115 2. Control characters less than \177 are represented as '^' followed
4116 by the character offset from the '@' character in the ASCII map;
4117 for example, \007 is represented as '^G'.
4118
4119 3. \177 is represented as '^' followed by '?'.
4120
4121 The display of characters having their eighth bit set was less stan‐
4122 dard. Existing implementations use hex (0x00), octal (\000), and a
4123 meta-bit display. (The latter displayed bytes that had their eighth bit
4124 set as the two characters "M−" followed by the seven-bit display as
4125 described above.) The latter probably has the best claim to historical
4126 practice because it was used for the −v option of 4 BSD and 4 BSD-
4127 derived versions of the cat utility since 1980.
4128
4129 No specific display format is required by POSIX.1‐2008.
4130
4131 Explicit dependence on the ASCII character set has been avoided where
4132 possible, hence the use of the phrase an ``implementation-defined
4133 multi-character sequence'' for the display of non-printable characters
4134 in preference to the historical usage of, for instance, "^I" for the
4135 <tab>. Implementations are encouraged to conform to historical prac‐
4136 tice in the absence of any strong reason to diverge.
4137
4138 Historically, all ex commands beginning with the letter 'p' could be
4139 entered using capitalized versions of the commands; for example,
4140 P[rint], Pre[serve], and Pu[t] were all valid command names.
4141 POSIX.1‐2008 permits, but does not require, this historical practice
4142 because capital forms of the commands are used by some implementations
4143 for other purposes.
4144
4145 Put
4146 Historically, an ex put command, executed from open or visual mode, was
4147 the same as the open or visual mode P command, if the buffer was named
4148 and was cut in character mode, and the same as the p command if the
4149 buffer was named and cut in line mode. If the unnamed buffer was the
4150 source of the text, the entire line from which the text was taken was
4151 usually put, and the buffer was handled as if in line mode, but it was
4152 possible to get extremely anomalous behavior. In addition, using the Q
4153 command to switch into ex mode, and then doing a put often resulted in
4154 errors as well, such as appending text that was unrelated to the (sup‐
4155 posed) contents of the buffer. For consistency and simplicity of speci‐
4156 fication, POSIX.1‐2008 does not permit these behaviors. All ex put com‐
4157 mands are required to operate in line mode, and the contents of the
4158 buffers are not altered by changing the mode of the editor.
4159
4160 Read
4161 Historically, an ex read command executed from open or visual mode,
4162 executed in an empty file, left an empty line as the first line of the
4163 file. For consistency and simplicity of specification, POSIX.1‐2008
4164 does not permit this behavior. Historically, a read in open or visual
4165 mode from a program left the cursor at the last line read in, not the
4166 first. For consistency, POSIX.1‐2008 does not permit this behavior.
4167
4168 Historical implementations of ex were unable to undo read commands that
4169 read from the output of a program. For consistency, POSIX.1‐2008 does
4170 not permit this behavior.
4171
4172 Historically, the ex and vi message after a successful read or write
4173 command specified ``characters'', not ``bytes''. POSIX.1‐2008 requires
4174 that the number of bytes be displayed, not the number of characters,
4175 because it may be difficult in multi-byte implementations to determine
4176 the number of characters read. Implementations are encouraged to clar‐
4177 ify the message displayed to the user.
4178
4179 Historically, reads were not permitted on files other than type regu‐
4180 lar, except that FIFO files could be read (probably only because they
4181 did not exist when ex and vi were originally written). Because the his‐
4182 torical ex evaluated read! and read ! equivalently, there can be no
4183 optional way to force the read. POSIX.1‐2008 permits, but does not
4184 require, this behavior.
4185
4186 Recover
4187 Some historical implementations of the editor permitted users to
4188 recover the edit buffer contents from a previous edit session, and then
4189 exit without saving those contents (or explicitly discarding them). The
4190 intent of POSIX.1‐2008 in requiring that the edit buffer be treated as
4191 already modified is to prevent this user error.
4192
4193 Rewind
4194 Historical implementations supported the rewind command when the user
4195 was editing the first file in the list; that is, the file that the
4196 rewind command would edit. POSIX.1‐2008 requires conformance to histor‐
4197 ical practice.
4198
4199 Substitute
4200 Historically, ex accepted an r option to the s command. The effect of
4201 the r option was to use the last regular expression used in any command
4202 as the pattern, the same as the ~ command. The r option is not required
4203 by POSIX.1‐2008. Historically, the c and g options were toggled; for
4204 example, the command :s/abc/def/ was the same as s/abc/def/ccccgggg.
4205 For simplicity of specification, POSIX.1‐2008 does not permit this
4206 behavior.
4207
4208 The tilde command is often used to replace the last search RE. For
4209 example, in the sequence:
4210
4211 s/red/blue/
4212 /green
4213 ~
4214
4215 the ~ command is equivalent to:
4216
4217 s/green/blue/
4218
4219 Historically, ex accepted all of the following forms:
4220
4221 s/abc/def/
4222 s/abc/def
4223 s/abc/
4224 s/abc
4225
4226 POSIX.1‐2008 requires conformance to this historical practice.
4227
4228 The s command presumes that the '^' character only occupies a single
4229 column in the display. Much of the ex and vi specification presumes
4230 that the <space> only occupies a single column in the display. There
4231 are no known character sets for which this is not true.
4232
4233 Historically, the final column position for the substitute commands was
4234 based on previous column movements; a search for a pattern followed by
4235 a substitution would leave the column position unchanged, while a 0
4236 command followed by a substitution would change the column position to
4237 the first non-<blank>. For consistency and simplicity of specifica‐
4238 tion, POSIX.1‐2008 requires that the final column position always be
4239 set to the first non-<blank>.
4240
4241 Set
4242 Historical implementations redisplayed all of the options for each
4243 occurrence of the all keyword. POSIX.1‐2008 permits, but does not
4244 require, this behavior.
4245
4246 Tag
4247 No requirement is made as to where ex and vi shall look for the file
4248 referenced by the tag entry. Historical practice has been to look for
4249 the path found in the tags file, based on the current directory. A use‐
4250 ful extension found in some implementations is to look based on the
4251 directory containing the tags file that held the entry, as well. No
4252 requirement is made as to which reference for the tag in the tags file
4253 is used. This is deliberate, in order to permit extensions such as mul‐
4254 tiple entries in a tags file for a tag.
4255
4256 Because users often specify many different tags files, some of which
4257 need not be relevant or exist at any particular time, POSIX.1‐2008
4258 requires that error messages about problem tags files be displayed only
4259 if the requested tag is not found, and then, only once for each time
4260 that the tag edit option is changed.
4261
4262 The requirement that the current edit buffer be unmodified is only nec‐
4263 essary if the file indicated by the tag entry is not the same as the
4264 current file (as defined by the current pathname). Historically, the
4265 file would be reloaded if the filename had changed, as well as if the
4266 filename was different from the current pathname. For consistency and
4267 simplicity of specification, POSIX.1‐2008 does not permit this behav‐
4268 ior, requiring that the name be the only factor in the decision.
4269
4270 Historically, vi only searched for tags in the current file from the
4271 current cursor to the end of the file, and therefore, if the wrapscan
4272 option was not set, tags occurring before the current cursor were not
4273 found. POSIX.1‐2008 considers this a bug, and implementations are
4274 required to search for the first occurrence in the file, regardless.
4275
4276 Undo
4277 The undo description deliberately uses the word ``modified''. The undo
4278 command is not intended to undo commands that replace the contents of
4279 the edit buffer, such as edit, next, tag, or recover.
4280
4281 Cursor positioning after the undo command was inconsistent in the his‐
4282 torical vi, sometimes attempting to restore the original cursor posi‐
4283 tion (global, undo, and v commands), and sometimes, in the presence of
4284 maps, placing the cursor on the last line added or changed instead of
4285 the first. POSIX.1‐2008 requires a simplified behavior for consistency
4286 and simplicity of specification.
4287
4288 Version
4289 The version command cannot be exactly specified since there is no
4290 widely-accepted definition of what the version information should con‐
4291 tain. Implementations are encouraged to do something reasonably intel‐
4292 ligent.
4293
4294 Write
4295 Historically, the ex and vi message after a successful read or write
4296 command specified ``characters'', not ``bytes''. POSIX.1‐2008 requires
4297 that the number of bytes be displayed, not the number of characters
4298 because it may be difficult in multi-byte implementations to determine
4299 the number of characters written. Implementations are encouraged to
4300 clarify the message displayed to the user.
4301
4302 Implementation-defined tests are permitted so that implementations can
4303 make additional checks; for example, for locks or file modification
4304 times.
4305
4306 Historically, attempting to append to a nonexistent file caused an
4307 error. It has been left unspecified in POSIX.1‐2008 to permit implemen‐
4308 tations to let the write succeed, so that the append semantics are sim‐
4309 ilar to those of the historical csh.
4310
4311 Historical vi permitted empty edit buffers to be written. However,
4312 since the way vi got around dealing with ``empty'' files was to always
4313 have a line in the edit buffer, no matter what, it wrote them as files
4314 of a single, empty line. POSIX.1‐2008 does not permit this behavior.
4315
4316 Historically, ex restored standard output and standard error to their
4317 values as of when ex was invoked, before writes to programs were per‐
4318 formed. This could disturb the terminal configuration as well as be a
4319 security issue for some terminals. POSIX.1‐2008 does not permit this,
4320 requiring that the program output be captured and displayed as if by
4321 the ex print command.
4322
4323 Adjust Window
4324 Historically, the line count was set to the value of the scroll option
4325 if the type character was end-of-file. This feature was broken on most
4326 historical implementations long ago, however, and is not documented
4327 anywhere. For this reason, POSIX.1‐2008 is resolutely silent.
4328
4329 Historically, the z command was <blank>-sensitive and z + and z − did
4330 different things than z+ and z− because the type could not be distin‐
4331 guished from a flag. (The commands z . and z = were historically
4332 invalid.) POSIX.1‐2008 requires conformance to this historical prac‐
4333 tice.
4334
4335 Historically, the z command was further <blank>-sensitive in that the
4336 count could not be <blank>-delimited; for example, the commands z= 5
4337 and z− 5 were also invalid. Because the count is not ambiguous with
4338 respect to either the type character or the flags, this is not permit‐
4339 ted by POSIX.1‐2008.
4340
4341 Escape
4342 Historically, ex filter commands only read the standard output of the
4343 commands, letting standard error appear on the terminal as usual. The
4344 vi utility, however, read both standard output and standard error.
4345 POSIX.1‐2008 requires the latter behavior for both ex and vi, for con‐
4346 sistency.
4347
4348 Shift Left and Shift Right
4349 Historically, it was possible to add shift characters to increase the
4350 effect of the command; for example, <<< outdented (or >>> indented) the
4351 lines 3 levels of indentation instead of the default 1. POSIX.1‐2008
4352 requires conformance to historical practice.
4353
4354 <control>‐D
4355 Historically, the <control>‐D command erased the prompt, providing the
4356 user with an unbroken presentation of lines from the edit buffer. This
4357 is not required by POSIX.1‐2008; implementations are encouraged to pro‐
4358 vide it if possible. Historically, the <control>‐D command took, and
4359 then ignored, a count. POSIX.1‐2008 does not permit this behavior.
4360
4361 Write Line Number
4362 Historically, the ex = command, when executed in ex mode in an empty
4363 edit buffer, reported 0, and from open or visual mode, reported 1. For
4364 consistency and simplicity of specification, POSIX.1‐2008 does not per‐
4365 mit this behavior.
4366
4367 Execute
4368 Historically, ex did not correctly handle the inclusion of text input
4369 commands (that is, append, insert, and change) in executed buffers.
4370 POSIX.1‐2008 does not permit this exclusion for consistency.
4371
4372 Historically, the logical contents of the buffer being executed did not
4373 change if the buffer itself were modified by the commands being exe‐
4374 cuted; that is, buffer execution did not support self-modifying code.
4375 POSIX.1‐2008 requires conformance to historical practice.
4376
4377 Historically, the @ command took a range of lines, and the @ buffer was
4378 executed once per line, with the current line ('.') set to each speci‐
4379 fied line. POSIX.1‐2008 requires conformance to historical practice.
4380
4381 Some historical implementations did not notice if errors occurred dur‐
4382 ing buffer execution. This, coupled with the ability to specify a range
4383 of lines for the ex @ command, makes it trivial to cause them to drop
4384 core. POSIX.1‐2008 requires that implementations stop buffer execution
4385 if any error occurs, if the specified line doesn't exist, or if the
4386 contents of the edit buffer itself are replaced (for example, the buf‐
4387 fer executes the ex :edit command).
4388
4389 Regular Expressions in ex
4390 Historical practice is that the characters in the replacement part of
4391 the last s command—that is, those matched by entering a '~' in the reg‐
4392 ular expression—were not further expanded by the regular expression
4393 engine. So, if the characters contained the string "a.," they would
4394 match 'a' followed by ".," and not 'a' followed by any character.
4395 POSIX.1‐2008 requires conformance to historical practice.
4396
4397 Edit Options in ex
4398 The following paragraphs describe the historical behavior of some edit
4399 options that were not, for whatever reason, included in POSIX.1‐2008.
4400 Implementations are strongly encouraged to only use these names if the
4401 functionality described here is fully supported.
4402
4403 extended The extended edit option has been used in some implementa‐
4404 tions of vi to provide extended regular expressions instead
4405 of basic regular expressions This option was omitted from
4406 POSIX.1‐2008 because it is not widespread historical prac‐
4407 tice.
4408
4409 flash The flash edit option historically caused the screen to flash
4410 instead of beeping on error. This option was omitted from
4411 POSIX.1‐2008 because it is not found in some historical
4412 implementations.
4413
4414 hardtabs The hardtabs edit option historically defined the number of
4415 columns between hardware tab settings. This option was omit‐
4416 ted from POSIX.1‐2008 because it was believed to no longer be
4417 generally useful.
4418
4419 modeline The modeline (sometimes named modelines) edit option histori‐
4420 cally caused ex or vi to read the five first and last lines
4421 of the file for editor commands. This option is a security
4422 problem, and vendors are strongly encouraged to delete it
4423 from historical implementations.
4424
4425 open The open edit option historically disallowed the ex open and
4426 visual commands. This edit option was omitted because these
4427 commands are required by POSIX.1‐2008.
4428
4429 optimize The optimize edit option historically expedited text through‐
4430 put by setting the terminal to not do automatic <carriage-
4431 return> characters when printing more than one logical line
4432 of output. This option was omitted from POSIX.1‐2008 because
4433 it was intended for terminals without addressable cursors,
4434 which are rarely, if ever, still used.
4435
4436 ruler The ruler edit option has been used in some implementations
4437 of vi to present a current row/column ruler for the user.
4438 This option was omitted from POSIX.1‐2008 because it is not
4439 widespread historical practice.
4440
4441 sourceany The sourceany edit option historically caused ex or vi to
4442 source start-up files that were owned by users other than the
4443 user running the editor. This option is a security problem,
4444 and vendors are strongly encouraged to remove it from their
4445 implementations.
4446
4447 timeout The timeout edit option historically enabled the (now stan‐
4448 dard) feature of only waiting for a short period before
4449 returning keys that could be part of a macro. This feature
4450 was omitted from POSIX.1‐2008 because its behavior is now
4451 standard, it is not widely useful, and it was rarely docu‐
4452 mented.
4453
4454 verbose The verbose edit option has been used in some implementations
4455 of vi to cause vi to output error messages for common errors;
4456 for example, attempting to move the cursor past the beginning
4457 or end of the line instead of only alerting the screen. (The
4458 historical vi only alerted the terminal and presented no mes‐
4459 sage for such errors. The historical editor option terse did
4460 not select when to present error messages, it only made
4461 existing error messages more or less verbose.) This option
4462 was omitted from POSIX.1‐2008 because it is not widespread
4463 historical practice; however, implementors are encouraged to
4464 use it if they wish to provide error messages for naive
4465 users.
4466
4467 wraplen The wraplen edit option has been used in some implementations
4468 of vi to specify an automatic margin measured from the left
4469 margin instead of from the right margin. This is useful when
4470 multiple screen sizes are being used to edit a single file.
4471 This option was omitted from POSIX.1‐2008 because it is not
4472 widespread historical practice; however, implementors are
4473 encouraged to use it if they add this functionality.
4474
4475 autoindent, ai
4476 Historically, the command 0a did not do any autoindentation, regardless
4477 of the current indentation of line 1. POSIX.1‐2008 requires that any
4478 indentation present in line 1 be used.
4479
4480 autoprint, ap
4481 Historically, the autoprint edit option was not completely consistent
4482 or based solely on modifications to the edit buffer. Exceptions were
4483 the read command (when reading from a file, but not from a filter), the
4484 append, change, insert, global, and v commands, all of which were not
4485 affected by autoprint, and the tag command, which was affected by auto‐
4486 print. POSIX.1‐2008 requires conformance to historical practice.
4487
4488 Historically, the autoprint option only applied to the last of multiple
4489 commands entered using <vertical-line> delimiters; for example, delete
4490 <newline> was affected by autoprint, but delete|version <newline> was
4491 not. POSIX.1‐2008 requires conformance to historical practice.
4492
4493 autowrite, aw
4494 Appending the '!' character to the ex next command to avoid performing
4495 an automatic write was not supported in historical implementations.
4496 POSIX.1‐2008 requires that the behavior match the other ex commands for
4497 consistency.
4498
4499 ignorecase, ic
4500 Historical implementations of case-insensitive matching (the ignorecase
4501 edit option) lead to counter-intuitive situations when uppercase char‐
4502 acters were used in range expressions. Historically, the process was as
4503 follows:
4504
4505 1. Take a line of text from the edit buffer.
4506
4507 2. Convert uppercase to lowercase in text line.
4508
4509 3. Convert uppercase to lowercase in regular expressions, except in
4510 character class specifications.
4511
4512 4. Match regular expressions against text.
4513
4514 This would mean that, with ignorecase in effect, the text:
4515
4516 The cat sat on the mat
4517
4518 would be matched by
4519
4520 /^the/
4521
4522 but not by:
4523
4524 /^[A−Z]he/
4525
4526 For consistency with other commands implementing regular expressions,
4527 POSIX.1‐2008 does not permit this behavior.
4528
4529 paragraphs, para
4530 The ISO POSIX‐2:1993 standard made the default paragraphs and sections
4531 edit options implementation-defined, arguing they were historically
4532 oriented to the UNIX system troff text formatter, and a ``portable
4533 user'' could use the {, }, [[, ]], (, and ) commands in open or visual
4534 mode and have the cursor stop in unexpected places. POSIX.1‐2008 speci‐
4535 fies their values in the POSIX locale because the unusual grouping
4536 (they only work when grouped into two characters at a time) means that
4537 they cannot be used for general-purpose movement, regardless.
4538
4539 readonly
4540 Implementations are encouraged to provide the best possible information
4541 to the user as to the read-only status of the file, with the exception
4542 that they should not consider the current special privileges of the
4543 process. This provides users with a safety net because they must force
4544 the overwrite of read-only files, even when running with additional
4545 privileges.
4546
4547 The readonly edit option specification largely conforms to historical
4548 practice. The only difference is that historical implementations did
4549 not notice that the user had set the readonly edit option in cases
4550 where the file was already marked read-only for some reason, and would
4551 therefore reinitialize the readonly edit option the next time the con‐
4552 tents of the edit buffer were replaced. This behavior is disallowed by
4553 POSIX.1‐2008.
4554
4555 report
4556 The requirement that lines copied to a buffer interact differently than
4557 deleted lines is historical practice. For example, if the report edit
4558 option is set to 3, deleting 3 lines will cause a report to be written,
4559 but 4 lines must be copied before a report is written.
4560
4561 The requirement that the ex global, v, open, undo, and visual commands
4562 present reports based on the total number of lines added or deleted
4563 during the command execution, and that commands executed by the global
4564 and v commands not present reports, is historical practice.
4565 POSIX.1‐2008 extends historical practice by requiring that buffer exe‐
4566 cution be treated similarly. The reasons for this are two-fold. Histor‐
4567 ically, only the report by the last command executed from the buffer
4568 would be seen by the user, as each new report would overwrite the last.
4569 In addition, the standard developers believed that buffer execution had
4570 more in common with global and v commands than it did with other ex
4571 commands, and should behave similarly, for consistency and simplicity
4572 of specification.
4573
4574 showmatch, sm
4575 The length of time the cursor spends on the matching character is
4576 unspecified because the timing capabilities of systems are often inex‐
4577 act and variable. The time should be long enough for the user to
4578 notice, but not long enough for the user to become annoyed. Some imple‐
4579 mentations of vi have added a matchtime option that permits users to
4580 set the number of 0,1 second intervals the cursor pauses on the match‐
4581 ing character.
4582
4583 showmode
4584 The showmode option has been used in some historical implementations of
4585 ex and vi to display the current editing mode when in open or visual
4586 mode. The editing modes have generally included ``command'' and
4587 ``input'', and sometimes other modes such as ``replace'' and
4588 ``change''. The string was usually displayed on the bottom line of the
4589 screen at the far right-hand corner. In addition, a preceding '*' char‐
4590 acter often denoted whether the contents of the edit buffer had been
4591 modified. The latter display has sometimes been part of the showmode
4592 option, and sometimes based on another option. This option was not
4593 available in the 4 BSD historical implementation of vi, but was viewed
4594 as generally useful, particularly to novice users, and is required by
4595 POSIX.1‐2008.
4596
4597 The smd shorthand for the showmode option was not present in all his‐
4598 torical implementations of the editor. POSIX.1‐2008 requires it, for
4599 consistency.
4600
4601 Not all historical implementations of the editor displayed a mode
4602 string for command mode, differentiating command mode from text input
4603 mode by the absence of a mode string. POSIX.1‐2008 permits this behav‐
4604 ior for consistency with historical practice, but implementations are
4605 encouraged to provide a display string for both modes.
4606
4607 slowopen
4608 Historically, the slowopen option was automatically set if the terminal
4609 baud rate was less than 1200 baud, or if the baud rate was 1200 baud
4610 and the redraw option was not set. The slowopen option had two effects.
4611 First, when inserting characters in the middle of a line, characters
4612 after the cursor would not be pushed ahead, but would appear to be
4613 overwritten. Second, when creating a new line of text, lines after the
4614 current line would not be scrolled down, but would appear to be over‐
4615 written. In both cases, ending text input mode would cause the screen
4616 to be refreshed to match the actual contents of the edit buffer.
4617 Finally, terminals that were sufficiently intelligent caused the editor
4618 to ignore the slowopen option. POSIX.1‐2008 permits most historical
4619 behavior, extending historical practice to require slowopen behaviors
4620 if the edit option is set by the user.
4621
4622 tags
4623 The default path for tags files is left unspecified as implementations
4624 may have their own tags implementations that do not correspond to the
4625 historical ones. The default tags option value should probably at least
4626 include the file ./tags.
4627
4628 term
4629 Historical implementations of ex and vi ignored changes to the term
4630 edit option after the initial terminal information was loaded. This is
4631 permitted by POSIX.1‐2008; however, implementations are encouraged to
4632 permit the user to modify their terminal type at any time.
4633
4634 terse
4635 Historically, the terse edit option optionally provided a shorter, less
4636 descriptive error message, for some error messages. This is permitted,
4637 but not required, by POSIX.1‐2008. Historically, most common visual
4638 mode errors (for example, trying to move the cursor past the end of a
4639 line) did not result in an error message, but simply alerted the termi‐
4640 nal. Implementations wishing to provide messages for novice users are
4641 urged to do so based on the edit option verbose, and not terse.
4642
4643 window
4644 In historical implementations, the default for the window edit option
4645 was based on the baud rate as follows:
4646
4647 1. If the baud rate was less than 1200, the edit option w300 set the
4648 window value; for example, the line:
4649
4650 set w300=12
4651
4652 would set the window option to 12 if the baud rate was less than
4653 1200.
4654
4655 2. If the baud rate was equal to 1200, the edit option w1200 set the
4656 window value.
4657
4658 3. If the baud rate was greater than 1200, the edit option w9600 set
4659 the window value.
4660
4661 The w300, w1200, and w9600 options do not appear in POSIX.1‐2008
4662 because of their dependence on specific baud rates.
4663
4664 In historical implementations, the size of the window displayed by var‐
4665 ious commands was related to, but not necessarily the same as, the win‐
4666 dow edit option. For example, the size of the window was set by the ex
4667 command visual 10, but it did not change the value of the window edit
4668 option. However, changing the value of the window edit option did
4669 change the number of lines that were displayed when the screen was
4670 repainted. POSIX.1‐2008 does not permit this behavior in the interests
4671 of consistency and simplicity of specification, and requires that all
4672 commands that change the number of lines that are displayed do it by
4673 setting the value of the window edit option.
4674
4675 wrapmargin, wm
4676 Historically, the wrapmargin option did not affect maps inserting char‐
4677 acters that also had associated counts; for example :map K 5aABC DEF.
4678 Unfortunately, there are widely used maps that depend on this behavior.
4679 For consistency and simplicity of specification, POSIX.1‐2008 does not
4680 permit this behavior.
4681
4682 Historically, wrapmargin was calculated using the column display width
4683 of all characters on the screen. For example, an implementation using
4684 "^I" to represent <tab> characters when the list edit option was set,
4685 where '^' and 'I' each took up a single column on the screen, would
4686 calculate the wrapmargin based on a value of 2 for each <tab>. The
4687 number edit option similarly changed the effective length of the line
4688 as well. POSIX.1‐2008 requires conformance to historical practice.
4689
4690 Earlier versions of this standard allowed for implementations with
4691 bytes other than eight bits, but this has been modified in this ver‐
4692 sion.
4693
4695 None.
4696
4698 Section 2.9.1.1, Command Search and Execution, ctags, ed, sed, sh,
4699 stty, vi
4700
4701 The Base Definitions volume of POSIX.1‐2008, Table 5-1, Escape
4702 Sequences and Associated Actions, Chapter 8, Environment Variables,
4703 Section 9.3, Basic Regular Expressions, Section 12.2, Utility Syntax
4704 Guidelines
4705
4706 The System Interfaces volume of POSIX.1‐2008, access()
4707
4709 Portions of this text are reprinted and reproduced in electronic form
4710 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
4711 -- Portable Operating System Interface (POSIX), The Open Group Base
4712 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
4713 cal and Electronics Engineers, Inc and The Open Group. (This is
4714 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
4715 event of any discrepancy between this version and the original IEEE and
4716 The Open Group Standard, the original IEEE and The Open Group Standard
4717 is the referee document. The original Standard can be obtained online
4718 at http://www.unix.org/online.html .
4719
4720 Any typographical or formatting errors that appear in this page are
4721 most likely to have been introduced during the conversion of the source
4722 files to man page format. To report such errors, see https://www.ker‐
4723 nel.org/doc/man-pages/reporting_bugs.html .
4724
4725
4726
4727IEEE/The Open Group 2013 EX(1P)