Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   ex.1p    ( 1 )

текстовый редактор (text editor)

Расширенное описание (Extended description)

Only the ex mode of the editor is described in this section. See vi(1p) for additional editing capabilities available in ex.

When an error occurs, ex shall write a message. If the terminal supports a standout mode (such as inverse video), the message shall be written in standout mode. If the terminal does not support a standout mode, and the edit option errorbells is set, an alert action shall precede the error message.

By default, ex shall start in command mode, which shall be indicated by a : prompt; see the prompt command. Text input mode can be entered by the append, insert, or change commands; it can be exited (and command mode re-entered) by typing a <period> ('.') alone at the beginning of a line.

Initialization in ex and vi The following symbols are used in this and following sections to specify locations in the edit buffer:

alternate and current pathnames Two pathnames, named current and alternate, are maintained by the editor. Any ex commands that take filenames as arguments shall set them as follows:

1. If a file argument is specified to the ex edit, ex, or recover commands, or if an ex tag command replaces the contents of the edit buffer.

a. If the command replaces the contents of the edit buffer, the current pathname shall be set to the file argument or the file indicated by the tag, and the alternate pathname shall be set to the previous value of the current pathname.

b. Otherwise, the alternate pathname shall be set to the file argument.

2. If a file argument is specified to the ex next command:

a. If the command replaces the contents of the edit buffer, the current pathname shall be set to the first file argument, and the alternate pathname shall be set to the previous value of the current pathname.

3. If a file argument is specified to the ex file command, the current pathname shall be set to the file argument, and the alternate pathname shall be set to the previous value of the current pathname.

4. If a file argument is specified to the ex read and write commands (that is, when reading or writing a file, and not to the program named by the shell edit option), or a file argument is specified to the ex xit command:

a. If the current pathname has no value, the current pathname shall be set to the file argument.

b. Otherwise, the alternate pathname shall be set to the file argument.

If the alternate pathname is set to the previous value of the current pathname when the current pathname had no previous value, then the alternate pathname shall have no value as a result.

current line The line of the edit buffer referenced by the cursor. Each command description specifies the current line after the command has been executed, as the current line value. When the edit buffer contains no lines, the current line shall be zero; see Addressing in ex.

current column The current display line column occupied by the cursor. (The columns shall be numbered beginning at 1.) Each command description specifies the current column after the command has been executed, as the current column value. This column is an ideal column that is remembered over the lifetime of the editor. The actual display line column upon which the cursor rests may be different from the current column; see the cursor positioning discussion in Command Descriptions in vi.

set to non-<blank> A description for a current column value, meaning that the current column shall be set to the last display line column on which is displayed any part of the first non-<blank> of the line. If the line has no non-<blank> non-<newline> characters, the current column shall be set to the last display line column on which is displayed any part of the last non-<newline> character in the line. If the line is empty, the current column shall be set to column position 1.

The length of lines in the edit buffer may be limited to {LINE_MAX} bytes. In open and visual mode, the length of lines in the edit buffer may be limited to the number of characters that will fit in the display. If either limit is exceeded during editing, an error message shall be written. If either limit is exceeded by a line read in from a file, an error message shall be written and the edit session may be terminated.

If the editor stops running due to any reason other than a user command, and the edit buffer has been modified since the last complete write, it shall be equivalent to a SIGHUP asynchronous event. If the system crashes, it shall be equivalent to a SIGHUP asynchronous event.

During initialization (before the first file is copied into the edit buffer or any user commands from the terminal are processed) the following shall occur:

1. If the environment variable EXINIT is set, the editor shall execute the ex commands contained in that variable.

2. If the EXINIT variable is not set, and all of the following are true:

a. The HOME environment variable is not null and not empty.

b. The file .exrc in the directory referred to by the HOME environment variable:

i. Exists

ii. Is owned by the same user ID as the real user ID of the process or the process has appropriate privileges

iii. Is not writable by anyone other than the owner

the editor shall execute the ex commands contained in that file.

3. If and only if all of the following are true:

a. The current directory is not referred to by the HOME environment variable.

b. A command in the EXINIT environment variable or a command in the .exrc file in the directory referred to by the HOME environment variable sets the editor option exrc.

c. The .exrc file in the current directory:

i. Exists

ii. Is owned by the same user ID as the real user ID of the process, or by one of a set of implementation- defined user IDs

iii. Is not writable by anyone other than the owner

the editor shall attempt to execute the ex commands contained in that file.

Lines in any .exrc file that are blank lines shall be ignored. If any .exrc file exists, but is not read for ownership or permission reasons, it shall be an error.

After the EXINIT variable and any .exrc files are processed, the first file specified by the user shall be edited, as follows:

1. If the user specified the -t option, the effect shall be as if the ex tag command was entered with the specified argument, with the exception that if tag processing does not result in a file to edit, the effect shall be as described in step 3. below.

2. Otherwise, if the user specified any command line file arguments, the effect shall be as if the ex edit command was entered with the first of those arguments as its file argument.

3. Otherwise, the effect shall be as if the ex edit command was entered with a nonexistent filename as its file argument. It is unspecified whether this action shall set the current pathname. In an implementation where this action does not set the current pathname, any editor command using the current pathname shall fail until an editor command sets the current pathname.

If the -r option was specified, the first time a file in the initial argument list or a file specified by the -t option is edited, if recovery information has previously been saved about it, that information shall be recovered and the editor shall behave as if the contents of the edit buffer have already been modified. If there are multiple instances of the file to be recovered, the one most recently saved shall be recovered, and an informational message that there are previous versions of the file that can be recovered shall be written. If no recovery information about a file is available, an informational message to this effect shall be written, and the edit shall proceed as usual.

If the -c option was specified, the first time a file that already exists (including a file that might not exist but for which recovery information is available, when the -r option is specified) replaces or initializes the contents of the edit buffer, the current line shall be set to the last line of the edit buffer, the current column shall be set to non-<blank>, and the ex commands specified with the -c option shall be executed. In this case, the current line and current column shall not be set as described for the command associated with the replacement or initialization of the edit buffer contents. However, if the -t option or a tag command is associated with this action, the -c option commands shall be executed and then the movement to the tag shall be performed.

The current argument list shall initially be set to the filenames specified by the user on the command line. If no filenames are specified by the user, the current argument list shall be empty. If the -t option was specified, it is unspecified whether any filename resulting from tag processing shall be prepended to the current argument list. In the case where the filename is added as a prefix to the current argument list, the current argument list reference shall be set to that filename. In the case where the filename is not added as a prefix to the current argument list, the current argument list reference shall logically be located before the first of the filenames specified on the command line (for example, a subsequent ex next command shall edit the first filename from the command line). If the -t option was not specified, the current argument list reference shall be to the first of the filenames on the command line.

Addressing in ex Addressing in ex relates to the current line and the current column; the address of a line is its 1-based line number, the address of a column is its 1-based count from the beginning of the line. Generally, the current line is the last line affected by a command. The current line number is the address of the current line. In each command description, the effect of the command on the current line number and the current column is described.

Addresses are constructed as follows:

1. The character '.' (period) shall address the current line.

2. The character '$' shall address the last line of the edit buffer.

3. The positive decimal number n shall address the nth line of the edit buffer.

4. The address "'x" refers to the line marked with the mark name character 'x', which shall be a lowercase letter from the portable character set, the backquote character, or the single-quote character. It shall be an error if the line that was marked is not currently present in the edit buffer or the mark has not been set. Lines can be marked with the ex mark or k commands, or the vi m command.

5. A regular expression enclosed by <slash> characters ('/') shall address the first line found by searching forwards from the line following the current line toward the end of the edit buffer and stopping at the first line for which the line excluding the terminating <newline> matches the regular expression. As stated in Regular Expressions in ex, an address consisting of a null regular expression delimited by <slash> characters ("//") shall address the next line for which the line excluding the terminating <newline> matches the last regular expression encountered. In addition, the second <slash> can be omitted at the end of a command line. If the wrapscan edit option is set, the search shall wrap around to the beginning of the edit buffer and continue up to and including the current line, so that the entire edit buffer is searched. Within the regular expression, the sequence "\/" shall represent a literal <slash> instead of the regular expression delimiter.

6. A regular expression enclosed in <question-mark> characters ('?') shall address the first line found by searching backwards from the line preceding the current line toward the beginning of the edit buffer and stopping at the first line for which the line excluding the terminating <newline> matches the regular expression. An address consisting of a null regular expression delimited by <question-mark> characters ("??") shall address the previous line for which the line excluding the terminating <newline> matches the last regular expression encountered. In addition, the second <question-mark> can be omitted at the end of a command line. If the wrapscan edit option is set, the search shall wrap around from the beginning of the edit buffer to the end of the edit buffer and continue up to and including the current line, so that the entire edit buffer is searched. Within the regular expression, the sequence "\?" shall represent a literal <question-mark> instead of the RE delimiter.

7. A <plus-sign> ('+') or a <hyphen-minus> ('-') followed by a decimal number shall address the current line plus or minus the number. A '+' or '-' not followed by a decimal number shall address the current line plus or minus 1.

Addresses can be followed by zero or more address offsets, optionally <blank>-separated. Address offsets are constructed as follows:

1. A '+' or '-' immediately followed by a decimal number shall add (subtract) the indicated number of lines to (from) the address. A '+' or '-' not followed by a decimal number shall add (subtract) 1 to (from) the address.

2. A decimal number shall add the indicated number of lines to the address.

It shall not be an error for an intermediate address value to be less than zero or greater than the last line in the edit buffer. It shall be an error for the final address value to be less than zero or greater than the last line in the edit buffer.

Commands take zero, one, or two addresses; see the descriptions of 1addr and 2addr in Command Descriptions in ex. If more than the required number of addresses are provided to a command that requires zero addresses, it shall be an error. Otherwise, if more than the required number of addresses are provided to a command, the addresses specified first shall be evaluated and then discarded until the maximum number of valid addresses remain.

Addresses shall be separated from each other by a <comma> (',') or a <semicolon> (';'). If no address is specified before or after a <comma> or <semicolon> separator, it shall be as if the address of the current line was specified before or after the separator. In the case of a <semicolon> separator, the current line ('.') shall be set to the first address, and only then will the next address be calculated. This feature can be used to determine the starting line for forwards and backwards searches (see rules 5. and 6.).

A <percent-sign> ('%') shall be equivalent to entering the two addresses "1,$".

Any delimiting <blank> characters between addresses, address separators, or address offsets shall be discarded.

Command Line Parsing in ex The following symbol is used in this and following sections to describe parsing behavior:

escape If a character is referred to as ``<backslash>-escaped'' or ``<control>‐V-escaped'', it shall mean that the character acquired or lost a special meaning by virtue of being preceded, respectively, by a <backslash> or <control>‐V character. Unless otherwise specified, the escaping character shall be discarded at that time and shall not be further considered for any purpose.

Command-line parsing shall be done in the following steps. For each step, characters already evaluated shall be ignored; that is, the phrase ``leading character'' refers to the next character that has not yet been evaluated.

1. Leading <colon> characters shall be skipped.

2. Leading <blank> characters shall be skipped.

3. If the leading character is a double-quote character, the characters up to and including the next non-<backslash>-escaped <newline> shall be discarded, and any subsequent characters shall be parsed as a separate command.

4. Leading characters that can be interpreted as addresses shall be evaluated; see Addressing in ex.

5. Leading <blank> characters shall be skipped.

6. If the next character is a <vertical-line> character or a <newline>:

a. If the next character is a <newline>:

i. If ex is in open or visual mode, the current line shall be set to the last address specified, if any.

ii. Otherwise, if the last command was terminated by a <vertical-line> character, no action shall be taken; for example, the command "||<newline>" shall execute two implied commands, not three.

iii. Otherwise, step 6.b. shall apply.

b. Otherwise, the implied command shall be the print command. The last #, p, and l flags specified to any ex command shall be remembered and shall apply to this implied command. Executing the ex number, print, or list command shall set the remembered flags to #, nothing, and l, respectively, plus any other flags specified for that execution of the number, print, or list command.

If ex is not currently performing a global or v command, and no address or count is specified, the current line shall be incremented by 1 before the command is executed. If incrementing the current line would result in an address past the last line in the edit buffer, the command shall fail, and the increment shall not happen.

c. The <newline> or <vertical-line> character shall be discarded and any subsequent characters shall be parsed as a separate command.

7. The command name shall be comprised of the next character (if the character is not alphabetic), or the next character and any subsequent alphabetic characters (if the character is alphabetic), with the following exceptions:

a. Commands that consist of any prefix of the characters in the command name delete, followed immediately by any of the characters 'l', 'p', '+', '-', or '#' shall be interpreted as a delete command, followed by a <blank>, followed by the characters that were not part of the prefix of the delete command. The maximum number of characters shall be matched to the command name delete; for example, "del" shall not be treated as "de" followed by the flag l.

b. Commands that consist of the character 'k', followed by a character that can be used as the name of a mark, shall be equivalent to the mark command followed by a <blank>, followed by the character that followed the 'k'.

c. Commands that consist of the character 's', followed by characters that could be interpreted as valid options to the s command, shall be the equivalent of the s command, without any pattern or replacement values, followed by a <blank>, followed by the characters after the 's'.

8. The command name shall be matched against the possible command names, and a command name that contains a prefix matching the characters specified by the user shall be the executed command. In the case of commands where the characters specified by the user could be ambiguous, the executed command shall be as follows:

┌───┬────────┬┬───┬───────┬┬───┬───────┐ │a append ││n next ││t t │ │c change ││p print ││u undo │ │ch change ││pr print ││un undo │ │e edit ││r read ││v v │ │m move ││re read ││w write │ │ma mark ││s s ││ │ │ └───┴────────┴┴───┴───────┴┴───┴───────┘ Implementation extensions with names causing similar ambiguities shall not be checked for a match until all possible matches for commands specified by POSIX.1‐2008 have been checked.

9. If the command is a ! command, or if the command is a read command followed by zero or more <blank> characters and a !, or if the command is a write command followed by one or more <blank> characters and a !, the rest of the command shall include all characters up to a non-<backslash>-escaped <newline>. The <newline> shall be discarded and any subsequent characters shall be parsed as a separate ex command.

10. Otherwise, if the command is an edit, ex, or next command, or a visual command while in open or visual mode, the next part of the command shall be parsed as follows:

a. Any '!' character immediately following the command shall be skipped and be part of the command.

b. Any leading <blank> characters shall be skipped and be part of the command.

c. If the next character is a '+', characters up to the first non-<backslash>-escaped <newline> or non-<backslash>-escaped <blank> shall be skipped and be part of the command.

d. The rest of the command shall be determined by the steps specified in paragraph 12.

11. Otherwise, if the command is a global, open, s, or v command, the next part of the command shall be parsed as follows:

a. Any leading <blank> characters shall be skipped and be part of the command.

b. If the next character is not an alphanumeric, double- quote, <newline>, <backslash>, or <vertical-line> character:

i. The next character shall be used as a command delimiter.

ii. If the command is a global, open, or v command, characters up to the first non-<backslash>-escaped <newline>, or first non-<backslash>-escaped delimiter character, shall be skipped and be part of the command.

iii. If the command is an s command, characters up to the first non-<backslash>-escaped <newline>, or second non-<backslash>-escaped delimiter character, shall be skipped and be part of the command.

c. If the command is a global or v command, characters up to the first non-<backslash>-escaped <newline> shall be skipped and be part of the command.

d. Otherwise, the rest of the command shall be determined by the steps specified in paragraph 12.

12. Otherwise:

a. If the command was a map, unmap, abbreviate, or unabbreviate command, characters up to the first non-<control>‐V-escaped <newline>, <vertical-line>, or double-quote character shall be skipped and be part of the command.

b. Otherwise, characters up to the first non-<backslash>-escaped <newline>, <vertical-line>, or double-quote character shall be skipped and be part of the command.

c. If the command was an append, change, or insert command, and the step 12.b. ended at a <vertical-line> character, any subsequent characters, up to the next non-<backslash>-escaped <newline> shall be used as input text to the command.

d. If the command was ended by a double-quote character, all subsequent characters, up to the next non-<backslash>-escaped <newline>, shall be discarded.

e. The terminating <newline> or <vertical-line> character shall be discarded and any subsequent characters shall be parsed as a separate ex command.

Command arguments shall be parsed as described by the Synopsis and Description of each individual ex command. This parsing shall not be <blank>-sensitive, except for the ! argument, which must follow the command name without intervening <blank> characters, and where it would otherwise be ambiguous. For example, count and flag arguments need not be <blank>-separated because "d22p" is not ambiguous, but file arguments to the ex next command must be separated by one or more <blank> characters. Any <blank> in command arguments for the abbreviate, unabbreviate, map, and unmap commands can be <control>‐V-escaped, in which case the <blank> shall not be used as an argument delimiter. Any <blank> in the command argument for any other command can be <backslash>-escaped, in which case that <blank> shall not be used as an argument delimiter.

Within command arguments for the abbreviate, unabbreviate, map, and unmap commands, any character can be <control>‐V-escaped. All such escaped characters shall be treated literally and shall have no special meaning. Within command arguments for all other ex commands that are not regular expressions or replacement strings, any character that would otherwise have a special meaning can be <backslash>-escaped. Escaped characters shall be treated literally, without special meaning as shell expansion characters or '!', '%', and '#' expansion characters. See Regular Expressions in ex and Replacement Strings in ex for descriptions of command arguments that are regular expressions or replacement strings.

Non-<backslash>-escaped '%' characters appearing in file arguments to any ex command shall be replaced by the current pathname; unescaped '#' characters shall be replaced by the alternate pathname. It shall be an error if '%' or '#' characters appear unescaped in an argument and their corresponding values are not set.

Non-<backslash>-escaped '!' characters in the arguments to either the ex ! command or the open and visual mode ! command, or in the arguments to the ex read command, where the first non-<blank> after the command name is a '!' character, or in the arguments to the ex write command where the command name is followed by one or more <blank> characters and the first non-<blank> after the command name is a '!' character, shall be replaced with the arguments to the last of those three commands as they appeared after all unescaped '%', '#', and '!' characters were replaced. It shall be an error if '!' characters appear unescaped in one of these commands and there has been no previous execution of one of these commands.

If an error occurs during the parsing or execution of an ex command:

* An informational message to this effect shall be written. Execution of the ex command shall stop, and the cursor (for example, the current line and column) shall not be further modified.

* If the ex command resulted from a map expansion, all characters from that map expansion shall be discarded, except as otherwise specified by the map command.

* Otherwise, if the ex command resulted from the processing of an EXINIT environment variable, a .exrc file, a :source command, a -c option, or a +command specified to an ex edit, ex, next, or visual command, no further commands from the source of the commands shall be executed.

* Otherwise, if the ex command resulted from the execution of a buffer or a global or v command, no further commands caused by the execution of the buffer or the global or v command shall be executed.

* Otherwise, if the ex command was not terminated by a <newline>, all characters up to and including the next non-<backslash>-escaped <newline> shall be discarded.

Input Editing in ex The following symbol is used in this and the following sections to specify command actions:

word In the POSIX locale, a word consists of a maximal sequence of letters, digits, and underscores, delimited at both ends by characters other than letters, digits, or underscores, or by the beginning or end of a line or the edit buffer.

When accepting input characters from the user, in either ex command mode or ex text input mode, ex shall enable canonical mode input processing, as defined in the System Interfaces volume of POSIX.1‐2017.

If in ex text input mode:

1. If the number edit option is set, ex shall prompt for input using the line number that would be assigned to the line if it is entered, in the format specified for the ex number command.

2. If the autoindent edit option is set, ex shall prompt for input using autoindent characters, as described by the autoindent edit option. autoindent characters shall follow the line number, if any.

If in ex command mode:

1. If the prompt edit option is set, input shall be prompted for using a single ':' character; otherwise, there shall be no prompt.

The input characters in the following sections shall have the following effects on the input line.

Scroll Synopsis:

eof

See the description of the stty eof character in stty(1p).

If in ex command mode:

If the eof character is the first character entered on the line, the line shall be evaluated as if it contained two characters: a <control>‐D and a <newline>.

Otherwise, the eof character shall have no special meaning.

If in ex text input mode:

If the cursor follows an autoindent character, the autoindent characters in the line shall be modified so that a part of the next text input character will be displayed on the first column in the line after the previous shiftwidth edit option column boundary, and the user shall be prompted again for input for the same line.

Otherwise, if the cursor follows a '0', which follows an autoindent character, and the '0' was the previous text input character, the '0' and all autoindent characters in the line shall be discarded, and the user shall be prompted again for input for the same line.

Otherwise, if the cursor follows a '^', which follows an autoindent character, and the '^' was the previous text input character, the '^' and all autoindent characters in the line shall be discarded, and the user shall be prompted again for input for the same line. In addition, the autoindent level for the next input line shall be derived from the same line from which the autoindent level for the current input line was derived.

Otherwise, if there are no autoindent or text input characters in the line, the eof character shall be discarded.

Otherwise, the eof character shall have no special meaning.

<newline> Synopsis:

<newline> <control>-J

If in ex command mode:

Cause the command line to be parsed; <control>‐J shall be mapped to the <newline> for this purpose.

If in ex text input mode:

Terminate the current line. If there are no characters other than autoindent characters on the line, all characters on the line shall be discarded.

Prompt for text input on a new line after the current line. If the autoindent edit option is set, an appropriate number of autoindent characters shall be added as a prefix to the line as described by the ex autoindent edit option.

<backslash> Synopsis:

<backslash>

Allow the entry of a subsequent <newline> or <control>‐J as a literal character, removing any special meaning that it may have to the editor during text input mode. The <backslash> character shall be retained and evaluated when the command line is parsed, or retained and included when the input text becomes part of the edit buffer.

<control>‐V Synopsis:

<control>-V

Allow the entry of any subsequent character as a literal character, removing any special meaning that it may have to the editor during text input mode. The <control>‐V character shall be discarded before the command line is parsed or the input text becomes part of the edit buffer.

If the ``literal next'' functionality is performed by the underlying system, it is implementation-defined whether a character other than <control>‐V performs this function.

<control>‐W Synopsis:

<control>-W

Discard the <control>‐W, and the word previous to it in the input line, including any <blank> characters following the word and preceding the <control>‐W. If the ``word erase'' functionality is performed by the underlying system, it is implementation- defined whether a character other than <control>‐W performs this function.

Command Descriptions in ex The following symbols are used in this section to represent command modifiers. Some of these modifiers can be omitted, in which case the specified defaults shall be used.

1addr A single line address, given in any of the forms described in Addressing in ex; the default shall be the current line ('.'), unless otherwise specified.

If the line address is zero, it shall be an error, unless otherwise specified in the following command descriptions.

If the edit buffer is empty, and the address is specified with a command other than =, append, insert, open, put, read, or visual, or the address is not zero, it shall be an error.

2addr Two addresses specifying an inclusive range of lines. If no addresses are specified, the default for 2addr shall be the current line only (".,."), unless otherwise specified in the following command descriptions. If one address is specified, 2addr shall specify that line only, unless otherwise specified in the following command descriptions.

It shall be an error if the first address is greater than the second address.

If the edit buffer is empty, and the two addresses are specified with a command other than the !, write, wq, or xit commands, or either address is not zero, it shall be an error.

count A positive decimal number. If count is specified, it shall be equivalent to specifying an additional address to the command, unless otherwise specified by the following command descriptions. The additional address shall be equal to the last address specified to the command (either explicitly or by default) plus count-1.

If this would result in an address greater than the last line of the edit buffer, it shall be corrected to equal the last line of the edit buffer.

flags One or more of the characters '+', '-', '#', 'p', or 'l' (ell). The flag characters can be <blank>-separated, and in any order or combination. The characters '#', 'p', and 'l' shall cause lines to be written in the format specified by the print command with the specified flags.

The lines to be written are as follows:

1. All edit buffer lines written during the execution of the ex &, ~, list, number, open, print, s, visual, and z commands shall be written as specified by flags.

2. After the completion of an ex command with a flag as an argument, the current line shall be written as specified by flags, unless the current line was the last line written by the command.

The characters '+' and '-' cause the value of the current line after the execution of the ex command to be adjusted by the offset address as described in Addressing in ex. This adjustment shall occur before the current line is written as described in 2. above.

The default for flags shall be none.

buffer One of a number of named areas for holding text. The named buffers are specified by the alphanumeric characters of the POSIX locale. There shall also be one ``unnamed'' buffer. When no buffer is specified for editor commands that use a buffer, the unnamed buffer shall be used. Commands that store text into buffers shall store the text as it was before the command took effect, and shall store text occurring earlier in the file before text occurring later in the file, regardless of how the text region was specified. Commands that store text into buffers shall store the text into the unnamed buffer as well as any specified buffer.

In ex commands, buffer names are specified as the name by itself. In open or visual mode commands the name is preceded by a double-quote ('"') character.

If the specified buffer name is an uppercase character, and the buffer contents are to be modified, the buffer shall be appended to rather than being overwritten. If the buffer is not being modified, specifying the buffer name in lowercase and uppercase shall have identical results.

There shall also be buffers named by the numbers 1 through 9. In open and visual mode, if a region of text including characters from more than a single line is being modified by the vi c or d commands, the motion character associated with the c or d commands specifies that the buffer text shall be in line mode, or the commands %, `, /, ?, (, ), N, n, {, or } are used to define a region of text for the c or d commands, the contents of buffers 1 through 8 shall be moved into the buffer named by the next numerically greater value, the contents of buffer 9 shall be discarded, and the region of text shall be copied into buffer 1. This shall be in addition to copying the text into a user-specified buffer or unnamed buffer, or both. Numeric buffers can be specified as a source buffer for open and visual mode commands; however, specifying a numeric buffer as the write target of an open or visual mode command shall have unspecified results.

The text of each buffer shall have the characteristic of being in either line or character mode. Appending text to a non-empty buffer shall set the mode to match the characteristic of the text being appended. Appending text to a buffer shall cause the creation of at least one additional line in the buffer. All text stored into buffers by ex commands shall be in line mode. The ex commands that use buffers as the source of text specify individually how buffers of different modes are handled. Each open or visual mode command that uses buffers for any purpose specifies individually the mode of the text stored into the buffer and how buffers of different modes are handled.

file Command text used to derive a pathname. The default shall be the current pathname, as defined previously, in which case, if no current pathname has yet been established it shall be an error, except where specifically noted in the individual command descriptions that follow. If the command text contains any of the characters '~', '{', '[', '*', '?', '$', '"', backquote, single-quote, and <backslash>, it shall be subjected to the process of ``shell expansions'', as described below; if more than a single pathname results and the command expects only one, it shall be an error.

The process of shell expansions in the editor shall be done as follows. The ex utility shall pass two arguments to the program named by the shell edit option; the first shall be -c, and the second shall be the string "echo" and the command text as a single argument. The standard output and standard error of that command shall replace the command text.

! A character that can be appended to the command name to modify its operation, as detailed in the individual command descriptions. With the exception of the ex read, write, and ! commands, the '!' character shall only act as a modifier if there are no <blank> characters between it and the command name.

remembered search direction The vi commands N and n begin searching in a forwards or backwards direction in the edit buffer based on a remembered search direction, which is initially unset, and is set by the ex global, v, s, and tag commands, and the vi / and ? commands.

Abbreviate Synopsis:

ab[breviate][lhs rhs]

If lhs and rhs are not specified, write the current list of abbreviations and do nothing more.

Implementations may restrict the set of characters accepted in lhs or rhs, except that printable characters and <blank> characters shall not be restricted. Additional restrictions shall be implementation-defined.

In both lhs and rhs, any character may be escaped with a <control>‐V, in which case the character shall not be used to delimit lhs from rhs, and the escaping <control>‐V shall be discarded.

In open and visual text input mode, if a non-word or <ESC> character that is not escaped by a <control>‐V character is entered after a word character, a check shall be made for a set of characters matching lhs, in the text input entered during this command. If it is found, the effect shall be as if rhs was entered instead of lhs.

The set of characters that are checked is defined as follows:

1. If there are no characters inserted before the word and non- word or <ESC> characters that triggered the check, the set of characters shall consist of the word character.

2. If the character inserted before the word and non-word or <ESC> characters that triggered the check is a word character, the set of characters shall consist of the characters inserted immediately before the triggering characters that are word characters, plus the triggering word character.

3. If the character inserted before the word and non-word or <ESC> characters that triggered the check is not a word character, the set of characters shall consist of the characters that were inserted before the triggering characters that are neither <blank> characters nor word characters, plus the triggering word character.

It is unspecified whether the lhs argument entered for the ex abbreviate and unabbreviate commands is replaced in this fashion. Regardless of whether or not the replacement occurs, the effect of the command shall be as if the replacement had not occurred.

Current line: Unchanged.

Current column: Unchanged.

Append Synopsis:

[1addr] a[ppend][!]

Enter ex text input mode; the input text shall be placed after the specified line. If line zero is specified, the text shall be placed at the beginning of the edit buffer.

This command shall be affected by the number and autoindent edit options; following the command name with '!' shall cause the autoindent edit option setting to be toggled for the duration of this command only.

Current line: Set to the last input line; if no lines were input, set to the specified line, or to the first line of the edit buffer if a line of zero was specified, or zero if the edit buffer is empty.

Current column: Set to non-<blank>.

Arguments Synopsis:

ar[gs]

Write the current argument list, with the current argument-list entry, if any, between '[' and ']' characters.

Current line: Unchanged.

Current column: Unchanged.

Change Synopsis:

[2addr] c[hange][!][count]

Enter ex text input mode; the input text shall replace the specified lines. The specified lines shall be copied into the unnamed buffer, which shall become a line mode buffer.

This command shall be affected by the number and autoindent edit options; following the command name with '!' shall cause the autoindent edit option setting to be toggled for the duration of this command only.

Current line: Set to the last input line; if no lines were input, set to the line before the first address, or to the first line of the edit buffer if there are no lines preceding the first address, or to zero if the edit buffer is empty.

Current column: Set to non-<blank>.

Change Directory Synopsis:

chd[ir][!][directory] cd[!][directory]

Change the current working directory to directory.

If no directory argument is specified, and the HOME environment variable is set to a non-null and non-empty value, directory shall default to the value named in the HOME environment variable. If the HOME environment variable is empty or is undefined, the default value of directory is implementation- defined.

If no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, and the current pathname does not begin with a '/', it shall be an error.

Current line: Unchanged.

Current column: Unchanged.

Copy Synopsis:

[2addr] co[py] 1addr [flags] [2addr] t 1addr [flags]

Copy the specified lines after the specified destination line; line zero specifies that the lines shall be placed at the beginning of the edit buffer.

Current line: Set to the last line copied.

Current column: Set to non-<blank>.

Delete Synopsis:

[2addr] d[elete][buffer][count][flags]

Delete the specified lines into a buffer (defaulting to the unnamed buffer), which shall become a line-mode buffer.

Flags can immediately follow the command name; see Command Line Parsing in ex.

Current line: Set to the line following the deleted lines, or to the last line in the edit buffer if that line is past the end of the edit buffer, or to zero if the edit buffer is empty.

Current column: Set to non-<blank>.

Edit Synopsis:

e[dit][!][+command][file] ex[!][+command][file]

If no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, it shall be an error.

If file is specified, replace the current contents of the edit buffer with the current contents of file, and set the current pathname to file. If file is not specified, replace the current contents of the edit buffer with the current contents of the file named by the current pathname. If for any reason the current contents of the file cannot be accessed, the edit buffer shall be empty.

The +command option shall be <blank>-delimited; <blank> characters within the +command can be escaped by preceding them with a <backslash> character. The +command shall be interpreted as an ex command immediately after the contents of the edit buffer have been replaced and the current line and column have been set.

If the edit buffer is empty:

Current line: Set to 0.

Current column: Set to 1.

Otherwise, if executed while in ex command mode or if the +command argument is specified:

Current line: Set to the last line of the edit buffer.

Current column: Set to non-<blank>.

Otherwise, if file is omitted or results in the current pathname:

Current line: Set to the first line of the edit buffer.

Current column: Set to non-<blank>.

Otherwise, if file is the same as the last file edited, the line and column shall be set as follows; if the file was previously edited, the line and column may be set as follows:

Current line: Set to the last value held when that file was last edited. If this value is not a valid line in the new edit buffer, set to the first line of the edit buffer.

Current column: If the current line was set to the last value held when the file was last edited, set to the last value held when the file was last edited. Otherwise, or if the last value is not a valid column in the new edit buffer, set to non-<blank>.

Otherwise:

Current line: Set to the first line of the edit buffer.

Current column: Set to non-<blank>.

File Synopsis:

f[ile][file]

If a file argument is specified, the alternate pathname shall be set to the current pathname, and the current pathname shall be set to file.

Write an informational message. If the file has a current pathname, it shall be included in this message; otherwise, the message shall indicate that there is no current pathname. If the edit buffer contains lines, the current line number and the number of lines in the edit buffer shall be included in this message; otherwise, the message shall indicate that the edit buffer is empty. If the edit buffer has been modified since the last complete write, this fact shall be included in this message. If the readonly edit option is set, this fact shall be included in this message. The message may contain other unspecified information.

Current line: Unchanged.

Current column: Unchanged.

Global Synopsis:

[2addr] g[lobal] /pattern/ [commands] [2addr] v /pattern/ [commands]

The optional '!' character after the global command shall be the same as executing the v command.

If pattern is empty (for example, "//") or not specified, the last regular expression used in the editor command shall be used as the pattern. The pattern can be delimited by <slash> characters (shown in the Synopsis), as well as any non- alphanumeric or non-<blank> other than <backslash>, <vertical- line>, <newline>, or double-quote.

If no lines are specified, the lines shall default to the entire file.

The global and v commands are logically two-pass operations. First, mark the lines within the specified lines for which the line excluding the terminating <newline> matches (global) or does not match (v or global!) the specified pattern. Second, execute the ex commands given by commands, with the current line ('.') set to each marked line. If an error occurs during this process, or the contents of the edit buffer are replaced (for example, by the ex :edit command) an error message shall be written and no more commands resulting from the execution of this command shall be processed.

Multiple ex commands can be specified by entering multiple commands on a single line using a <vertical-line> to delimit them, or one per line, by escaping each <newline> with a <backslash>.

If no commands are specified:

1. If in ex command mode, it shall be as if the print command were specified.

2. Otherwise, no command shall be executed.

For the append, change, and insert commands, the input text shall be included as part of the command, and the terminating <period> can be omitted if the command ends the list of commands. The open and visual commands can be specified as one of the commands, in which case each marked line shall cause the editor to enter open or visual mode. If open or visual mode is exited using the vi Q command, the current line shall be set to the next marked line, and open or visual mode reentered, until the list of marked lines is exhausted.

The global, v, and undo commands cannot be used in commands. Marked lines may be deleted by commands executed for lines occurring earlier in the file than the marked lines. In this case, no commands shall be executed for the deleted lines.

If the remembered search direction is not set, the global and v commands shall set it to forward.

The autoprint and autoindent edit options shall be inhibited for the duration of the g or v command.

Current line: If no commands executed, set to the last marked line. Otherwise, as specified for the executed ex commands.

Current column: If no commands are executed, set to non-<blank>; otherwise, as specified for the individual ex commands.

Insert Synopsis:

[1addr] i[nsert][!]

Enter ex text input mode; the input text shall be placed before the specified line. If the line is zero or 1, the text shall be placed at the beginning of the edit buffer.

This command shall be affected by the number and autoindent edit options; following the command name with '!' shall cause the autoindent edit option setting to be toggled for the duration of this command only.

Current line: Set to the last input line; if no lines were input, set to the line before the specified line, or to the first line of the edit buffer if there are no lines preceding the specified line, or zero if the edit buffer is empty.

Current column: Set to non-<blank>.

Join Synopsis:

[2addr] j[oin][!][count][flags]

If count is specified:

If no address was specified, the join command shall behave as if 2addr were the current line and the current line plus count (.,. + count).

If one address was specified, the join command shall behave as if 2addr were the specified address and the specified address plus count (addr,addr + count).

If two addresses were specified, the join command shall behave as if an additional address, equal to the last address plus count -1 (addr1,addr2,addr2 + count -1), was specified.

If this would result in a second address greater than the last line of the edit buffer, it shall be corrected to be equal to the last line of the edit buffer.

If no count is specified:

If no address was specified, the join command shall behave as if 2addr were the current line and the next line (.,. +1).

If one address was specified, the join command shall behave as if 2addr were the specified address and the next line (addr,addr +1).

Join the text from the specified lines together into a single line, which shall replace the specified lines.

If a '!' character is appended to the command name, the join shall be without modification of any line, independent of the current locale.

Otherwise, in the POSIX locale, set the current line to the first of the specified lines, and then, for each subsequent line, proceed as follows:

1. Discard leading <space> characters from the line to be joined.

2. If the line to be joined is now empty, delete it, and skip steps 3 through 5.

3. If the current line ends in a <blank>, or the first character of the line to be joined is a ')' character, join the lines without further modification.

4. If the last character of the current line is a '.', join the lines with two <space> characters between them.

5. Otherwise, join the lines with a single <space> between them.

Current line: Set to the first line specified.

Current column: Set to non-<blank>.

List Synopsis:

[2addr] l[ist][count][flags]

This command shall be equivalent to the ex command:

[2addr] p[rint][count] l[flags]

See Print.

Map Synopsis:

map[!][lhs rhs]

If lhs and rhs are not specified:

1. If '!' is specified, write the current list of text input mode maps.

2. Otherwise, write the current list of command mode maps.

3. Do nothing more.

Implementations may restrict the set of characters accepted in lhs or rhs, except that printable characters and <blank> characters shall not be restricted. Additional restrictions shall be implementation-defined. In both lhs and rhs, any character can be escaped with a <control>‐V, in which case the character shall not be used to delimit lhs from rhs, and the escaping <control>‐V shall be discarded.

If the character '!' is appended to the map command name, the mapping shall be effective during open or visual text input mode rather than open or visual command mode. This allows lhs to have two different map definitions at the same time: one for command mode and one for text input mode.

For command mode mappings:

When the lhs is entered as any part of a vi command in open or visual mode (but not as part of the arguments to the command), the action shall be as if the corresponding rhs had been entered.

If any character in the command, other than the first, is escaped using a <control>‐V character, that character shall not be part of a match to an lhs.

It is unspecified whether implementations shall support map commands where the lhs is more than a single character in length, where the first character of the lhs is printable.

If lhs contains more than one character and the first character is '#', followed by a sequence of digits corresponding to a numbered function key, then when this function key is typed it shall be mapped to rhs. Characters other than digits following a '#' character also represent the function key named by the characters in the lhs following the '#' and may be mapped to rhs. It is unspecified how function keys are named or what function keys are supported.

For text input mode mappings:

When the lhs is entered as any part of text entered in open or visual text input modes, the action shall be as if the corresponding rhs had been entered.

If any character in the input text is escaped using a <control>‐V character, that character shall not be part of a match to an lhs.

It is unspecified whether the lhs text entered for subsequent map or unmap commands is replaced with the rhs text for the purposes of the screen display; regardless of whether or not the display appears as if the corresponding rhs text was entered, the effect of the command shall be as if the lhs text was entered.

If only part of the lhs is entered, it is unspecified how long the editor will wait for additional, possibly matching characters before treating the already entered characters as not matching the lhs.

The rhs characters shall themselves be subject to remapping, unless otherwise specified by the remap edit option, except that if the characters in lhs occur as prefix characters in rhs, those characters shall not be remapped.

On block-mode terminals, the mapping need not occur immediately (for example, it may occur after the terminal transmits a group of characters to the system), but it shall achieve the same results as if it occurred immediately.

Current line: Unchanged.

Current column: Unchanged.

Mark Synopsis:

[1addr] ma[rk] character [1addr] k character

Implementations shall support character values of a single lowercase letter of the POSIX locale and the backquote and single-quote characters; support of other characters is implementation-defined.

If executing the vi m command, set the specified mark to the current line and 1-based numbered character referenced by the current column, if any; otherwise, column position 1.

Otherwise, set the specified mark to the specified line and 1-based numbered first non-<blank> non-<newline> in the line, if any; otherwise, the last non-<newline> in the line, if any; otherwise, column position 1.

The mark shall remain associated with the line until the mark is reset or the line is deleted. If a deleted line is restored by a subsequent undo command, any marks previously associated with the line, which have not been reset, shall be restored as well. Any use of a mark not associated with a current line in the edit buffer shall be an error.

The marks ` and ' shall be set as described previously, immediately before the following events occur in the editor:

1. The use of '$' as an ex address

2. The use of a positive decimal number as an ex address

3. The use of a search command as an ex address

4. The use of a mark reference as an ex address

5. The use of the following open and visual mode commands: <control>‐], %, (, ), [, ], {, }

6. The use of the following open and visual mode commands: ', G, H, L, M, z if the current line will change as a result of the command

7. The use of the open and visual mode commands: /, ?, N, `, n if the current line or column will change as a result of the command

8. The use of the ex mode commands: z, undo, global, v

For rules 1., 2., 3., and 4., the ` and ' marks shall not be set if the ex command is parsed as specified by rule 6.a. in Command Line Parsing in ex.

For rules 5., 6., and 7., the ` and ' marks shall not be set if the commands are used as motion commands in open and visual mode.

For rules 1., 2., 3., 4., 5., 6., 7., and 8., the ` and ' marks shall not be set if the command fails.

The ` and ' marks shall be set as described previously, each time the contents of the edit buffer are replaced (including the editing of the initial buffer), if in open or visual mode, or if in ex mode and the edit buffer is not empty, before any commands or movements (including commands or movements specified by the -c or -t options or the +command argument) are executed on the edit buffer. If in open or visual mode, the marks shall be set as if executing the vi m command; otherwise, as if executing the ex mark command.

When changing from ex mode to open or visual mode, if the ` and ' marks are not already set, the ` and ' marks shall be set as described previously.

Current line: Unchanged.

Current column: Unchanged.

Move Synopsis:

[2addr] m[ove] 1addr [flags]

Move the specified lines after the specified destination line. A destination of line zero specifies that the lines shall be placed at the beginning of the edit buffer. It shall be an error if the destination line is within the range of lines to be moved.

Current line: Set to the last of the moved lines.

Current column: Set to non-<blank>.

Next Synopsis:

n[ext][!][+command][file ...]

If no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, it shall be an error, unless the file is successfully written as specified by the autowrite option.

If one or more files is specified:

1. Set the argument list to the specified filenames.

2. Set the current argument list reference to be the first entry in the argument list.

3. Set the current pathname to the first filename specified.

Otherwise:

1. It shall be an error if there are no more filenames in the argument list after the filename currently referenced.

2. Set the current pathname and the current argument list reference to the filename after the filename currently referenced in the argument list.

Replace the contents of the edit buffer with the contents of the file named by the current pathname. If for any reason the contents of the file cannot be accessed, the edit buffer shall be empty.

This command shall be affected by the autowrite and writeany edit options.

The +command option shall be <blank>-delimited; <blank> characters can be escaped by preceding them with a <backslash> character. The +command shall be interpreted as an ex command immediately after the contents of the edit buffer have been replaced and the current line and column have been set.

Current line: Set as described for the edit command.

Current column: Set as described for the edit command.

Number Synopsis:

[2addr] nu[mber][count][flags] [2addr] #[count][flags]

These commands shall be equivalent to the ex command:

[2addr] p[rint][count] #[flags]

See Print.

Open Synopsis:

[1addr] o[pen] /pattern/ [flags]

This command need not be supported on block-mode terminals or terminals with insufficient capabilities. If standard input, standard output, or standard error are not terminal devices, the results are unspecified.

Enter open mode.

The trailing delimiter can be omitted from pattern at the end of the command line. If pattern is empty (for example, "//") or not specified, the last regular expression used in the editor shall be used as the pattern. The pattern can be delimited by <slash> characters (shown in the Synopsis), as well as any alphanumeric, or non-<blank> other than <backslash>, <vertical-line>, <newline>, or double-quote.

Current line: Set to the specified line.

Current column: Set to non-<blank>.

Preserve Synopsis:

pre[serve]

Save the edit buffer in a form that can later be recovered by using the -r option or by using the ex recover command. After the file has been preserved, a mail message shall be sent to the user. This message shall be readable by invoking the mailx utility. The message shall contain the name of the file, the time of preservation, and an ex command that could be used to recover the file. Additional information may be included in the mail message.

Current line: Unchanged.

Current column: Unchanged.

Print Synopsis:

[2addr] p[rint][count][flags]

Write the addressed lines. The behavior is unspecified if the number of columns on the display is less than the number of columns required to write any single character in the lines being written.

Non-printable characters, except for the <tab>, shall be written as implementation-defined multi-character sequences.

If the # flag is specified or the number edit option is set, each line shall be preceded by its line number in the following format:

"%6d ", <line number>

If the l flag is specified or the list edit option is set:

1. The characters listed in the Base Definitions volume of POSIX.1‐2017, Table 5-1, Escape Sequences and Associated Actions shall be written as the corresponding escape sequence.

2. Non-printable characters not in the Base Definitions volume of POSIX.1‐2017, Table 5-1, Escape Sequences and Associated Actions shall be written as one three-digit octal number (with a preceding <backslash>) for each byte in the character (most significant byte first).

3. The end of each line shall be marked with a '$', and literal '$' characters within the line shall be written with a preceding <backslash>.

Long lines shall be folded; the length at which folding occurs is unspecified, but should be appropriate for the output terminal, considering the number of columns of the terminal.

If a line is folded, and the l flag is not specified and the list edit option is not set, it is unspecified whether a multi-column character at the folding position is separated; it shall not be discarded.

Current line: Set to the last written line.

Current column: Unchanged if the current line is unchanged; otherwise, set to non-<blank>.

Put Synopsis:

[1addr] pu[t][buffer]

Append text from the specified buffer (by default, the unnamed buffer) to the specified line; line zero specifies that the text shall be placed at the beginning of the edit buffer. Each portion of a line in the buffer shall become a new line in the edit buffer, regardless of the mode of the buffer.

Current line: Set to the last line entered into the edit buffer.

Current column: Set to non-<blank>.

Quit Synopsis:

q[uit][!]

If no '!' is appended to the command name:

1. If the edit buffer has been modified since the last complete write, it shall be an error.

2. If there are filenames in the argument list after the filename currently referenced, and the last command was not a quit, wq, xit, or ZZ (see Exit) command, it shall be an error.

Otherwise, terminate the editing session.

Read Synopsis:

[1addr] r[ead][!][file]

If '!' is not the first non-<blank> to follow the command name, a copy of the specified file shall be appended into the edit buffer after the specified line; line zero specifies that the copy shall be placed at the beginning of the edit buffer. The number of lines and bytes read shall be written. If no file is named, the current pathname shall be the default. If there is no current pathname, then file shall become the current pathname. If there is no current pathname or file operand, it shall be an error. Specifying a file that is not of type regular shall have unspecified results.

Otherwise, if file is preceded by '!', the rest of the line after the '!' shall have '%', '#', and '!' characters expanded as described in Command Line Parsing in ex.

The ex utility shall then pass two arguments to the program named by the shell edit option; the first shall be -c and the second shall be the expanded arguments to the read command as a single argument. The standard input of the program shall be set to the standard input of the ex program when it was invoked. The standard error and standard output of the program shall be appended into the edit buffer after the specified line.

Each line in the copied file or program output (as delimited by <newline> characters or the end of the file or output if it is not immediately preceded by a <newline>), shall be a separate line in the edit buffer. Any occurrences of <carriage-return> and <newline> pairs in the output shall be treated as single <newline> characters.

The special meaning of the '!' following the read command can be overridden by escaping it with a <backslash> character.

Current line: If no lines are added to the edit buffer, unchanged. Otherwise, if in open or visual mode, set to the first line entered into the edit buffer. Otherwise, set to the last line entered into the edit buffer.

Current column: Set to non-<blank>.

Recover Synopsis:

rec[over][!] file

If no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, it shall be an error.

If no file operand is specified, then the current pathname shall be used. If there is no current pathname or file operand, it shall be an error.

If no recovery information has previously been saved about file, the recover command shall behave identically to the edit command, and an informational message to this effect shall be written.

Otherwise, set the current pathname to file, and replace the current contents of the edit buffer with the recovered contents of file. If there are multiple instances of the file to be recovered, the one most recently saved shall be recovered, and an informational message that there are previous versions of the file that can be recovered shall be written. The editor shall behave as if the contents of the edit buffer have already been modified.

Current file: Set as described for the edit command.

Current column: Set as described for the edit command.

Rewind Synopsis:

rew[ind][!]

If no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, it shall be an error, unless the file is successfully written as specified by the autowrite option.

If the argument list is empty, it shall be an error.

The current argument list reference and the current pathname shall be set to the first filename in the argument list.

Replace the contents of the edit buffer with the contents of the file named by the current pathname. If for any reason the contents of the file cannot be accessed, the edit buffer shall be empty.

This command shall be affected by the autowrite and writeany edit options.

Current line: Set as described for the edit command.

Current column: Set as described for the edit command.

Set Synopsis:

se[t][option[=[value]] ...][nooption ...][option? ...][all]

When no arguments are specified, write the value of the term edit option and those options whose values have been changed from the default settings; when the argument all is specified, write all of the option values.

Giving an option name followed by the character '?' shall cause the current value of that option to be written. The '?' can be separated from the option name by zero or more <blank> characters. The '?' shall be necessary only for Boolean valued options. Boolean options can be given values by the form set option to turn them on or set nooption to turn them off; string and numeric options can be assigned by the form set option=value. Any <blank> characters in strings can be included as is by preceding each <blank> with an escaping <backslash>. More than one option can be set or listed by a single set command by specifying multiple arguments, each separated from the next by one or more <blank> characters.

See Edit Options in ex for details about specific options.

Current line: Unchanged.

Current column: Unchanged.

Shell Synopsis:

sh[ell]

Invoke the program named in the shell edit option with the single argument -i (interactive mode). Editing shall be resumed when the program exits.

Current line: Unchanged.

Current column: Unchanged.

Source Synopsis:

so[urce] file

Read and execute ex commands from file. Lines in the file that are blank lines shall be ignored.

Current line: As specified for the individual ex commands.

Current column: As specified for the individual ex commands.

Substitute Synopsis:

[2addr] s[ubstitute][/pattern/repl/[options][count][flags]] [2addr] &[options][count][flags]] [2addr] ~[options][count][flags]]

Replace the first instance of the pattern pattern by the string repl on each specified line. (See Regular Expressions in ex and Replacement Strings in ex.) Any non-alphabetic, non-<blank> delimiter other than <backslash>, '|', <newline>, or double-quote can be used instead of '/'. <backslash> characters can be used to escape delimiters, <backslash> characters, and other special characters.

The trailing delimiter can be omitted from pattern or from repl at the end of the command line. If both pattern and repl are not specified or are empty (for example, "//"), the last s command shall be repeated. If only pattern is not specified or is empty, the last regular expression used in the editor shall be used as the pattern. If only repl is not specified or is empty, the pattern shall be replaced by nothing. If the entire replacement pattern is '%', the last replacement pattern to an s command shall be used.

Entering a <carriage-return> in repl (which requires an escaping <backslash> in ex mode and an escaping <control>‐V in open or vi mode) shall split the line at that point, creating a new line in the edit buffer. The <carriage-return> shall be discarded.

If options includes the letter 'g' (global), all non-overlapping instances of the pattern in the line shall be replaced.

If options includes the letter 'c' (confirm), then before each substitution the line shall be written; the written line shall reflect all previous substitutions. On the following line, <space> characters shall be written beneath the characters from the line that are before the pattern to be replaced, and '^' characters written beneath the characters included in the pattern to be replaced. The ex utility shall then wait for a response from the user. An affirmative response shall cause the substitution to be done, while any other input shall not make the substitution. An affirmative response shall consist of a line with the affirmative response (as defined by the current locale) at the beginning of the line. This line shall be subject to editing in the same way as the ex command line.

If interrupted (see the ASYNCHRONOUS EVENTS section), any modifications confirmed by the user shall be preserved in the edit buffer after the interrupt.

If the remembered search direction is not set, the s command shall set it to forward.

In the second Synopsis, the & command shall repeat the previous substitution, as if the & command were replaced by:

s/pattern/repl/

where pattern and repl are as specified in the previous s, &, or ~ command.

In the third Synopsis, the ~ command shall repeat the previous substitution, as if the '~' were replaced by:

s/pattern/repl/

where pattern shall be the last regular expression specified to the editor, and repl shall be from the previous substitution (including & and ~) command.

These commands shall be affected by the LC_MESSAGES environment variable.

Current line: Set to the last line in which a substitution occurred, or, unchanged if no substitution occurred.

Current column: Set to non-<blank>.

Suspend Synopsis:

su[spend][!] st[op][!]

Allow control to return to the invoking process; ex shall suspend itself as if it had received the SIGTSTP signal. The suspension shall occur only if job control is enabled in the invoking shell (see the description of set -m).

These commands shall be affected by the autowrite and writeany edit options.

The current susp character (see stty(1p)) shall be equivalent to the suspend command.

Tag Synopsis:

ta[g][!] tagstring

The results are unspecified if the format of a tags file is not as specified by the ctags utility (see ctags(1p)) description.

The tag command shall search for tagstring in the tag files referred to by the tag edit option, in the order they are specified, until a reference to tagstring is found. Files shall be searched from beginning to end. If no reference is found, it shall be an error and an error message to this effect shall be written. If the reference is not found, or if an error occurs while processing a file referred to in the tag edit option, it shall be an error, and an error message shall be written at the first occurrence of such an error.

Otherwise, if the tags file contained a pattern, the pattern shall be treated as a regular expression used in the editor; for example, for the purposes of the s command.

If the tagstring is in a file with a different name than the current pathname, set the current pathname to the name of that file, and replace the contents of the edit buffer with the contents of that file. In this case, if no '!' is appended to the command name, and the edit buffer has been modified since the last complete write, it shall be an error, unless the file is successfully written as specified by the autowrite option.

This command shall be affected by the autowrite, tag, taglength, and writeany edit options.

Current line: If the tags file contained a line number, set to that line number. If the line number is larger than the last line in the edit buffer, an error message shall be written and the current line shall be set as specified for the edit command.

If the tags file contained a pattern, set to the first occurrence of the pattern in the file. If no matching pattern is found, an error message shall be written and the current line shall be set as specified for the edit command.

Current column: If the tags file contained a line-number reference and that line-number was not larger than the last line in the edit buffer, or if the tags file contained a pattern and that pattern was found, set to non-<blank>. Otherwise, set as specified for the edit command.

Unabbreviate Synopsis:

una[bbrev] lhs

If lhs is not an entry in the current list of abbreviations (see Abbreviate), it shall be an error. Otherwise, delete lhs from the list of abbreviations.

Current line: Unchanged.

Current column: Unchanged.

Undo Synopsis:

u[ndo]

Reverse the changes made by the last command that modified the contents of the edit buffer, including undo. For this purpose, the global, v, open, and visual commands, and commands resulting from buffer executions and mapped character expansions, are considered single commands.

If no action that can be undone preceded the undo command, it shall be an error.

If the undo command restores lines that were marked, the mark shall also be restored unless it was reset subsequent to the deletion of the lines.

Current line:

1. If lines are added or changed in the file, set to the first line added or changed.

2. Set to the line before the first line deleted, if it exists.

3. Set to 1 if the edit buffer is not empty.

4. Set to zero.

Current column: Set to non-<blank>.

Unmap Synopsis:

unm[ap][!] lhs

If '!' is appended to the command name, and if lhs is not an entry in the list of text input mode map definitions, it shall be an error. Otherwise, delete lhs from the list of text input mode map definitions.

If no '!' is appended to the command name, and if lhs is not an entry in the list of command mode map definitions, it shall be an error. Otherwise, delete lhs from the list of command mode map definitions.

Current line: Unchanged.

Current column: Unchanged.

Version Synopsis:

ve[rsion]

Write a message containing version information for the editor. The format of the message is unspecified.

Current line: Unchanged.

Current column: Unchanged.

Visual Synopsis:

[1addr] vi[sual][type][count][flags]

If ex is currently in open or visual mode, the Synopsis and behavior of the visual command shall be the same as the edit command, as specified by Edit.

Otherwise, this command need not be supported on block-mode terminals or terminals with insufficient capabilities. If standard input, standard output, or standard error are not terminal devices, the results are unspecified.

If count is specified, the value of the window edit option shall be set to count (as described in window). If the '^' type character was also specified, the window edit option shall be set before being used by the type character.

Enter visual mode. If type is not specified, it shall be as if a type of '+' was specified. The type shall cause the following effects:

+ Place the beginning of the specified line at the top of the display.

- Place the end of the specified line at the bottom of the display.

. Place the beginning of the specified line in the middle of the display.

^ If the specified line is less than or equal to the value of the window edit option, set the line to 1; otherwise, decrement the line by the value of the window edit option minus 1. Place the beginning of this line as close to the bottom of the displayed lines as possible, while still displaying the value of the window edit option number of lines.

Current line: Set to the specified line.

Current column: Set to non-<blank>.

Write Synopsis:

[2addr] w[rite][!][>>][file] [2addr] w[rite][!][file] [2addr] wq[!][>>][file]

If no lines are specified, the lines shall default to the entire file.

The command wq shall be equivalent to a write command followed by a quit command; wq! shall be equivalent to write! followed by quit. In both cases, if the write command fails, the quit shall not be attempted.

If the command name is not followed by one or more <blank> characters, or file is not preceded by a '!' character, the write shall be to a file.

1. If the >> argument is specified, and the file already exists, the lines shall be appended to the file instead of replacing its contents. If the >> argument is specified, and the file does not already exist, it is unspecified whether the write shall proceed as if the >> argument had not been specified or if the write shall fail.

2. If the readonly edit option is set (see readonly), the write shall fail.

3. If file is specified, and is not the current pathname, and the file exists, the write shall fail.

4. If file is not specified, the current pathname shall be used. If there is no current pathname, the write command shall fail.

5. If the current pathname is used, and the current pathname has been changed by the file or read commands, and the file exists, the write shall fail. If the write is successful, subsequent writes shall not fail for this reason (unless the current pathname is changed again).

6. If the whole edit buffer is not being written, and the file to be written exists, the write shall fail.

For rules 1., 2., 3., and 5., the write can be forced by appending the character '!' to the command name.

For rules 2., 3., and 5., the write can be forced by setting the writeany edit option.

Additional, implementation-defined tests may cause the write to fail.

If the edit buffer is empty, a file without any contents shall be written.

An informational message shall be written noting the number of lines and bytes written.

Otherwise, if the command is followed by one or more <blank> characters, and the file is preceded by '!', the rest of the line after the '!' shall have '%', '#', and '!' characters expanded as described in Command Line Parsing in ex.

The ex utility shall then pass two arguments to the program named by the shell edit option; the first shall be -c and the second shall be the expanded arguments to the write command as a single argument. The specified lines shall be written to the standard input of the command. The standard error and standard output of the program, if any, shall be written as described for the print command. If the last character in that output is not a <newline>, a <newline> shall be written at the end of the output.

The special meaning of the '!' following the write command can be overridden by escaping it with a <backslash> character.

Current line: Unchanged.

Current column: Unchanged.

Write and Exit Synopsis:

[2addr] x[it][!][file]

If the edit buffer has not been modified since the last complete write, xit shall be equivalent to the quit command, or if a '!' is appended to the command name, to quit!.

Otherwise, xit shall be equivalent to the wq command, or if a '!' is appended to the command name, to wq!.

Current line: Unchanged.

Current column: Unchanged.

Yank Synopsis:

[2addr] ya[nk][buffer][count]

Copy the specified lines to the specified buffer (by default, the unnamed buffer), which shall become a line-mode buffer.

Current line: Unchanged.

Current column: Unchanged.

Adjust Window Synopsis:

[1addr] z[!][type ...][count][flags]

If no line is specified, the current line shall be the default; if type is omitted as well, the current line value shall first be incremented by 1. If incrementing the current line would cause it to be greater than the last line in the edit buffer, it shall be an error.

If there are <blank> characters between the type argument and the preceding z command name or optional '!' character, it shall be an error.

If count is specified, the value of the window edit option shall be set to count (as described in window). If count is omitted, it shall default to 2 times the value of the scroll edit option, or if ! was specified, the number of lines in the display minus 1.

If type is omitted, then count lines starting with the specified line shall be written. Otherwise, count lines starting with the line specified by the type argument shall be written.

The type argument shall change the lines to be written. The possible values of type are as follows:

- The specified line shall be decremented by the following value:

(((number of '-' characters) x count) -1)

If the calculation would result in a number less than 1, it shall be an error. Write lines from the edit buffer, starting at the new value of line, until count lines or the last line in the edit buffer has been written.

+ The specified line shall be incremented by the following value:

(((number of '+' characters) -1) x count) +1

If the calculation would result in a number greater than the last line in the edit buffer, it shall be an error. Write lines from the edit buffer, starting at the new value of line, until count lines or the last line in the edit buffer has been written.

=,. If more than a single '.' or '=' is specified, it shall be an error. The following steps shall be taken:

1. If count is zero, nothing shall be written.

2. Write as many of the N lines before the current line in the edit buffer as exist. If count or '!' was specified, N shall be:

(count -1) /2

Otherwise, N shall be:

(count -3) /2

If N is a number less than 3, no lines shall be written.

3. If '=' was specified as the type character, write a line consisting of the smaller of the number of columns in the display divided by two, or 40 '-' characters.

4. Write the current line.

5. Repeat step 3.

6. Write as many of the N lines after the current line in the edit buffer as exist. N shall be defined as in step 2. If N is a number less than 3, no lines shall be written. If count is less than 3, no lines shall be written.

^ The specified line shall be decremented by the following value:

(((number of '^' characters) +1) x count) -1

If the calculation would result in a number less than 1, it shall be an error. Write lines from the edit buffer, starting at the new value of line, until count lines or the last line in the edit buffer has been written.

Current line: Set to the last line written, unless the type is =, in which case, set to the specified line.

Current column: Set to non-<blank>.

Escape Synopsis:

! command [addr]! command

The contents of the line after the '!' shall have '%', '#', and '!' characters expanded as described in Command Line Parsing in ex. If the expansion causes the text of the line to change, it shall be redisplayed, preceded by a single '!' character.

The ex utility shall execute the program named by the shell edit option. It shall pass two arguments to the program; the first shall be -c, and the second shall be the expanded arguments to the ! command as a single argument.

If no lines are specified, the standard input, standard output, and standard error of the program shall be set to the standard input, standard output, and standard error of the ex program when it was invoked. In addition, a warning message shall be written if the edit buffer has been modified since the last complete write, and the warn edit option is set.

If lines are specified, they shall be passed to the program as standard input, and the standard output and standard error of the program shall replace those lines in the edit buffer. Each line in the program output (as delimited by <newline> characters or the end of the output if it is not immediately preceded by a <newline>), shall be a separate line in the edit buffer. Any occurrences of <carriage-return> and <newline> pairs in the output shall be treated as single <newline> characters. The specified lines shall be copied into the unnamed buffer before they are replaced, and the unnamed buffer shall become a line- mode buffer.

If in ex mode, a single '!' character shall be written when the program completes.

This command shall be affected by the shell and warn edit options. If no lines are specified, this command shall be affected by the autowrite and writeany edit options. If lines are specified, this command shall be affected by the autoprint edit option.

Current line:

1. If no lines are specified, unchanged.

2. Otherwise, set to the last line read in, if any lines are read in.

3. Otherwise, set to the line before the first line of the lines specified, if that line exists.

4. Otherwise, set to the first line of the edit buffer if the edit buffer is not empty.

5. Otherwise, set to zero.

Current column: If no lines are specified, unchanged. Otherwise, set to non-<blank>.

Shift Left Synopsis:

[2addr] <[< ...][count][flags]

Shift the specified lines to the start of the line; the number of column positions to be shifted shall be the number of command characters times the value of the shiftwidth edit option. Only leading <blank> characters shall be deleted or changed into other <blank> characters in shifting; other characters shall not be affected.

Lines to be shifted shall be copied into the unnamed buffer, which shall become a line-mode buffer.

This command shall be affected by the autoprint edit option.

Current line: Set to the last line in the lines specified.

Current column: Set to non-<blank>.

Shift Right Synopsis:

[2addr] >[> ...][count][flags]

Shift the specified lines away from the start of the line; the number of column positions to be shifted shall be the number of command characters times the value of the shiftwidth edit option. The shift shall be accomplished by adding <blank> characters as a prefix to the line or changing leading <blank> characters into other <blank> characters. Empty lines shall not be changed.

Lines to be shifted shall be copied into the unnamed buffer, which shall become a line-mode buffer.

This command shall be affected by the autoprint edit option.

Current line: Set to the last line in the lines specified.

Current column: Set to non-<blank>.

<control>‐D Synopsis:

<control>-D

Write the next n lines, where n is the minimum of the values of the scroll edit option and the number of lines after the current line in the edit buffer. If the current line is the last line of the edit buffer it shall be an error.

Current line: Set to the last line written.

Current column: Set to non-<blank>.

Write Line Number Synopsis:

[1addr] = [flags]

If line is not specified, it shall default to the last line in the edit buffer. Write the line number of the specified line.

Current line: Unchanged.

Current column: Unchanged.

Execute Synopsis:

[2addr] @ buffer [2addr] * buffer

If no buffer is specified or is specified as '@' or '*', the last buffer executed shall be used. If no previous buffer has been executed, it shall be an error.

For each line specified by the addresses, set the current line ('.') to the specified line, and execute the contents of the named buffer (as they were at the time the @ command was executed) as ex commands. For each line of a line-mode buffer, and all but the last line of a character-mode buffer, the ex command parser shall behave as if the line was terminated by a <newline>.

If an error occurs during this process, or a line specified by the addresses does not exist when the current line would be set to it, or more than a single line was specified by the addresses, and the contents of the edit buffer are replaced (for example, by the ex :edit command) an error message shall be written, and no more commands resulting from the execution of this command shall be processed.

Current line: As specified for the individual ex commands.

Current column: As specified for the individual ex commands.

Regular Expressions in ex The ex utility shall support regular expressions that are a superset of the basic regular expressions described in the Base Definitions volume of POSIX.1‐2017, Section 9.3, Basic Regular Expressions. A null regular expression ("//") shall be equivalent to the last regular expression encountered.

Regular expressions can be used in addresses to specify lines and, in some commands (for example, the substitute command), to specify portions of a line to be substituted.

The following constructs can be used to enhance the basic regular expressions:

\< Match the beginning of a word. (See the definition of word at the beginning of Command Descriptions in ex.)

\> Match the end of a word.

~ Match the replacement part of the last substitute command. The <tilde> ('~') character can be escaped in a regular expression to become a normal character with no special meaning. The <backslash> shall be discarded.

When the editor option magic is not set, the only characters with special meanings shall be '^' at the beginning of a pattern, '$' at the end of a pattern, and <backslash>. The characters '.', '*', '[', and '~' shall be treated as ordinary characters unless preceded by a <backslash>; when preceded by a <backslash> they shall regain their special meaning, or in the case of <backslash>, be handled as a single <backslash>. <backslash> characters used to escape other characters shall be discarded.

Replacement Strings in ex The character '&' ('\&' if the editor option magic is not set) in the replacement string shall stand for the text matched by the pattern to be replaced. The character '~' ('\~' if magic is not set) shall be replaced by the replacement part of the previous substitute command. The sequence '\n', where n is an integer, shall be replaced by the text matched by the corresponding back- reference expression. If the corresponding back-reference expression does not match, then the characters '\n' shall be replaced by the empty string.

The strings '\l', '\u', '\L', and '\U' can be used to modify the case of elements in the replacement string (using the '\&' or "\"digit) notation. The string '\l' ('\u') shall cause the character that follows to be converted to lowercase (uppercase). The string '\L' ('\U') shall cause all characters subsequent to it to be converted to lowercase (uppercase) as they are inserted by the substitution until the string '\e' or '\E', or the end of the replacement string, is encountered.

Otherwise, any character following a <backslash> shall be treated as that literal character, and the escaping <backslash> shall be discarded.

An example of case conversion with the s command is as follows:

:p The cat sat on the mat. :s/\<.at\>/\u&/gp The Cat Sat on the Mat. :s/S\(.*\)M/S\U\1\eM/p The Cat SAT ON THE Mat.

Edit Options in ex The ex utility has a number of options that modify its behavior. These options have default settings, which can be changed using the set command.

Options are Boolean unless otherwise specified.

autoindent, ai [Default unset]

If autoindent is set, each line in input mode shall be indented (using first as many <tab> characters as possible, as determined by the editor option tabstop, and then using <space> characters) to align with another line, as follows:

1. If in open or visual mode and the text input is part of a line-oriented command (see the EXTENDED DESCRIPTION in vi(1p)), align to the first column.

2. Otherwise, if in open or visual mode, indentation for each line shall be set as follows:

a. If a line was previously inserted as part of this command, it shall be set to the indentation of the last inserted line by default, or as otherwise specified for the <control>‐D character in Input Mode Commands in vi.

b. Otherwise, it shall be set to the indentation of the previous current line, if any; otherwise, to the first column.

3. For the ex a, i, and c commands, indentation for each line shall be set as follows:

a. If a line was previously inserted as part of this command, it shall be set to the indentation of the last inserted line by default, or as otherwise specified for the eof character in Scroll.

b. Otherwise, if the command is the ex a command, it shall be set to the line appended after, if any; otherwise to the first column.

c. Otherwise, if the command is the ex i command, it shall be set to the line inserted before, if any; otherwise to the first column.

d. Otherwise, if the command is the ex c command, it shall be set to the indentation of the line replaced.

autoprint, ap [Default set]

If autoprint is set, the current line shall be written after each ex command that modifies the contents of the current edit buffer, and after each tag command for which the tag search pattern was found or tag line number was valid, unless:

1. The command was executed while in open or visual mode.

2. The command was executed as part of a global or v command or @ buffer execution.

3. The command was the form of the read command that reads a file into the edit buffer.

4. The command was the append, change, or insert command.

5. The command was not terminated by a <newline>.

6. The current line shall be written by a flag specified to the command; for example, delete # shall write the current line as specified for the flag modifier to the delete command, and not as specified by the autoprint edit option.

autowrite, aw [Default unset]

If autowrite is set, and the edit buffer has been modified since it was last completely written to any file, the contents of the edit buffer shall be written as if the ex write command had been specified without arguments, before each command affected by the autowrite edit option is executed. Appending the character '!' to the command name of any of the ex commands except '!' shall prevent the write. If the write fails, it shall be an error and the command shall not be executed.

beautify, bf [Default unset]

If beautify is set, all non-printable characters, other than <tab>, <newline>, and <form-feed> characters, shall be discarded from text read in from files.

directory, dir [Default implementation-defined]

The value of this option specifies the directory in which the editor buffer is to be placed. If this directory is not writable by the user, the editor shall quit.

edcompatible, ed [Default unset]

Causes the presence of g and c suffixes on substitute commands to be remembered, and toggled by repeating the suffixes.

errorbells, eb [Default unset]

If the editor is in ex mode, and the terminal does not support a standout mode (such as inverse video), and errorbells is set, error messages shall be preceded by alerting the terminal.

exrc [Default unset]

If exrc is set, ex shall access any .exrc file in the current directory, as described in Initialization in ex and vi. If exrc is not set, ex shall ignore any .exrc file in the current directory during initialization, unless the current directory is that named by the HOME environment variable.

ignorecase, ic [Default unset]

If ignorecase is set, characters that have uppercase and lowercase representations shall have those representations considered as equivalent for purposes of regular expression comparison.

The ignorecase edit option shall affect all remembered regular expressions; for example, unsetting the ignorecase edit option shall cause a subsequent vi n command to search for the last basic regular expression in a case-sensitive fashion.

list [Default unset]

If list is set, edit buffer lines written while in ex command mode shall be written as specified for the print command with the l flag specified. In open or visual mode, each edit buffer line shall be displayed as specified for the ex print command with the l flag specified. In open or visual text input mode, when the cursor does not rest on any character in the line, it shall rest on the '$' marking the end of the line.

magic [Default set]

If magic is set, modify the interpretation of characters in regular expressions and substitution replacement strings (see Regular Expressions in ex and Replacement Strings in ex).

mesg [Default set]

If mesg is set, the permission for others to use the write or talk commands to write to the terminal shall be turned on while in open or visual mode. The shell-level command mesg n shall take precedence over any setting of the ex mesg option; that is, if mesg y was issued before the editor started (or in a shell escape), such as:

:!mesg y

the mesg option in ex shall suppress incoming messages, but the mesg option shall not enable incoming messages if mesg n was issued.

number, nu [Default unset]

If number is set, edit buffer lines written while in ex command mode shall be written with line numbers, in the format specified by the print command with the # flag specified. In ex text input mode, each line shall be preceded by the line number it will have in the file.

In open or visual mode, each edit buffer line shall be displayed with a preceding line number, in the format specified by the ex print command with the # flag specified. This line number shall not be considered part of the line for the purposes of evaluating the current column; that is, column position 1 shall be the first column position after the format specified by the print command.

paragraphs, para [Default in the POSIX locale IPLPPPQPP LIpplpipbp]

The paragraphs edit option shall define additional paragraph boundaries for the open and visual mode commands. The paragraphs edit option can be set to a character string consisting of zero or more character pairs. It shall be an error to set it to an odd number of characters.

prompt [Default set]

If prompt is set, ex command mode input shall be prompted for with a <colon> (':'); when unset, no prompt shall be written.

readonly [Default see text]

If the readonly edit option is set, read-only mode shall be enabled (see Write). The readonly edit option shall be initialized to set if either of the following conditions are true:

* The command-line option -R was specified.

* Performing actions equivalent to the access() function called with the following arguments indicates that the file lacks write permission:

1. The current pathname is used as the path argument.

2. The constant W_OK is used as the amode argument.

The readonly edit option may be initialized to set for other, implementation-defined reasons. The readonly edit option shall not be initialized to unset based on any special privileges of the user or process. The readonly edit option shall be reinitialized each time that the contents of the edit buffer are replaced (for example, by an edit or next command) unless the user has explicitly set it, in which case it shall remain set until the user explicitly unsets it. Once unset, it shall again be reinitialized each time that the contents of the edit buffer are replaced.

redraw [Default unset]

The editor simulates an intelligent terminal on a dumb terminal. (Since this is likely to require a large amount of output to the terminal, it is useful only at high transmission speeds.)

remap [Default set]

If remap is set, map translation shall allow for maps defined in terms of other maps; translation shall continue until a final product is obtained. If unset, only a one-step translation shall be done.

report [Default 5]

The value of this report edit option specifies what number of lines being added, copied, deleted, or modified in the edit buffer will cause an informational message to be written to the user. The following conditions shall cause an informational message. The message shall contain the number of lines added, copied, deleted, or modified, but is otherwise unspecified.

* An ex or vi editor command, other than open, undo, or visual, that modifies at least the value of the report edit option number of lines, and which is not part of an ex global or v command, or ex or vi buffer execution, shall cause an informational message to be written.

* An ex yank or vi y or Y command, that copies at least the value of the report edit option plus 1 number of lines, and which is not part of an ex global or v command, or ex or vi buffer execution, shall cause an informational message to be written.

* An ex global, v, open, undo, or visual command or ex or vi buffer execution, that adds or deletes a total of at least the value of the report edit option number of lines, and which is not part of an ex global or v command, or ex or vi buffer execution, shall cause an informational message to be written. (For example, if 3 lines were added and 8 lines deleted during an ex visual command, 5 would be the number compared against the report edit option after the command completed.)

scroll, scr [Default (number of lines in the display -1)/2]

The value of the scroll edit option shall determine the number of lines scrolled by the ex <control>‐D and z commands. For the vi <control>‐D and <control>‐U commands, it shall be the initial number of lines to scroll when no previous <control>‐D or <control>‐U command has been executed.

sections [Default in the POSIX locale NHSHH HUnhsh]

The sections edit option shall define additional section boundaries for the open and visual mode commands. The sections edit option can be set to a character string consisting of zero or more character pairs; it shall be an error to set it to an odd number of characters.

shell, sh [Default from the environment variable SHELL]

The value of this option shall be a string. The default shall be taken from the SHELL environment variable. If the SHELL environment variable is null or empty, the sh (see sh(1p)) utility shall be the default.

shiftwidth, sw [Default 8]

The value of this option shall give the width in columns of an indentation level used during autoindentation and by the shift commands (< and >).

showmatch, sm [Default unset]

The functionality described for the showmatch edit option need not be supported on block-mode terminals or terminals with insufficient capabilities.

If showmatch is set, in open or visual mode, when a ')' or '}' is typed, if the matching '(' or '{' is currently visible on the display, the matching '(' or '{' shall be flagged moving the cursor to its location for an unspecified amount of time.

showmode [Default unset]

If showmode is set, in open or visual mode, the current mode that the editor is in shall be displayed on the last line of the display. Command mode and text input mode shall be differentiated; other unspecified modes and implementation- defined information may be displayed.

slowopen [Default unset]

If slowopen is set during open and visual text input modes, the editor shall not update portions of the display other than those display line columns that display the characters entered by the user (see Input Mode Commands in vi).

tabstop, ts [Default 8]

The value of this edit option shall specify the column boundary used by a <tab> in the display (see autoprint, ap and Input Mode Commands in vi).

taglength, tl [Default zero]

The value of this edit option shall specify the maximum number of characters that are considered significant in the user-specified tag name and in the tag name from the tags file. If the value is zero, all characters in both tag names shall be significant.

tags [Default see text]

The value of this edit option shall be a string of <blank>-delimited pathnames of files used by the tag command. The default value is unspecified.

term [Default from the environment variable TERM]

The value of this edit option shall be a string. The default shall be taken from the TERM variable in the environment. If the TERM environment variable is empty or null, the default is unspecified. The editor shall use the value of this edit option to determine the type of the display device.

The results are unspecified if the user changes the value of the term edit option after editor initialization.

terse [Default unset]

If terse is set, error messages may be less verbose. However, except for this caveat, error messages are unspecified. Furthermore, not all error messages need change for different settings of this option.

warn [Default set]

If warn is set, and the contents of the edit buffer have been modified since they were last completely written, the editor shall write a warning message before certain ! commands (see Escape).

window [Default see text]

A value used in open and visual mode, by the <control>‐B and <control>‐F commands, and, in visual mode, to specify the number of lines displayed when the screen is repainted.

If the -w command-line option is not specified, the default value shall be set to the value of the LINES environment variable. If the LINES environment variable is empty or null, the default shall be the number of lines in the display minus 1.

Setting the window edit option to zero or to a value greater than the number of lines in the display minus 1 (either explicitly or based on the -w option or the LINES environment variable) shall cause the window edit option to be set to the number of lines in the display minus 1.

The baud rate of the terminal line may change the default in an implementation-defined manner.

wrapmargin, wm [Default 0]

If the value of this edit option is zero, it shall have no effect.

If not in the POSIX locale, the effect of this edit option is implementation-defined.

Otherwise, it shall specify a number of columns from the ending margin of the terminal.

During open and visual text input modes, for each character for which any part of the character is displayed in a column that is less than wrapmargin columns from the ending margin of the display line, the editor shall behave as follows:

1. If the character triggering this event is a <blank>, it, and all immediately preceding <blank> characters on the current line entered during the execution of the current text input command, shall be discarded, and the editor shall behave as if the user had entered a single <newline> instead. In addition, if the next user-entered character is a <space>, it shall be discarded as well.

2. Otherwise, if there are one or more <blank> characters on the current line immediately preceding the last group of inserted non-<blank> characters which was entered during the execution of the current text input command, the <blank> characters shall be replaced as if the user had entered a single <newline> instead.

If the autoindent edit option is set, and the events described in 1. or 2. are performed, any <blank> characters at or after the cursor in the current line shall be discarded.

The ending margin shall be determined by the system or overridden by the user, as described for COLUMNS in the ENVIRONMENT VARIABLES section and the Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment Variables.

wrapscan, ws [Default set]

If wrapscan is set, searches (the ex / or ? addresses, or open and visual mode /, ?, N, and n commands) shall wrap around the beginning or end of the edit buffer; when unset, searches shall stop at the beginning or end of the edit buffer.

writeany, wa [Default unset]

If writeany is set, some of the checks performed when executing the ex write commands shall be inhibited, as described in editor option autowrite.