Movatterモバイル変換


[0]ホーム

URL:


<<<PreviousHomeNext>>>


NAME

ex — text editor

SYNOPSIS

[UP][Option Start] ex[-rR] [-s|-v] [-ccommand][-ttagstring] [-wsize] [file...][Option End]

DESCRIPTION

Theex utility is a line-oriented text editor. There are two other modes of the editor—open and visual—in whichscreen-oriented editing is available. This is described more fully by theexopen andvisual commands and invi.

If an operand is'-', the results are unspecified.

This section uses the termedit buffer to describe the current working text. No specific implementation is implied bythis term. All editing changes are performed on the edit buffer, and no changes to it shall affect any file until an editor commandwrites the file.

Certain terminals do not have all the capabilities necessary to support the completeex definition, such as thefull-screen editing commands (visual mode oropen mode). When these commands cannot be supported on such terminals,this condition shall not produce an error message such as "not an editor command" or report a syntax error. The implementationmay either accept the commands and produce results on the screen that are the result of an unsuccessful attempt to meet therequirements of this volume of POSIX.1-2024 or report an error describing the terminal-related deficiency.

OPTIONS

Theex utility shall conform to XBD12.2 Utility SyntaxGuidelines, except for the unspecified usage of'-', and that'+' may be recognized as an optiondelimiter as well as'-'.

The following options shall be supported:

-c command
Specify an initial command to be executed in the first edit buffer loaded from an existing file (see the EXTENDED DESCRIPTIONsection). Implementations may support more than a single-c option. In such implementations, the specified commands shall beexecuted in the order specified on the command line.
-r
Recover the named files (see the EXTENDED DESCRIPTION section). Recovery information for a file shall be saved during an editoror system crash (for example, when the editor is terminated by a signal which the editor can catch), or after the use of anexpreserve command.

Acrash in this context is an unexpected failure of the system or utility that requires restarting the failed system orutility. A system crash implies that any utilities running at the time also crash. In the case of an editor or system crash, thenumber of changes to the edit buffer (since the most recentpreserve command) that will be recovered is unspecified.

If nofile operands are given and the-t option is not specified, all other options, theEXINIT variable,and any.exrc files shall be ignored; a list of all recoverable files available to the invoking user shall be written, andthe editor shall exit normally without further action.

-R
Setreadonly edit option.
-s
Prepareex for batch use by taking the following actions:
  • Suppress writing prompts and informational (but not diagnostic) messages.

  • Ignore the value ofTERM and any implementation default terminal type and assume the terminal is a type incapable ofsupporting open or visual modes; see thevisual command and the description ofvi.

  • Suppress the use of theEXINIT environment variable and the reading of any.exrc file; see the EXTENDEDDESCRIPTION section.

  • Suppress autoindentation, ignoring the value of theautoindent edit option.

-t tagstring
Edit the file containing the specifiedtagstring; seectags. The tagsfeature represented by-ttagstring and thetag command is optional. It shall be provided on any system thatalso provides a conforming implementation ofctags; otherwise, the use of-tproduces undefined results. On any system, it shall be an error to specify more than a single-t option.
-v
Begin in visual mode (seevi).
-w size
Set the value of thewindow editor option tosize.

OPERANDS

The following operand shall be supported:

file
A pathname of a file to be edited.

STDIN

The standard input consists of a series of commands and input text, as described in the EXTENDED DESCRIPTION section. Theimplementation may limit each line of standard input to a length of {LINE_MAX}.

If the standard input is not a terminal device, it shall be as if the-s option had been specified.

If a read from the standard input returns an error, or if the editor detects an end-of-file condition from the standard input,it shall be equivalent to a SIGHUP asynchronous event.

INPUT FILES

Input files shall be text files or files that would be text files except for an incomplete last line that is not longer than{LINE_MAX}-1 bytes in length and contains no NUL characters. By default, any incomplete last line shall be treated as if it had atrailing <newline>. The editing of other forms of files may optionally be allowed byex implementations.

The.exrc files and source files shall be text files consisting ofex commands; see the EXTENDED DESCRIPTIONsection.

By default, the editor shall read lines from the files to be edited without interpreting any of those lines as any form ofeditor command.

ENVIRONMENT VARIABLES

The following environment variables shall affect the execution ofex:

COLUMNS
Override the system-selected horizontal screen size. See XBD8. EnvironmentVariables for valid values and results when it is unset or null.
EXINIT
Determine a list ofex commands that are executed on editor start-up. See the EXTENDED DESCRIPTION section for moredetails of the initialization phase.
HOME
Determine a pathname of a directory that shall be searched for an editor start-up file named.exrc; see the EXTENDEDDESCRIPTION section.
LANG
Provide a default value for the internationalization variables that are unset or null. (See XBD8.2 Internationalization Variables for the precedence of internationalizationvariables used to determine the values of locale categories.)
LC_ALL
If set to a non-empty string value, override the values of all the other internationalization variables.
LC_COLLATE

Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regularexpressions.
LC_CTYPE
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files), the behavior of character classes within regular expressions, theclassification of characters as uppercase or lowercase letters, the case conversion of letters, and the detection of wordboundaries.
LC_MESSAGES

Determine the locale used to process affirmative responses, and the locale that should be used to affect the format and contents ofdiagnostic messages written to standard error.
LINES
Override the system-selected vertical screen size, used as the number of lines in a screenful and the vertical screen size invisual mode. See XBD8. Environment Variables for valid values and resultswhen it is unset or null.
NLSPATH
[XSI][Option Start]Determine the location of messages objects and message catalogs.[Option End]
PATH
Determine the search path for the shell command specified in theex editor commands!,shell,read,andwrite, and the open and visual mode command!; see the description of command search and execution in2.9.1.4 Command Search and Execution.
SHELL
Determine the preferred command line interpreter for use as the default value of theshell edit option.
TERM
Determine the name of the terminal type. If this variable is unset or null, an unspecified default terminal type shall beused.

ASYNCHRONOUS EVENTS

The following term is used in this and following sections to specify command and asynchronous event actions:

complete write

A complete write is a write of the entire contents of the edit buffer to a file of a type other than a terminal device, or thesaving of the edit buffer caused by the user executing theexpreserve command. Writing the contents of the editbuffer to a temporary file that will be removed when the editor exits shall not be considered a complete write.

The following actions shall be taken upon receipt of signals:

SIGINT
If the standard input is not a terminal device,ex shall not write the file or return to command or text input mode, andshall exit with a non-zero exit status.

Otherwise, if executing an open or visual text input mode command,ex in receipt of SIGINT shall behave identically toits receipt of the <ESC> character.

Otherwise:

  1. If executing anex text input mode command, all input lines that have been completely entered shall be resolved into theedit buffer, and any partially entered line shall be discarded.

  2. If there is a currently executing command, it shall be aborted and a message displayed. Unless otherwise specified by theex orvi command descriptions, it is unspecified whether any lines modified by theexecuting command appear modified, or as they were before being modified by the executing command, in the buffer.

    If the currently executing command was a motion command, its associated command shall be discarded.

  3. If in open or visual command mode, the terminal shall be alerted.

  4. The editor shall then return to command mode.

SIGCONT
Ifex is in open mode or visual mode, the actions described below for SIGWINCH shall be taken, except that the screenshall always be refreshed (regardless of whether the terminal window size changed).
SIGHUP
If the edit buffer has been modified since the last complete write,ex shall attempt to save the edit buffer so that itcan be recovered later using the-r option or theexrecover command. The editor shall not write the file orreturn to command or text input mode, and shall terminate with a non-zero exit status.
SIGTERM
Refer to SIGHUP.
SIGWINCH
Ifex is in open mode or visual mode, the current terminal window size associated with the terminal on standard outputshall be obtained, as if by a call to XSHtcgetwinsize(). If the terminalwindow size is successfully obtained, it shall be used as follows:
  • If theCOLUMNS environment variable is unset or does not contain a number, the horizontal screen size shall be set to thenumber of columns in the obtained terminal window size.

  • Ifex is in visual mode, the-w option was not specified and theLINES environment variable is unset ordoes not contain a number, the vertical screen size shall be set to the number of rows in the obtained terminal window size.

If the above resulted in either the vertical screen size or the horizontal screen size (or both) changing to a different value,ex shall update the values it has for the number of lines and columns in the display and shall adjust thewindow editoption and the column number at which thewrapmargin edit option takes effect (if non-zero) accordingly (seeEdit Options in ex) and refresh the screen; otherwise,ex may refresh the screen.

The action taken for all other signals is unspecified.

STDOUT

The standard output shall be used only for writing prompts to the user, for informational messages, and for writing lines fromthe file.

STDERR

The standard error shall be used only for diagnostic messages.

OUTPUT FILES

The output fromex shall be text files.

EXTENDED DESCRIPTION

Only theex mode of the editor is described in this section. Seevi foradditional editing capabilities available inex.

When an error occurs,ex shall write a message. If the terminal supports a standout mode (such as inverse video), themessage shall be written in standout mode. If the terminal does not support a standout mode, and the edit optionerrorbellsis 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 theprompt command.Text input mode can be entered by theappend,insert, orchange commands; it can be exited (and command modere-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, namedcurrent andalternate, are maintained by the editor. Anyex commands that take filenamesas arguments shall set them as follows:
  1. If afile argument is specified to theexedit,ex, orrecover commands, or if anextag command replaces the contents of the edit buffer.

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

    2. Otherwise, the alternate pathname shall be set to thefile argument.

  2. If afile argument is specified to theexnext command:

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

  3. If afile argument is specified to theexfile command, the current pathname shall be set to thefile argument, and the alternate pathname shall be set to the previous value of the current pathname.

  4. If afile argument is specified to theexread andwrite commands (that is, when reading or writinga file, and not to the program named by theshell edit option), or afile argument is specified to theexxit command:

    1. If the current pathname has no value, the current pathname shall be set to thefile argument.

    2. Otherwise, the alternate pathname shall be set to thefile 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 hasbeen executed, as thecurrent line value. When the edit buffer contains no lines, the current line shall be zero; seeAddressing in ex.
current column

The current display line column occupied by the cursor. (The columns shall be numbered beginning at 1.) Each command descriptionspecifies the current column after the command has been executed, as thecurrent column value. This column is anideal column that is remembered over the lifetime of the editor. The actual display line column upon which the cursor restsmay be different from the current column; see the cursor positioning discussion inCommand 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 isdisplayed 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 theedit buffer may be limited to the number of characters that will fit in the display. If either limit is exceeded during editing, anerror message shall be written. If either limit is exceeded by a line read in from a file, an error message shall be written andthe 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 lastcomplete write, it shall be equivalent to a SIGHUP asynchronous event. If the system crashes, it shall be equivalent to a SIGHUPasynchronous event.

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

  1. If the environment variableEXINIT is set, the editor shall execute theex commands contained in thatvariable.

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

    1. TheHOME environment variable is not null and not empty.

    2. The file.exrc in the directory referred to by theHOME environment variable:

      1. Exists

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

      3. Is not writable by anyone other than the owner

    the editor shall execute theex commands contained in that file.

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

    1. The current directory is not referred to by theHOME environment variable.

    2. A command in theEXINIT environment variable or a command in the.exrc file in the directory referred to by theHOME environment variable sets the editor optionexrc.

    3. The.exrc file in the current directory:

      1. Exists

      2. 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

      3. Is not writable by anyone other than the owner

    the editor shall attempt to execute theex 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 forownership or permission reasons, it shall be an error.

After theEXINIT 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 theextag command was entered with thespecified argument, with the exception that if tag processing does not result in a file to edit, the effect shall be as describedin step 3. below.

  2. Otherwise, if the user specified any command linefile arguments, the effect shall be as if theexeditcommand was entered with the first of those arguments as itsfile argument.

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

If the-r option was specified, the first time a file in the initial argument list or a file specified by the-toption is edited, if recovery information has previously been saved about it, that information shall be recovered and the editorshall behave as if the contents of the edit buffer have already been modified. If there are multiple instances of the file to berecovered, the one most recently saved shall be recovered, and an informational message that there are previous versions of thefile that can be recovered shall be written. If no recovery information about a file is available, an informational message to thiseffect 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 forwhich recovery information is available, when the-r option is specified) replaces or initializes the contents of the editbuffer, the current line shall be set to the last line of the edit buffer, the current column shall be set to non-<blank>,and theex commands specified with the-c option shall be executed. In this case, the current line and current columnshall 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 atag command is associated with this action, the-c option commands shall beexecuted 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 arespecified by the user, the current argument list shall be empty. If the-t option was specified, it is unspecified whetherany filename resulting from tag processing shall be prepended to the current argument list. In the case where the filename is addedas a prefix to the current argument list, the current argument list reference shall be set to that filename. In the case where thefilename is not added as a prefix to the current argument list, the current argument list reference shall logically be locatedbefore the first of the filenames specified on the command line (for example, a subsequentexnext command shall editthe first filename from the command line). If the-t option was not specified, the current argument list reference shall beto the first of the filenames on the command line.

Addressing in ex

Addressing inex 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 affectedby a command. The current line number is the address of the current line. In each command description, the effect of the command onthe 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 numbern shall address thenth 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 letterfrom the portable character set, the backquote character, or the single-quote character. It shall be an error if the line that wasmarked is not currently present in the edit buffer or the mark has not been set. Lines can be marked with theexmarkork commands, or thevim command.

  5. A regular expression enclosed by <slash> characters ('/') shall address the first line found by searchingforwards from the line following the current line toward the end of the edit buffer and stopping at the first line for which theline excluding the terminating <newline> matches the regular expression. As stated inRegularExpressions 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 expressionencountered. In addition, the second <slash> can be omitted at the end of a command line. If thewrapscan edit optionis set, the search shall wrap around to the beginning of the edit buffer and continue up to and including the current line, so thatthe 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 searchingbackwards from the line preceding the current line toward the beginning of the edit buffer and stopping at the first line for whichthe line excluding the terminating <newline> matches the regular expression. An address consisting of a null regularexpression delimited by <question-mark> characters ("??") shall address the previous line for which the lineexcluding 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 thewrapscan edit option is set, the search shall wraparound from the beginning of the edit buffer to the end of the edit buffer and continue up to and including the current line, sothat 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 thecurrent line plus or minus the number. A'+' or'-' not followed by a decimal number shall address the currentline plus or minus 1.

Addresses can be followed by zero or more address offsets, optionally <blank>-separated. Address offsets are constructedas 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) theaddress.

  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 editbuffer. 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 of1addr and2addr inCommand Descriptions in ex. If more than the required number of addresses are provided to a command thatrequires 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 noaddress is specified before or after a <comma> or <semicolon> separator, it shall be as if the address of the currentline 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 shall the next address be calculated. This feature can be used to determine thestarting 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 thecharacter acquired or lost a special meaning by virtue of being preceded, respectively, by a <backslash> or <control>-Vcharacter. Unless otherwise specified, the escaping character shall be discarded at that time and shall not be further consideredfor any purpose.

Command-line parsing shall be done in the following steps. For each step, characters already evaluated shall be ignored; thatis, 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; seeAddressing in ex.

  5. Leading <blank> characters shall be skipped.

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

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

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

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

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

    2. Otherwise, the implied command shall be theprint command. The last#,p, andl flags specified toanyex command shall be remembered and shall apply to this implied command. Executing theexnumber,print, orlist command shall set the remembered flags to#, nothing, andl, respectively, plus anyother flags specified for that execution of thenumber,print, orlist command.

      Ifex is not currently performing aglobal orv command, and no address or count is specified, the currentline shall be incremented by 1 before the command is executed. If incrementing the current line would result in an address past thelast line in the edit buffer, the command shall fail, and the increment shall not happen.

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

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

    1. Commands that consist of any prefix of the characters in the command namedelete, followed immediately by any of thecharacters'l','p','+','-', or'#' shall be interpreted as adelete command,followed by a <blank>, followed by the characters that were not part of the prefix of thedelete command. The maximumnumber of characters shall be matched to the command namedelete; for example,"del" shall not be treated as"de" followed by the flagl.

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

    3. Commands that consist of the character's', followed by characters that could be interpreted as valid options to thes command, shall be the equivalent of thes 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 thecharacters specified by the user shall be the executed command. In the case of commands where the characters specified by the usercould 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 allpossible matches for commands specified by POSIX.1-2024 have been checked.

  9. If the command is a! command, or if the command is aread command followed by zero or more<blank> characters and a!, or if the command is awrite 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 separateexcommand.
  10. Otherwise, if the command is anedit,ex, ornext command, or avisual command whilein open or visual mode, the next part of the command shall be parsed as follows:
    1. Any'!' character immediately following the command shall be skipped and be part of the command.
    2. Any leading <blank> characters shall be skipped and be part of the command.
    3. 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.
    4. The rest of the command shall be determined by the steps specified in paragraph 12.
  11. Otherwise, if the command is aglobal,open,s, orv command, the next part of thecommand shall be parsed as follows:
    1. Any leading <blank> characters shall be skipped and be part of the command.
    2. If the next character is not an alphanumeric, double-quote, <newline>, <backslash>, or<vertical-line> character:
      1. The next character shall be used as a command delimiter.
      2. If the command is aglobal,open, orv command, characters up to the firstnon-<backslash>-escaped <newline>, or first non-<backslash>-escaped delimiter character, shall be skipped and bepart of the command.
      3. If the command is ans 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.
    3. If the command is aglobal orv command, characters up to the first non-<backslash>-escaped<newline> shall be skipped and be part of the command.
    4. Otherwise, the rest of the command shall be determined by the steps specified in paragraph 12.
  12. Otherwise:
    1. If the command was amap,unmap,abbreviate, orunabbreviate command, characters up tothe first non-<control>-V-escaped <newline>, <vertical-line>, or double-quote character shall be skipped and bepart of the command.
    2. Otherwise, characters up to the first non-<backslash>-escaped <newline>, <vertical-line>, ordouble-quote character shall be skipped and be part of the command.
    3. If the command was anappend,change, orinsert command, and the step 12.b. ended at a<vertical-line> character, any subsequent characters, up to the next non-<backslash>-escaped <newline> shall beused as input text to the command.
    4. If the command was ended by a double-quote character, all subsequent characters, up to the nextnon-<backslash>-escaped <newline>, shall be discarded.
    5. The terminating <newline> or <vertical-line> character shall be discarded and any subsequentcharacters shall be parsed as a separateex command.

Command arguments shall be parsed as described by the Synopsis and Description of each individualexcommand. This parsing shall not be <blank>-sensitive, except for the! argument, which has to follow the command namewithout intervening <blank> characters, and where it would otherwise be ambiguous. For example,count andflagarguments need not be <blank>-separated because"d22p" is not ambiguous, butfile arguments to theexnext command need to be separated by one or more <blank> characters. Any <blank> in command arguments for theabbreviate,unabbreviate,map, andunmap 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 theabbreviate,unabbreviate,map, andunmap commands, anycharacter can be <control>-V-escaped. All such escaped characters shall be treated literally and shall have no specialmeaning. Within command arguments for all otherex commands that are not regular expressions or replacement strings, anycharacter that would otherwise have a special meaning can be <backslash>-escaped. Escaped characters shall be treatedliterally, without special meaning as shell expansion characters or'!','%', and'#' expansioncharacters. SeeRegular Expressions in ex andReplacement Strings inex for descriptions of command arguments that are regular expressions or replacement strings.

Non-<backslash>-escaped'%' characters appearing infile arguments to anyex commandshall be replaced by the current pathname; unescaped'#' characters shall be replaced by the alternate pathname. It shallbe an error if'%' or'#' characters appear unescaped in an argument and their corresponding values are notset.

Non-<backslash>-escaped'!' characters in the arguments to either theex! command orthe open and visual mode! command, or in the arguments to theexread command, where the firstnon-<blank> after the command name is a'!' character, or in the arguments to theexwrite commandwhere the command name is followed by one or more <blank> characters and the first non-<blank> after the command nameis a'!' character, shall be replaced with the arguments to the last of those three commands as they appeared after allunescaped'%','#', and'!' characters were replaced. It shall be an error if'!' charactersappear 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 anex command:

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 bycharacters 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 eitherex command mode orex text input mode,ex shall enable canonical mode input processing, as defined in the System Interfaces volume of POSIX.1-2024.

If inex text input mode:

  1. If thenumber edit option is set,ex shall prompt for input using the line number that would beassigned to the line if it is entered, in the format specified for theexnumber command.
  2. If theautoindent edit option is set,ex shall prompt for input usingautoindent characters,as described by theautoindent edit option.autoindent characters shall follow the line number, if any.

If inex command mode:

  1. If theprompt 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 thesttyeof character instty.

If inex command mode:

If theeof character is the first character entered on the line, the line shall be evaluated as if it containedtwo characters: a <control>-D and a <newline>.

Otherwise, theeof character shall have no special meaning.


If inex text input mode:

If the cursor follows anautoindent character, theautoindent characters in the line shall be modified sothat a part of the next text input character is displayed on the first column in the line after the previousshiftwidth editoption column boundary, and the user shall be prompted again for input for the same line.

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

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

Otherwise, if there are noautoindent or text input characters in the line, theeof character shallbe discarded.

Otherwise, theeof character shall have no special meaning.

<newline>
Synopsis:

<newline>
<control>-J

If inex command mode:

Cause the command line to be parsed; <control>-J shall be mapped to the <newline> for thispurpose.

If inex text input mode:

Terminate the current line. If there are no characters other thanautoindent characters on the line, allcharacters on the line shall be discarded.

Prompt for text input on a new line after the current line. If theautoindent edit option is set, anappropriate number ofautoindent characters shall be added as a prefix to the line as described by theexautoindent edit option.

<backslash>
Synopsis:

<backslash>

Allow the entry of a subsequent <newline> or <control>-J as a literal character, removing any specialmeaning that it may have to the editor during text input mode. The <backslash> character shall be retained and evaluated whenthe 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 haveto the editor during text input mode. The <control>-V character shall be discarded before the command line is parsed or theinput text becomes part of the edit buffer.

If the "literal next" functionality is performed by the underlying system, it is implementation-defined whether acharacter 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 theunderlying 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 beomitted, in which case the specified defaults shall be used.

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

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

If the edit buffer is empty, and the address is specified with a command other than=,append,insert,open,put,read, orvisual, 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 for2addr shall be thecurrent 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, orxit commands, or either address is not zero, it shall be an error.

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

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

flags
One or more of the characters'+','-','#','p', or'l' (ell). The flagcharacters 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 theprint command with the specifiedflags.

The lines to be written are as follows:

  1. All edit buffer lines written during the execution of theex&,~,list,number,open,print,s,visual, andz commands shall be written as specified byflags.
  2. After the completion of anex command with a flag as an argument, the current line shall be written asspecified byflags, 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 theex command to be adjusted by the offset address as described inAddressing in ex. Thisadjustment shall occur before the current line is written as described in 2. above.

The default forflags 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 POSIXlocale. There shall also be one "unnamed" buffer. When no buffer is specified for editor commands that use a buffer, the unnamedbuffer shall be used. Commands that store text into buffers shall store the text as it was before the command took effect, andshall store text occurring earlier in the file before text occurring later in the file, regardless of how the text region wasspecified. Commands that store text into buffers shall store the text into the unnamed buffer as well as any specified buffer.

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

If the specified buffer name is an uppercase character, and the buffer contents are to be modified, the buffershall be appended to rather than being overwritten. If the buffer is not being modified, specifying the buffer name in lowercaseand 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 textincluding characters from more than a single line is being modified by thevic ord commands, the motion character associated with thec ord commands specifies that the buffer text shall bein line mode, or the commands%,`,/,?,(,),N,n,{, or}are used to define a region of text for thec ord commands, the contents of buffers 1 through 8 shall be moved intothe buffer named by the next numerically greater value, the contents of buffer 9 shall be discarded, and the region of text shallbe 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 thewrite 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 toa non-empty buffer shall set the mode to match the characteristic of the text being appended. Appending text to a buffer shallcause the creation of at least one additional line in the buffer. All text stored into buffers byex commands shall be inline mode. Theex commands that use buffers as the source of text specify individually how buffers of different modes arehandled. Each open or visual mode command that uses buffers for any purpose specifies individually the mode of the text stored intothe 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 nocurrent pathname has yet been established it shall be an error, except where specifically noted in the individual commanddescriptions that follow. If the command text contains any of the characters'~','{','[','*','?','$','"', backquote, single-quote, and <backslash>, it shall be subjected tothe 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. Theex utility shall pass twoarguments 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 thecommand text.

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

Thevi commandsN andn begin searching in a forwards or backwardsdirection in the edit buffer based on a remembered search direction, which is initially unset, and is set by theexglobal,v,s, andtag commands, and thevi/ and? commands.
Abbreviate
Synopsis:

ab[breviate][lhs rhs]

Iflhs andrhs are not specified, write the current list of abbreviations and do nothing more.

Implementations may restrict the set of characters accepted inlhs orrhs, except that printablecharacters and <blank> characters shall not be restricted. Additional restrictions shall be implementation-defined.

In bothlhs andrhs, any character may be escaped with a <control>-V, in which case thecharacter shall not be used to delimitlhs fromrhs, 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 matchinglhs,in the text input entered during this command. If it is found, the effect shall be as ifrhs was entered instead oflhs.

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 thecheck, 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 aword character, the set of characters shall consist of the characters inserted immediately before the triggering characters thatare 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 aword character, the set of characters shall consist of the characters that were inserted before the triggering characters that areneither <blank> characters nor word characters, plus the triggering word character.

It is unspecified whether thelhs argument entered for theexabbreviate andunabbreviate commands is replaced in this fashion. Regardless of whether or not the replacement occurs, the effect of thecommand shall be as if the replacement had not occurred.

Current line: Unchanged.

Current column: Unchanged.

Append
Synopsis:

[1addr]a[ppend][!]

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

This command shall be affected by thenumber andautoindent edit options; following the command namewith'!' shall cause theautoindent 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 firstline 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]

Enterex text input mode; the input text shall replace the specified lines. The specified lines shall becopied into the unnamed buffer, which shall become a line mode buffer.

This command shall be affected by thenumber andautoindent edit options; following the command namewith'!' shall cause theautoindent 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 isempty.

Current column: Set to non-<blank>.

Change Directory
Synopsis:

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

Change the current working directory todirectory.

If nodirectory argument is specified, and theHOME environment variable is set to a non-null andnon-empty value,directory shall default to the value named in theHOME environment variable. If theHOMEenvironment variable is empty or is undefined, the default value ofdirectory is implementation-defined.

If no'!' is appended to the command name, and the edit buffer has been modified since the last completewrite, 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]t1addr[flags]

Copy the specified lines after the specified destination line; line zero specifies that the lines shall be placedat 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-modebuffer.

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

Current line: Set to the line following the deleted lines, or to the last line in the edit buffer if thatline 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 completewrite, it shall be an error.

Iffile is specified, replace the current contents of the edit buffer with the current contents offile, and set the current pathname tofile. Iffile is not specified, replace the current contents of the editbuffer with the current contents of the file named by the current pathname. If for any reason the current contents of the filecannot 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 beinterpreted as anex command immediately after the contents of the edit buffer have been replaced and the current line andcolumn have been set.

If the edit buffer is empty:

Current line: Set to 0.

Current column: Set to 1.

Otherwise, if executed while inex 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, iffile 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, iffile is the same as the last file edited, the line and column shall be set as follows; if thefile 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 linein 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 thelast 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 tonon-<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 afile argument is specified, the alternate pathname shall be set to the current pathname, and thecurrent pathname shall be set tofile.

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 numberand the number of lines in the edit buffer shall be included in this message; otherwise, the message shall indicate that the editbuffer is empty. If the edit buffer has been modified since the last complete write, this fact shall be included in this message.If thereadonly edit option is set, this fact shall be included in this message. The message may contain other unspecifiedinformation.

Current line: Unchanged.

Current column: Unchanged.

Global
Synopsis:

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

The optional'!' character after theglobal command shall be the same as executing thevcommand.

Ifpattern is empty (for example,"//") or not specified, the last regular expression used in theeditor command shall be used as thepattern. Thepattern can be delimited by <slash> characters (shown in theSynopsis), as well as any non-alphanumeric or non-<blank> other than <backslash>, <vertical-line>,<newline>, or double-quote. Within the pattern, in certain circumstances the delimiter can be used as a literal character;seeRegular Expressions in ex.

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

Theglobal andv commands are logically two-pass operations. First, mark the lines within thespecified lines for which the line excluding the terminating <newline> matches (global) or does not match (v orglobal!) the specified pattern. Second, execute theex commands given bycommands, 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 theex:edit command) an error message shall be written and no more commands resulting from theexecution of this command shall be processed.

Multipleex 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 inex command mode, it shall be as if theprint command were specified.
  2. Otherwise, no command shall be executed.

For theappend,change, andinsert commands, the input text shall be included as part of thecommand, and the terminating <period> can be omitted if the command ends the list of commands. Theopen andvisual commands can be specified as one of the commands, in which case each marked line shall cause the editor to enter openor visual mode. If open or visual mode is exited using theviQ command, thecurrent line shall be set to the next marked line, and open or visual mode reentered, until the list of marked lines isexhausted.

Theglobal,v, andundo commands cannot be used incommands. Marked lines may bedeleted by commands executed for lines occurring earlier in the file than the marked lines. In this case, no commands shall beexecuted for the deleted lines.

If the remembered search direction is not set, theglobal andv commands shall set it to forward.

Theautoprint andautoindent edit options shall be inhibited for the duration of theg orv command.

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

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

Insert
Synopsis:

[1addr]i[nsert][!]

Enterex text input mode; the input text shall be placed before the specified line. If the line is zero or1, the text shall be placed at the beginning of the edit buffer.

This command shall be affected by thenumber andautoindent edit options; following the command namewith'!' shall cause theautoindent 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 isempty.

Current column: Set to non-<blank>.

Join
Synopsis:

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

Ifcount is specified:

If no address was specified, thejoin command shall behave as if2addr were the current line and thecurrent line pluscount (.,. +count).

If one address was specified, thejoin command shall behave as if2addr were the specified addressand the specified address pluscount (addr,addr +count).

If two addresses were specified, thejoin command shall behave as if an additional address, equal to thelast address pluscount -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 beequal to the last line of the edit buffer.

If nocount is specified:

If no address was specified, thejoin command shall behave as if2addr were the current line and the nextline (.,. +1).

If one address was specified, thejoin command shall behave as if2addr were the specified addressand 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, thejoin shall be without modification of anyline, independent of the current locale.

Otherwise, in the POSIX locale, set the current line to the first of the specified lines, and then, for eachsubsequent 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> charactersbetween 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 theex command:

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

SeePrint.

Map
Synopsis:

map[!][lhs rhs]

Iflhs andrhs 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 inlhs orrhs, except that printablecharacters and <blank> characters shall not be restricted. Additional restrictions shall be implementation-defined. In bothlhs andrhs, any character can be escaped with a <control>-V, in which case the character shall not be used todelimitlhs fromrhs, and the escaping <control>-V shall be discarded.

If the character'!' is appended to themap command name, the mapping shall be effective duringopen or visual text input mode rather thanopen orvisual command mode. This allowslhs to have two differentmap definitions at the same time: one for command mode and one for text input mode.

For command mode mappings:

When thelhs is entered as any part of avi command in open or visualmode (but not as part of the arguments to the command), the action shall be as if the correspondingrhs had been entered.

If any character in the command, other than the first, is escaped using a <control>-V character, thatcharacter shall not be part of a match to anlhs.

It is unspecified whether implementations shall supportmap commands where thelhs is more than asingle character in length, where the first character of thelhs is printable.

Iflhs contains more than one character and the first character is'#', followed by a sequence ofdigits corresponding to a numbered function key, then when this function key is typed it shall be mapped torhs. Charactersother than digits following a'#' character also represent the function key named by the characters in thelhsfollowing the'#' and may be mapped torhs. It is unspecified how function keys are named or what function keys aresupported.

For text input mode mappings:

When thelhs is entered as any part of text entered in open or visual text input modes, the action shall be asif the correspondingrhs had been entered.

If any character in the input text is escaped using a <control>-V character, that character shall not be partof a match to anlhs.

It is unspecified whether thelhs text entered for subsequentmap orunmap commands isreplaced with therhs text for the purposes of the screen display; regardless of whether or not the display appears as ifthe correspondingrhs text was entered, the effect of the command shall be as if thelhs text was entered.

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

Therhs characters shall themselves be subject to remapping, unless otherwise specified by theremapedit option, except that if the characters inlhs occur as prefix characters inrhs, those characters shall not beremapped.

On block-mode terminals, the mapping need not occur immediately (for example, it may occur after the terminaltransmits 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]kcharacter

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

If executing thevim command, set the specified mark to thecurrent 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 position1.

The mark shall remain associated with the line until the mark is reset or the line is deleted. If a deleted line isrestored by a subsequentundo command, any marks previously associated with the line, which have not been reset, shall berestored 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 occurin the editor:

  1. The use of'$' as anex address
  2. The use of a positive decimal number as anex address
  3. The use of a search command as anex address
  4. The use of a mark reference as anex 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,zif 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 lineor column will change as a result of the command
  8. The use of theex mode commands:z,undo,global,v

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

For rules 5., 6., and 7., the` and' marks shall not be set if the commands are used as motioncommands 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 commandfails.

The` and' marks shall be set as described previously, each time the contents of the edit buffer arereplaced (including the editing of the initial buffer), if in open or visual mode, or if inex mode and the edit buffer isnot 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 executingthevim command; otherwise, as if executing theexmarkcommand.

When changing fromex 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 linesshall be placed at the beginning of the edit buffer. It shall be an error if the destination line is within the range of lines tobe 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 completewrite, it shall be an error, unless the file is successfully written as specified by theautowrite 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 currentlyreferenced.
  2. Set the current pathname and the current argument list reference to the filename after the filename currentlyreferenced in the argument list.

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

This command shall be affected by theautowrite andwriteany edit options.

The+command option shall be <blank>-delimited; <blank> characters can be escaped bypreceding them with a <backslash> character. The+command shall be interpreted as anex commandimmediately 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 theedit command.

Current column: Set as described for theedit command.

Number
Synopsis:

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

These commands shall be equivalent to theex command:

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

SeePrint.

Open
Synopsis:

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

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

Enter open mode.

The trailing delimiter can be omitted frompattern at the end of the command line. Ifpattern isempty (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 theexrecover command. After the file has been preserved, a mail message shall be sent to the user. This message shall be readableby invoking themailx utility. The message shall contain the name of the file, thetime of preservation, and anex command that could be used to recover the file. Additional information may be included inthe 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 thenumber 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-charactersequences.

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

"%6dΔΔ", <line number>

If thel flag is specified or thelist edit option is set:

  1. The characters listed in XBDEscape Sequences and AssociatedActions shall be written as the corresponding escape sequence.
  2. Non-printable characters not in XBDEscape Sequences andAssociated Actions shall be written as one three-digit octal number (with a preceding <backslash>) for each byte inthe character (most significant byte first).
  3. The end of each line shall be marked with a'$', and literal'$' characters within the lineshall be written with a preceding <backslash>.

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

If a line is folded, and thel flag is not specified and thelist edit option is not set, it isunspecified 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 specifiesthat 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 inthe 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 notaquit,wq,xit, orZZ (seeExit) 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 shallbe appended into the edit buffer after the specified line; line zero specifies that the copy shall be placed at the beginning ofthe edit buffer. The number of lines and bytes read shall be written. If nofile is named, the current pathname shall be thedefault. If there is no current pathname, thenfile shall become the current pathname. If there is no current pathname orfile operand, it shall be an error. Specifying afile that is not of type regular shall have unspecified results.

Otherwise, iffile is preceded by'!', the rest of the line after the'!' shall have'%','#', and'!' characters expanded as described inCommand Line Parsing inex.

Theex utility shall then pass two arguments to the program named by the shell edit option; the first shallbe-c and the second shall be the expanded arguments to theread command as a single argument. The standard input ofthe program shall be set to the standard input of theex program when it was invoked. The standard error and standard outputof 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 fileor 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 theread 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, setto 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 completewrite, it shall be an error.

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

If no recovery information has previously been saved aboutfile, therecover command shall behaveidentically to theedit command, and an informational message to this effect shall be written.

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

Current file: Set as described for theedit command.

Current column: Set as described for theedit command.

Rewind
Synopsis:

rew[ind][!]

If no'!' is appended to the command name, and the edit buffer has been modified since the last completewrite, it shall be an error, unless the file is successfully written as specified by theautowrite 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 argumentlist.

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

This command shall be affected by theautowrite andwriteany edit options.

Current line: Set as described for theedit command.

Current column: Set as described for theedit command.

Set
Synopsis:

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

When no arguments are specified, write the value of theterm edit option and those options whose values havebeen changed from the default settings; when the argumentall 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 bewritten. The'?' can be separated from the option name by zero or more <blank> characters. The'?' shall benecessary only for Boolean valued options. Boolean options can be given values by the formsetoption to turn them onorsetnooption to turn them off; string and numeric options can be assigned by the formsetoption=value. Any <blank> characters in strings can be included as is by preceding each <blank> with anescaping <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. Arguments can appear in any order and shall be processed inthe specified order.

SeeEdit Options in ex for details about specific options.

Current line: Unchanged.

Current column: Unchanged.

Shell
Synopsis:

sh[ell]

Invoke the program named in theshell 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 executeex commands fromfile. Lines in the file that are blank lines shall be ignored.

Current line: As specified for the individualex commands.

Current column: As specified for the individualex 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 patternpattern by the stringrepl on each specified line. (SeeRegular Expressions in ex andReplacement Strings in ex.) Anynon-alphabetic, non-<blank> delimiter other than <backslash>,'|', <newline>, or double-quote can beused instead of'/'. Within the pattern, in certain circumstances the delimiter can be used as a literal character; seeRegular Expressions in ex. Within the replacement, the delimiter shall not terminate thereplacement if it is the second character of an escape sequence (see XBD9.1Regular Expression Definitions) and the escaped delimiter shall be treated as that literal character in the replacement(losing any special meaning it would have had if it was not used as the delimiter and was not escaped). It shall be an error if thesubstitution fails on every addressed line.

The trailing delimiter can be omitted frompattern or fromrepl at the end of the command line. Ifbothpattern andrepl are not specified or are empty (for example,"//"), the lasts command shall berepeated. If onlypattern is not specified or is empty, the last regular expression used in the editor shall be used as thepattern. If onlyrepl is not specified or is empty, the pattern shall be replaced by nothing. If the entire replacementpattern is'%', the last replacement pattern to ans command shall be used.

Entering a <carriage-return> inrepl (which requires an escaping <backslash> inex modeand an escaping <control>-V in open orvi mode) shall split the line at that point,creating a new line in the edit buffer. The <carriage-return> shall be discarded.

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

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

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

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

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

s/pattern/repl/

wherepattern andrepl are as specified in the previouss,&, or~ command.

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

s/pattern/repl/

wherepattern shall be the last regular expression specified to the editor, andrepl shall be fromthe previous substitution (including& and~) command.

These commands shall be affected by theLC_MESSAGES environment variable.

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

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 SIGTSTPsignal. The suspension shall occur only if job control is enabled in the invoking shell (see the description ofset-m).

These commands shall be affected by theautowrite andwriteany edit options.

The currentsusp character (seestty) shall be equivalent tothesuspend command.

Tag
Synopsis:

ta[g][!]tagstring

The results are unspecified if the format of a tags file is not as specified by thectags utility (seectags) description.

Thetag command shall search fortagstring in the tag files referred to by thetag editoption, in the order they are specified, until a reference totagstring is found. Files shall be searched from beginning toend. If no reference is found, it shall be an error and an error message to this effect shall be written. If the reference is notfound, or if an error occurs while processing a file referred to in thetag edit option, it shall be an error, and an errormessage 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 theeditor; for example, for the purposes of thes command.

If thetagstring is in a file with a different name than the current pathname, set the current pathname tothe 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, unlessthe file is successfully written as specified by theautowrite option.

This command shall be affected by theautowrite,tag,taglength, andwriteany editoptions.

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

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

Current column: If the tags file contained a line-number reference and that line-number was not larger thanthe 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 theedit command.

Unabbreviate
Synopsis:

una[bbrev]lhs

Iflhs is not an entry in the current list of abbreviations (seeAbbreviate), it shall be an error. Otherwise, deletelhs 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, includingundo.For this purpose, theglobal,v,open, andvisual commands, and commands resulting from bufferexecutions and mapped character expansions, are considered single commands.

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

If theundo command restores lines that were marked, the mark shall also be restored unless it was resetsubsequent 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 iflhs is not an entry in the list of text input modemap definitions, it shall be an error. Otherwise, deletelhs from the list of text input mode map definitions.

If no'!' is appended to the command name, and iflhs is not an entry in the list of command modemap definitions, it shall be an error. Otherwise, deletelhs 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]

Ifex is currently in open or visual mode, the Synopsis and behavior of the visual command shall be the sameas theedit command, as specified byEdit.

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.

Ifcount is specified, the value of thewindow edit option shall be set tocount (as describedinwindow). If the'^' type character was also specified, thewindow edit optionshall be set before being used by the type character.

Enter visual mode. Iftype is not specified, it shall be as if atype of'+' was specified.Thetype 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 thewindow edit option, set the line to 1; otherwise,decrement the line by the value of thewindow edit option minus 1. Place the beginning of this line as close to the bottomof the displayed lines as possible, while still displaying the value of thewindow 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 commandwq shall be equivalent to awrite command followed by aquit command;wq!shall be equivalent towrite! followed byquit. In both cases, if thewrite command fails, thequitshall not be attempted.

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

  1. If the>> argument is specified, and the file already exists, the lines shall be appended to the fileinstead of replacing its contents. If the>> argument is specified, and the file does not already exist, it isunspecified whether the write shall proceed as if the>> argument had not been specified or if the write shallfail.
  2. If thereadonly edit option is set (seereadonly), thewrite shallfail.
  3. Iffile is specified, and is not the current pathname, and the file exists, thewrite shallfail.
  4. Iffile is not specified, the current pathname shall be used. If there is no current pathname, thewrite command shall fail.
  5. If the current pathname is used, and the current pathname has been changed by thefile orreadcommands, and the file exists, thewrite shall fail. If thewrite is successful, subsequentwrites shall notfail 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, thewrite shallfail.

For rules 1., 2., 3., and 5., thewrite can be forced by appending the character'!' to the commandname.

For rules 2., 3., and 5., thewrite can be forced by setting thewriteany edit option.

Additional, implementation-defined tests may cause thewrite 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'!' charactersexpanded as described inCommand Line Parsing in ex.

Theex utility shall then pass two arguments to the program named by theshell edit option; the firstshall be-c and the second shall be the expanded arguments to thewrite command as a single argument. The specifiedlines shall be written to the standard input of the command. The standard error and standard output of the program, if any, shallbe written as described for theprint 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 thewrite 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 completewrite,xit shall be equivalent tothequit command, or if a'!' is appended to the command name, toquit!.

Otherwise,xit shall be equivalent to thewq command, or if a'!' is appended to the commandname, towq!.

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-modebuffer.

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; iftype is omitted as well, the current linevalue shall first be incremented by 1. If incrementing the current line would cause it to be greater than the last line in the editbuffer, it shall be an error.

If there are <blank> characters between thetype argument and the precedingz command name oroptional'!' character, it shall be an error.

Ifcount is specified, the value of thewindow edit option shall be set tocount (as describedinwindow). Ifcount is omitted, it shall default to 2 times the value of thescrolledit option, or if! was specified, the number of lines in the display minus 1.

Iftype is omitted, thencount lines starting with the specified line shall be written. Otherwise,count lines starting with the line specified by thetype argument shall be written.

Thetype argument shall change the lines to be written. The possible values oftype are asfollows:

-
The specified line shall be decremented by the following value:
(((number of '-' characters) xcount) -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, untilcount 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) xcount) +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, untilcount lines or the last line in the edit bufferhas been written.

=,.
If more than a single'.' or'=' is specified, it shall be an error. The following steps shall be taken:
  1. Ifcount is zero, nothing shall be written.
  2. Write as many of theN lines before the current line in the edit buffer as exist. Ifcount or'!' was specified,N shall be:
    (count -1) /2

    Otherwise,N shall be:

    (count -3) /2

    IfN 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 ofcolumns in the display divided by two, or 40'-' characters.
  4. Write the current line.
  5. Repeat step 3.
  6. Write as many of theN lines after the current line in the edit buffer as exist.N shall be definedas in step 2. IfN is a number less than 3, no lines shall be written. Ifcount is less than 3, no lines shall bewritten.
^
The specified line shall be decremented by the following value:
(((number of '^' characters) +1) xcount) -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, untilcount 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 specifiedline.

Current column: Set to non-<blank>.

Escape
Synopsis:

!command[2addr] !command

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

Theex utility shall execute the program named by theshell edit option. It shall pass two argumentsto the program; the first shall be-c, and the second shall be the expanded arguments to the! command as a singleargument.

If no lines are specified, the standard input, standard output, and standard error of the program shall be set tothe standard input, standard output, and standard error of theex program when it was invoked. In addition, a warningmessage shall be written if the edit buffer has been modified since the last complete write, and thewarn edit option isset.

If lines are specified, they shall be passed to the program as standard input, and the standard output and standarderror 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 editbuffer. 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 unnamedbuffer shall become a line-mode buffer.

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

This command shall be affected by theshell andwarn edit options. If no lines are specified, thiscommand shall be affected by theautowrite andwriteany edit options. If lines are specified, this command shall beaffected by theautoprint 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 thenumber of command characters times the value of theshiftwidth edit option. Only leading <blank> characters shall bedeleted 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 theautoprint 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 bethe number of command characters times the value of theshiftwidth 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 theautoprint 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 nextn lines, wheren is the minimum of the values of thescroll edit option and thenumber 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 anerror.

Current line: Set to the last line written.

Current column: Set to non-<blank>.

Write Line Number
Synopsis:

[1addr]=[flags]

Ifline is not specified, it shall default to the last line in the edit buffer. Write the line number of thespecified 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 executethe contents of the namedbuffer (as they were at the time the@ command was executed) asex commands. Foreach line of a line-mode buffer, and all but the last line of a character-mode buffer, theex command parser shall behave asif 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 linewould 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 theex:edit command) an error message shall be written, and no more commands resulting from theexecution of this command shall be processed.

Current line: As specified for the individualex commands.

Current column: As specified for the individualex commands.

Regular Expressions in ex

Theex utility shall support regular expressions that are a superset of the basic regular expressionsdescribed in XBD9.3 Basic Regular Expressions. A null regularexpression ("//") 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, thesubstitute command), to specify portions of a line to be substituted.

The start and end of a regular expression (RE) are marked by a delimiter character (although in some circumstancesthe end delimiter can be omitted). In addresses, the delimiter is either <slash> or <question-mark>. In commands, othercharacters can be used as the delimiter, as specified in the description of the command. Within the RE (as anex extensionto the BRE syntax), the delimiter shall not terminate the RE if it is the second character of an escape sequence (see XBD9.1 Regular Expression Definitions) and the escaped delimiter shall be treatedas that literal character in the RE (losing any special meaning it would have had if it was not used as the delimiter and was notescaped). In addition, the delimiter character shall not terminate the RE when it appears within a bracket expression, and shallhave its normal meaning in the bracket expression. For example, the command"g%[%]%p" is equivalent to"g/[%]/p",and the command"s-[0-9]--g" is equivalent to"s/[0-9]//g".

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

\<
Match the beginning of aword. (See the definition ofword at the beginning ofCommandDescriptions in ex.)
\>
Match the end of aword.
~
Match the replacement part of the lastsubstitute command. The <tilde> ('~') character can be escaped ina regular expression to become a normal character with no special meaning. The <backslash> shall be discarded.

When the editor optionmagic is not set, the only characters with special meanings shall be'^' atthe 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

Certain characters and strings have special meaning in replacement strings when the character, or the firstcharacter of the string, is unescaped.

The character'&' ('\&' if the editor optionmagic is not set) in the replacementstring shall stand for the text matched by the pattern to be replaced. The character'~' ('\~' ifmagic isnot set) shall be replaced by the replacement part of the previoussubstitute command. The sequence'\n', wheren is an integer, shall be replaced by the text matched by the corresponding back-reference expression. If the correspondingback-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 ofelements 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 thesubstitution until the string'\e' or'\E', or the end of the replacement string, is encountered.

Otherwise, any character following an unescaped <backslash> shall be treated as that literal character, andthe escaping <backslash> shall be discarded.

An example of case conversion with thes command is as follows:

:pThe cat sat on the mat.:s/\<.at\>/\u&/gpThe Cat Sat on the Mat.:s/S\(.*\)M/S\U\1\eM/pThe Cat SAT ON THE Mat.
Edit Options in ex

Theex utility has a number of options that modify its behavior. These options have default settings, whichcan be changed using theset command.

Options are Boolean unless otherwise specified.

autoindent, ai

[Defaultunset]

Ifautoindent is set, each line in input mode shall be indented (using first as many <tab> charactersas possible, as determined by the editor optiontabstop, and then using <space> characters) to align with anotherline, as follows:

  1. If in open or visual mode and the text input is part of a line-oriented command (see the EXTENDED DESCRIPTION invi), align to the first column.
  2. Otherwise, if in open or visual mode, indentation for each line shall be set as follows:
    1. If a line was previously inserted as part of this command, it shall be set to the indentation of the last insertedline by default, or as otherwise specified for the <control>-D character inInput Mode Commands in vi.
    2. Otherwise, it shall be set to the indentation of the previous current line, if any; otherwise, to the firstcolumn.
  3. For theexa,i, andc commands, indentation for each line shall be set as follows:
    1. If a line was previously inserted as part of this command, it shall be set to the indentation of the last insertedline by default, or as otherwise specified for theeof character inScroll.
    2. Otherwise, if the command is theexa command, it shall be set to the line appended after, if any;otherwise to the first column.
    3. Otherwise, if the command is theexi command, it shall be set to the line inserted before, if any;otherwise to the first column.
    4. Otherwise, if the command is theexc command, it shall be set to the indentation of the linereplaced.
autoprint, ap

[Defaultset]

Ifautoprint is set, the current line shall be written after eachex command that modifies thecontents of the current edit buffer, and after eachtag command for which the tag search pattern was found or tag linenumber was valid, unless:

  1. The command was executed while in open or visual mode.
  2. The command was executed as part of aglobal orv command or@ buffer execution.
  3. The command was the form of theread command that reads a file into the edit buffer.
  4. The command was theappend,change, orinsert 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 thecurrent line as specified for the flag modifier to thedelete command, and not as specified by theautoprint editoption.
autowrite, aw

[Defaultunset]

Ifautowrite 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 theexwrite command had been specified without arguments,before each command affected by theautowrite edit option is executed. Appending the character'!' to the commandname of any of theex commands except'!' shall prevent the write. If the write fails, it shall be an error and thecommand shall not be executed.

beautify, bf

[XSI][Option Start] [Defaultunset]

Ifbeautify is set, all non-printable characters, other than <tab>, <newline>, and<form-feed> characters, shall be discarded from text read in from files.[Option End]

directory, dir

[Defaultimplementation-defined]

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

edcompatible, ed

[Defaultunset]

Causes the presence ofg andc suffixes on substitute commands to be remembered, and toggled byrepeating the suffixes.

errorbells, eb

[Defaultunset]

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

exrc

[Defaultunset]

Ifexrc is set,ex shall access any.exrc file in the current directory, as described inInitialization in ex and vi. Ifexrc is not set,ex shall ignore any.exrcfile in the current directory during initialization, unless the current directory is that named by theHOME environmentvariable.

ignorecase, ic

[Defaultunset]

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

Theignorecase edit option shall affect all remembered regular expressions; for example, unsetting theignorecase edit option shall cause a subsequentvin command to search forthe last basic regular expression in a case-sensitive fashion.

list

[Defaultunset]

Iflist is set, edit buffer lines written while inex command mode shall be written as specified fortheprint command with thel flag specified. In open or visual mode, each edit buffer line shall be displayed asspecified for theexprint command with thel flag specified. In open or visual text input mode, when thecursor does not rest on any character in the line, it shall rest on the'$' marking the end of the line.

magic

[Defaultset]

Ifmagic is set, modify the interpretation of characters in regular expressions and substitution replacementstrings (seeRegular Expressions in ex andReplacement Strings in ex).

mesg

[Defaultset]

Ifmesg is set, the permission for others to use thewrite ortalk commands to write to theterminal shall be turned on while in open or visual mode. The shell-level commandmesgn shall take precedence over any setting of theexmesg option; that is, ifmesg y was issued beforethe editor started (or in a shell escape), such as:

:!mesg y

themesg option inex shall suppress incoming messages, but themesg option shall not enableincoming messages ifmesg n was issued.

number, nu

[Defaultunset]

Ifnumber is set, edit buffer lines written while inex command mode shall be written with linenumbers, in the format specified by theprint command with the# flag specified. Inex text input mode, eachline 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 formatspecified by theexprint command with the# flag specified. This line number shall not be considered part ofthe line for the purposes of evaluating the current column; that is, column position 1 shall be the first column position after theformat specified by theprint command.

paragraphs, para

[Default in the POSIX localeIPLPPPQPP LIpplpipbp]

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

prompt

[Defaultset]

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

readonly

[Defaultsee text]

If thereadonly edit option is set, read-only mode shall be enabled (seeWrite). Thereadonly edit option shall be initialized to set if either of the following conditionsare true:

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

redraw

[Defaultunset]

Ifredraw is set and the terminal is a type incapable of supporting open or visual modes, the editor shallredraw the screen when necessary in order to update its contents. (Since this is likely to require a large amount of output to theterminal, it is useful only at high transmission speeds.)

remap

[Defaultset]

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

report

[Default 5]

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

scroll, scr

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

The value of thescroll edit option shall determine the number of lines scrolled by theex<control>-D andz commands. For thevi <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 localeNHSHH HUnhsh]

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

shell, sh

[Default from the environment variableSHELL ]

The value of this option shall be a string. The default shall be taken from theSHELL environment variable.If theSHELL environment variable is null or empty, thesh (seesh) 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 bythe shift commands (< and>).

showmatch, sm

[Defaultunset]

The functionality described for theshowmatch edit option need not be supported on block-mode terminals orterminals with insufficient capabilities.

Ifshowmatch 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 movingthe cursor to its location for an unspecified amount of time.

showmode

[Defaultunset]

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

slowopen

[Defaultunset]

Ifslowopen is set during open and visual text input modes, the editor shall not update portions of thedisplay other than those display line columns that display the characters entered by the user (seeInput 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 (seeautoprint, ap andInput 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 theuser-specified tag name and in the tag name from the tags file. If the value is zero, all characters in both tag names shall besignificant.

tags

[Defaultsee text]

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

term

[Default from the environment variableTERM ]

The value of this edit option shall be a string. The default shall be taken from theTERM variable in theenvironment. If theTERM environment variable is empty or null, the default is unspecified. The editor shall use the valueof 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

[Defaultunset]

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

warn

[Defaultset]

Ifwarn is set, and the contents of the edit buffer have been modified since they were last completelywritten, the editor shall write a warning message before certain! commands (seeEscape).

window

[Defaultsee 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 theLINES environment variable. If theLINES environment variable is empty or null, the default shall be the number oflines in the display minus 1.

Setting thewindow 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 theLINES environment variable) shall cause thewindow editoption 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 acolumn that is less thanwrapmargin columns from the ending margin of the display line, the editor shall behave asfollows:

  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 editorshall 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 lastgroup 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 theautoindent 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 forCOLUMNS inthe ENVIRONMENT VARIABLES section and XBD8. Environment Variables.

wrapscan, ws

[Defaultset]

Ifwrapscan is set, searches (theex/ or? addresses, or open and visual mode/,?,N, andn 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

[Defaultunset]

Ifwriteany is set, some of the checks performed when executing theexwrite commands shall beinhibited, as described in editor optionautowrite.

EXIT STATUS

The following exit values shall be returned:

 0
Successful completion.
>0
An error occurred.

CONSEQUENCES OF ERRORS

When any error is encountered and the standard input is not a terminal device file, in addition to the default requirementsdescribed in1.4 Utility Description Defaults,ex shall neitherwrite the file (if one has been opened) nor return to command or text input mode.

Otherwise, when an unrecoverable error is encountered, it shall be equivalent to a SIGHUP asynchronous event.

Otherwise, when an error is encountered, the editor shall behave as specified inCommandLine Parsing in ex.


The following sections are informative.

APPLICATION USAGE

If a SIGSEGV signal is received whileex is saving a file, the file might not be successfully saved.

Thenext command can accept more than one file, so usage such as:

next `ls [abc]*`

is valid; it would not be valid for theedit orread commands, for example, because they expect onlyone file and unspecified results occur.

Unlike thesystem() function,ex does not pass"--"between the"-c" argument and the command string, so that programs for which-c takes an option-argument can beused in theshell edit option. Users who want to use anescape command to execute a utility whose name starts with'-' or'+' need to provide a pathname for that utility that does not start with either of those characters, orprecede the utility name with a <blank> character.

EXAMPLES

None.

RATIONALE

Theex/vi specification is based on the historical practice found in the 4 BSDand System V implementations ofex andvi.

Arestricted editor (both the historicalred utility and modifications toex) were consideredand rejected for inclusion. Neither option provided the level of security that users might expect.

It is recognized thatex visual mode and related features would be difficult, if not impossible, toimplement satisfactorily on a block-mode terminal, or a terminal without any form of cursor addressing; thus, it is not a mandatoryrequirement that such features should work on all terminals. It is the intention, however, that anex implementation shouldprovide the full set of capabilities on all terminals capable of supporting them.

Options

The-c replacement for+command was inspired by the-e option ofsed. Historically, all such commands (seeedit andnext as well) were executedfrom the last line of the edit buffer. This meant, for example, that"+/pattern" would fail unless thewrapscanoption was set. POSIX.1-2024 requires conformance to historical practice. The+command option is no longer specifiedby POSIX.1-2024 but may be present in some implementations. Historically, some implementations restricted theex commandsthat could be listed as part of the command line arguments. For consistency, POSIX.1-2024 does not permit these restrictions.

In historical implementations of the editor, the-R option (and thereadonly edit option) onlyprevented overwriting of files; appending to files was still permitted, mapping loosely into thecshnoclobbervariable. Some implementations, however, have not followed this semantic, andreadonly does not permit appending either.POSIX.1-2024 follows the latter practice, believing that it is a more obvious and intuitive meaning ofreadonly.

The-s option suppresses all interactive user feedback and is useful for editing scripts in batch jobs. Thelist of specific effects is historical practice. The terminal type "incapable of supporting open and visual modes" hashistorically been named "dumb".

The-t option was required because thectags utility appears inPOSIX.1-2024 and the option is available in all historical implementations ofex.

Historically, theex andvi utilities accepted a-x option,which did encryption based on the algorithm found in the historicalcrypt utility. The-x option for encryption, andthe associatedcrypt utility, were omitted because the algorithm used was not specifiable and the export control laws ofsome nations make it difficult to export cryptographic technology. In addition, it did not historically provide the level ofsecurity that users might expect.

Standard Input

An end-of-file condition is not equivalent to an end-of-file character. A common end-of-file character,<control>-D, is historically anex command.

There was no maximum line length in historical implementations ofex. Specifically, as it was parsed inchunks, the addresses had a different maximum length than the filenames. Further, the maximum line buffer size was declared asBUFSIZ, which was different lengths on different systems. This version selected the value of {LINE_MAX} to impose a reasonablerestriction on portable usage ofex and to aid test suite writers in their development of realistic tests that exercise thislimit.

Input Files

It was an explicit decision by the standard developers that a <newline> be added to any file lacking one. Itwas believed that this feature ofex andvi was relied on by users in order tomake text files lacking a trailing <newline> more portable. It is recognized that this will require a user-specified optionor extension for implementations that permitex andvi to edit files of type otherthan text if such files are not otherwise identified by the system. It was agreed that the ability to edit files of arbitrary typecan be useful, but it was not considered necessary to mandate that anex orviimplementation be required to handle files other than text files.

The paragraph in the INPUT FILES section, "By default, ...", is intended to close a long-standing securityproblem inex andvi; that of the "modeline" or "modelines" edit option. Thisfeature allows any line in the first or last five lines of the file containing the strings"ex:" or"vi:" (and,apparently,"ei:" or"vx:") to be a line containing editor commands, andex interprets all the text up tothe next':' or <newline> as a command. Consider the consequences, for example, of an unsuspecting user usingex orvi as the editor when replying to a mail message in which a line suchas:

ex:! rm -rf :

appeared in the signature lines. The standard developers believed strongly that an editor should not by defaultinterpret any lines of a file. Vendors are strongly urged to delete this feature from their implementations ofex andvi.

Asynchronous Events

The intention of the phrase "complete write" is that the entire edit buffer be written to stable storage. Thenote regarding temporary files is intended for implementations that use temporary files to back edit buffers unnamed by theuser.

Historically, SIGQUIT was ignored byex, but was the equivalent of theQ command in visual mode; thatis, it exited visual mode and enteredex mode. POSIX.1-2024 permits, but does not require, this behavior. Historically,SIGINT was often used byvi users to terminate text input mode (<control>-C isoften easier to enter than <ESC>). Some implementations ofvi alerted the terminalon this event, and some did not. POSIX.1-2024 requires that SIGINT behave identically to <ESC>, and that the terminal not bealerted.

Historically, suspending theex editor during text input mode was similar to SIGINT, as completed lines wereretained, but any partial line discarded, and the editor returned to command mode. POSIX.1-2024 is silent on this issue;implementations are encouraged to follow historical practice, where possible.

Historically, thevi editor did not treat SIGTSTP as an asynchronousevent, and it was therefore impossible to suspend the editor in visual text input mode. There are two major reasons for this. Thefirst is that SIGTSTP is a broadcast signal on UNIX systems, and the chain of events where the shellexecs an application that thenexecsvi usually caused confusion for theterminal state if SIGTSTP was delivered to the process group in the default manner. The second was that most implementations of theUNIXcurses package did not handle SIGTSTP safely, and the receipt of SIGTSTP at the wrong time would cause them to crash.POSIX.1-2024 is silent on this issue; implementations are encouraged to treat suspension as an asynchronous event if possible.

Historically, modifications to the edit buffer made before SIGINT interrupted an operation were retained; that is,anywhere from zero to all of the lines to be modified might have been modified by the time the SIGINT arrived. These changes werenot discarded by the arrival of SIGINT. POSIX.1-2024 permits this behavior, noting that theundo command is required to beable to undo these partially completed commands.

The action taken for signals other than SIGINT, SIGCONT, SIGHUP, and SIGTERM is unspecified because someimplementations attempt to save the edit buffer in a useful state when other signals are received.

Standard Error

Forex/vi, diagnostic messages are those messages reported as aresult of a failed attempt to invokeex orvi, such as invalid options orinsufficient resources, or an abnormal termination condition. Diagnostic messages should not be confused with the error messagesgenerated by inappropriate or illegal user commands.

Initialization in ex and vi

If anex command (other thancd,chdir, orsource) has a filename argument, one or bothof the alternate and current pathnames will be set. Informally, they are set as follows:

  1. If theex command is one that replaces the contents of the edit buffer, and it succeeds, the currentpathname will be set to the filename argument (the first filename argument in the case of thenext command) and thealternate pathname will be set to the previous current pathname, if there was one.
  2. In the case of the file read/write forms of theread andwrite commands, if there is no currentpathname, the current pathname will be set to the filename argument.
  3. Otherwise, the alternate pathname will be set to the filename argument.

For example,:edit foo and:recover foo, when successful, set the current pathname, and, if there wasa previous current pathname, the alternate pathname. The commands:write,!command, and:edit set neither thecurrent or alternate pathnames. If the:edit foo command were to fail for some reason, the alternate pathname would be set.Theread andwrite commands set the alternate pathname to theirfile argument, unless the current pathname isnot set, in which case they set the current pathname to theirfile arguments. The alternate pathname was not historicallyset by the:source command. POSIX.1-2024 requires conformance to historical practice. Implementations adding commands thattake filenames as arguments are encouraged to set the alternate pathname as described here.

Historically,ex andvi read the.exrc file in the$HOME directory twice, if the editor was executed in the$HOME directory. POSIX.1-2024 prohibits this behavior.

Historically, the 4 BSDex andvi read the$HOME and local.exrc files if they were owned by the real ID of the user, or thesourceany option was set, regardless of otherconsiderations. This was a security problem because it is possible to put normal UNIX system commands inside a.exrc file.POSIX.1-2024 does not specify thesourceany option, and historical implementations are encouraged to delete it.

The.exrc files must be owned by the real ID of the user, and not writable by anyone other than the owner.The appropriate privileges exception is intended to permit users to acquire special privileges, but continue to use the.exrc files in their home directories.

System V Release 3.2 and latervi implementations added the option[no]exrc. The behavior is that local.exrc files are read-only if theexrc option is set. The default for theexrc option was off, so by default, local.exrc files were not read. The problem this was intended to solve was thatSystem V permitted users to give away files, so there is no possible ownership or writeability test to ensure that the file issafe. This is still a security problem on systems where users can give away files, but there is nothing additional thatPOSIX.1-2024 can do. The implementation-defined exception is intended to permit groups to have local.exrc files that areshared by users, by creating pseudo-users to own the shared files.

POSIX.1-2024 does not mention system-wideex andvi start-upfiles. While they exist in several implementations ofex andvi, they are notpresent in any implementations considered historical practice by POSIX.1-2024. Implementations that have such files should use themonly if they are owned by the real user ID or an appropriate user (for example, root on UNIX systems) and if they are not writableby any user other than their owner. System-wide start-up files should be read before theEXINIT variable,$HOME/.exrc, or local.exrc files are evaluated.

Historically, anyex command could be entered in theEXINIT variable or the.exrc file,although ones requiring that the edit buffer already contain lines of text generally caused historical implementations of theeditor to dropcore. POSIX.1-2024 requires that anyex command be permitted in theEXINIT variable and.exrc files, for simplicity of specification and consistency, although many of them will obviously fail under manycircumstances.

The initialization of the contents of the edit buffer uses the phrase "the effect shall be" with regard tovariousex commands. The intent of this phrase is that edit buffer contents loaded during the initialization phase not belost; that is, loading the edit buffer should fail if the.exrc file read in the contents of a file and did not subsequentlywrite the edit buffer. An additional intent of this phrase is to specify that the initial current line and column is set asspecified for the individualex commands.

Historically, the-t option behaved as if the tag search were a+command; that is, it wasexecuted from the last line of the file specified by the tag. This resulted in the search failing if the pattern was a forwardsearch pattern and thewrapscan edit option was not set. POSIX.1-2024 does not permit this behavior, requiring that thesearch for the tag pattern be performed on the entire file, and, if not found, that the current line be set to a more reasonablelocation in the file.

Historically, the empty edit buffer presented for editing when a file was not specified by the user was unnamed.This is permitted by POSIX.1-2024; however, implementations are encouraged to provide users a temporary filename for this bufferbecause it permits them the use ofex commands that use the current pathname during temporary edit sessions.

Historically, the file specified using the-t option was not part of the current argument list. Thispractice is permitted by POSIX.1-2024; however, implementations are encouraged to include its name in the current argument list forconsistency.

Historically, the-c command was generally not executed until a file that already exists was edited.POSIX.1-2024 requires conformance to this historical practice. Commands that could cause the-c command to be executedinclude theex commandsedit,next,recover,rewind, andtag, and thevi commands <control>-^ and <control>-]. Historically, reading a file into an editbuffer did not cause the-c command to be executed (even though it might set the current pathname) with the exception thatit did cause the-c command to be executed if: the editor was inex mode, the edit buffer had no current pathname,the edit buffer was empty, and no read commands had yet been attempted. For consistency and simplicity of specification,POSIX.1-2024 does not permit this behavior.

Historically, the-r option was the same as a normal edit session if there was no recovery informationavailable for the file. This allowed users to enter:

vi -r *.c

and recover whatever files were recoverable. In some implementations, recovery was attempted only on the first filenamed, and the file was not entered into the argument list; in others, recovery was attempted for each file named. In addition,some historical implementations ignored-r if-t was specified or did not support command linefile argumentswith the-t option. For consistency and simplicity of specification, POSIX.1-2024 disallows these special cases, andrequires that recovery be attempted the first time each file is edited.

Historically,vi initialized the` and' marks, butex did not. This meant that if the first command inex mode wasvisual or if anex command was executedfirst (for example,vi +10file),vi wasentered without the marks being initialized. Because the standard developers believed the marks to be generally useful, and forconsistency and simplicity of specification, POSIX.1-2024 requires that they always be initialized if in open or visual mode, or ifinex mode and the edit buffer is not empty. Not initializing it inex mode if the edit buffer is empty is historicalpractice; however, it has always been possible to set (and use) marks in empty edit buffers in open and visual mode editsessions.

Addressing

Historically,ex andvi accepted the additional addressing forms'\/' and'\?'. They were equivalent to"//" and"??", respectively. They are not required byPOSIX.1-2024, mostly because nobody can remember whether they ever did anything different historically.

Historically,ex andvi permitted an address of zero for severalcommands, and permitted the% address in empty files for others. For consistency, POSIX.1-2024 requires support for theformer in the few commands where it makes sense, and disallows it otherwise. In addition, because POSIX.1-2024 requires that% be logically equivalent to"1,$", it is also supported where it makes sense and disallowed otherwise.

Historically, the% address could not be followed by further addresses. For consistency and simplicity ofspecification, POSIX.1-2024 requires that additional addresses be supported.

All of the following are validaddresses:

+++
Three lines after the current line.
/re/-
One line before the next occurrence ofre.
-2
Two lines before the current line.
3 ---- 2
Line one (note intermediate negative address).
1 2 3
Line six.

Any number of addresses can be provided to commands taking addresses; for example,"1,2,3,4,5p" printslines 4 and 5, because two is the greatest valid number of addresses accepted by theprint command. This, in combinationwith the <semicolon> delimiter, permits users to create commands based on ordered patterns in the file. For example, thecommand3;/foo/;+2print will display the first line after line 3 that contains the patternfoo, plus the next twolines. Note that the address3; must be evaluated before being discarded because the search origin for the/foo/command depends on this.

Historically, values could be added to addresses by including them after one or more <blank> characters; forexample,3 - 5p wrote the seventh line of the file, and/foo/ 5 was the same as/foo/+5.However, only absolute values could be added; for example,5 /foo/ was an error. POSIX.1-2024 requires conformance tohistorical practice. Address offsets are separately specified from addresses because they could historically be provided to visualmode search commands.

Historically, any missing addresses defaulted to the current line. This was true for leading and trailing<comma>-delimited addresses, and for trailing <semicolon>-delimited addresses. For consistency, POSIX.1-2024 requiresit for leading <semicolon> addresses as well.

Historically,ex andvi accepted the'^' character asboth an address and as a flag offset for commands. In both cases it was identical to the'-' character. POSIX.1-2024 doesnot require or prohibit this behavior.

Historically, the enhancements to basic regular expressions could be used in addressing; for example,'~','\<', and'\>'. POSIX.1-2024 requires conformance to historical practice; that is, that regular expressionusage be consistent, and that regular expression enhancements be supported wherever regular expressions are used.

Command Line Parsing in ex

Historicalex command parsing was even more complex than that described here. POSIX.1-2024 requires thesubset of the command parsing that the standard developers believed was documented and that users could reasonably be expected touse in a portable fashion, and that was historically consistent between implementations. (The discarded functionality is obscure,at best.) Historical implementations will require changes in order to comply with POSIX.1-2024; however, users are not expected tonotice any of these changes. Most of the complexity inex parsing is to handle three special termination cases:

  1. The!,global,v, and the filter versions of theread andwrite commands aredelimited by <newline> characters (they can contain <vertical-line> characters that are usually shell pipes).
  2. Theex,edit,next, andvisual in open and visual mode commands all takeexcommands, optionally containing <vertical-line> characters, as their first arguments.
  3. Thes command takes a regular expression as its first argument, and uses the delimiting characters todelimit the command.

Historically, <vertical-line> characters in the+command argument of theex,edit,next,vi, andvisual commands, and in thepattern andreplacement parts of thes command, did not delimit the command, and in the filter cases forread andwrite, and the!,global, andv commands, they did not delimit the command at all. For example, the following commands are allvalid:

:edit +25 | s/abc/ABC/ file.c:s/ | /PIPE/:read !spell % | columnate:global/pattern/p | l:s/a/b/ | s/c/d | set

Historically, empty or <blank> filled lines in.exrc files andsourced files (as well asEXINIT variables andex command scripts) were treated as default commands; that is,print commands.POSIX.1-2024 specifically requires that they be ignored when encountered in.exrc andsourced files to eliminate acommon source of new user error.

Historically,ex commands with multiple adjacent (or <blank>-separated) vertical lines were handledoddly when executed fromex mode. For example, the command||| <carriage-return>, when the cursor was on line1, displayed lines 2, 3, and 5 of the file. In addition, the command| would only display the line after the next line,instead of the next two lines. The former worked more logically when executed fromvimode, and displayed lines 2, 3, and 4. POSIX.1-2024 requires thevi behavior; that is, asingle default command and line number increment for each command separator, and trailing <newline> characters after<vertical-line> separators are discarded.

Historically,ex permitted a single extra <colon> as a leading command character; for example,:g/pattern/:p was a valid command. POSIX.1-2024 generalizes this to require that any number of leading <colon>characters be stripped.

Historically, any prefix of thedelete command could be followed without intervening <blank>characters by a flag character because in the commandd p,p is interpreted as the bufferp. POSIX.1-2024requires conformance to historical practice.

Historically, thek command could be followed by the mark name without intervening <blank> characters.POSIX.1-2024 requires conformance to historical practice.

Historically, thes command could be immediately followed by flag and option characters; for example,s/e/E/|s|sgc3p was a valid command. However, flag characters could not stand alone; for example, the commandssp ands l would fail, while the commandsgp ands gl would succeed. (Obviously, the'#' flagcharacter was used as a delimiter character if it followed the command.) Another issue was that option characters had to precedeflag characters even when the command was fully specified; for example, the commands/e/E/pg would fail, while the commands/e/E/gp would succeed. POSIX.1-2024 requires conformance to historical practice.

Historically, the first command name that had a prefix matching the input from the user was the executed command;for example,ve,ver, andvers all executed theversion command. Commands were in a specific order,however, so thata matchedappend, notabbreviate. POSIX.1-2024 requires conformance to historical practice.The restriction on command search order for implementations with extensions is to avoid the addition of commands such that thehistorical prefixes would fail to work portably.

Historical implementations ofex andvi did not correctly handlemultipleex commands, separated by <vertical-line> characters, that entered or exited visual mode or the editor.Because implementations ofvi exist that do not exhibit this failure mode, POSIX.1-2024does not permit it.

The requirement that alphabetic command names consist of all following alphabetic characters up to the nextnon-alphabetic character means that alphabetic command names must be separated from their arguments by one or more non-alphabeticcharacters, normally a <blank> or'!' character, except as specified for the exceptions, thedelete,k, ands commands.

Historically, the repeated execution of theex defaultprint commands (<control>-D,eof,<newline>, <carriage-return>) erased any prompting character and displayed the next lines without scrolling theterminal; that is, immediately below any previously displayed lines. This provided a cleaner presentation of the lines in the filefor the user. POSIX.1-2024 does not require this behavior because it may be impossible in some situations; however, implementationsare strongly encouraged to provide this semantic if possible.

Historically, it was possible to change files in the middle of a command, and have the rest of the command executedin the new file; for example:

:edit +25 file.c | s/abc/ABC/ | 1

was a valid command, and the substitution was attempted in the newly edited file. POSIX.1-2024 requires conformanceto historical practice. The following commands are examples that exercise theex parser:

echo 'foo | bar' > file1; echo 'foo/bar' > file2;vi:edit +1 | s/|/PIPE/ | w file1 | e file2 | 1 | s/\//SLASH/ | wq

Historically, there was no protection in editor implementations to avoidexglobal,v,@, or* commands changing edit buffers during execution of their associated commands. Because this would almostinvariably result in catastrophic failure of the editor, and implementations exist that do exhibit these problems, POSIX.1-2024requires that changing the edit buffer during aglobal orv command, or during a@ or* command forwhich there will be more than a single execution, be an error. Implementations supporting multiple edit buffers simultaneously arestrongly encouraged to apply the same semantics to switching between buffers as well.

Theex command quoting required by POSIX.1-2024 is a superset of the quoting in historical implementationsof the editor. For example, it was not historically possible to escape a <blank> in a filename; for example,:edit foo\\\ bar would report that too many filenames had been entered for the edit command, and there was nomethod of escaping a <blank> in the first argument of anedit,ex,next, orvisual command atall. POSIX.1-2024 extends historical practice, requiring that quoting behavior be made consistent across allex commands,except for themap,unmap,abbreviate, andunabbreviate commands, which historically used<control>-V instead of <backslash> characters for quoting. For those four commands, POSIX.1-2024 requires conformanceto historical practice.

Backslash quoting inex is non-intuitive. <backslash>-escapes are ignored unless they escape a specialcharacter; for example, when performingfile argument expansion, the string"\\%" is equivalent to'\%',not"\<current pathname>". This can be confusing for users because <backslash> is usuallyone of the characters that causes shell expansion to be performed, and therefore shell quoting rules must be taken intoconsideration. Generally, quoting characters are only considered if they escape a special character, and a quoting character mustbe provided for each layer of parsing for which the character is special. As another example, only a single <backslash> isnecessary for the'\l' sequence in substitute replacement patterns, because the character'l' is not special toany parsing layer above it.

<control>-V quoting inex is slightly different from backslash quoting. In the four commands where<control>-V quoting applies (abbreviate,unabbreviate,map, andunmap), any character may beescaped by a <control>-V whether it would have a special meaning or not. POSIX.1-2024 requires conformance to historicalpractice.

Historical implementations of the editor did not require delimiters within character classes to be escaped; forexample, the command:s/[/]// on the string"xxx/yyy" would delete the'/' from the string. POSIX.1-2024disallows this historical practice for consistency and because it places a large burden on implementations by requiring thatknowledge of regular expressions be built into the editor parser.

Historically, quoting <newline> characters inex commands was handled inconsistently. In most cases,the <newline> character always terminated the command, regardless of any preceding escape character, because<backslash> characters did not escape <newline> characters for mostex commands. However, someexcommands (for example,s,map, andabbreviation) permitted <newline> characters to be escaped (althoughin the case ofmap andabbreviation, <control>-V characters escaped them instead of <backslash>characters). This was true in not only the command line, but also.exrc andsourced files. For example, thecommand:

map = foo<control-V><newline>bar

would succeed, although it was sometimes difficult to get the <control>-V and the inserted <newline>passed to theex parser. For consistency and simplicity of specification, POSIX.1-2024 requires that it be possible toescape <newline> characters inex commands at all times, using <backslash> characters for mostexcommands, and using <control>-V characters for themap andabbreviation commands. For example, the commandprint<newline>list is required to be parsed as the single commandprint<newline>list. Whilethis differs from historical practice, POSIX.1-2024 developers believed it unlikely that any script or user depended on thehistorical behavior.

Historically, an error in a command specified using the-c option did not cause the rest of the-ccommands to be discarded. POSIX.1-2024 disallows this for consistency with mapped keys, the@,global,source,andv commands, theEXINIT environment variable, and the.exrc files.

Input Editing in ex

One of the common uses of the historicalex editor is over slow network connections. Editors that run incanonical mode can require far less traffic to and from, and far less processing on, the host machine, as well as more easilysupporting block-mode terminals. For these reasons, POSIX.1-2024 requires thatex be implemented using canonical mode inputprocessing, as was done historically.

POSIX.1-2024 does not require the historical 4 BSD input editing characters "word erase" or "literal next". Forthis reason, it is unspecified how they are handled byex, although they must have the required effect. Implementations thatresolve them after the line has been ended using a <newline> or <control>-M character, and implementations that rely onthe underlying system terminal support for this processing, are both conforming. Implementations are strongly urged to use theunderlying system functionality, if at all possible, for compatibility with other system text input interfaces.

Historically, when theeof character was used to decrement theautoindent level, the cursor moved todisplay the new end of theautoindent characters, but did not move the cursor to a new line, nor did it erase the<control>-D character from the line. POSIX.1-2024 does not specify that the cursor remain on the same line or that the restof the line is erased; however, implementations are strongly encouraged to provide the best possible user interface; that is, thecursor should remain on the same line, and any <control>-D character on the line should be erased.

POSIX.1-2024 does not require the historical 4 BSD input editing character "reprint", traditionally<control>-R, which redisplayed the current input from the user. For this reason, and because the functionality cannot beimplemented after the line has been terminated by the user, POSIX.1-2024 makes no requirements about this functionality.Implementations are strongly urged to make this historical functionality available, if possible.

Historically, <control>-Q did not perform a literal next function inex, as it did invi. POSIX.1-2024 requires conformance to historical practice to avoid breaking historicalex scripts and.exrc files.

eof

Whether theeof character immediately modifies theautoindent characters in the prompt is leftunspecified so that implementations can conform in the presence of systems that do not support this functionality. Implementationsare encouraged to modify the line and redisplay it immediately, if possible.

The specification of the handling of theeof character differs from historical practice only in thateof characters are not discarded if they follow normal characters in the text input. Historically, they were alwaysdiscarded.

Command Descriptions in ex

Historically, several commands (for example,global,v,visual,s,write,wq,yank,!,<,>,&, and~) were executable in empty files (that is, thedefault address(es) were 0), or permitted explicit addresses of 0 (for example, 0 was a valid address, or 0,0 was a valid range).Addresses of 0, or command execution in an empty file, make sense only for commands that add new text to the edit buffer or writecommands (because users may wish to write empty files). POSIX.1-2024 requires this behavior for such commands and disallows itotherwise, for consistency and simplicity of specification.

A count to anex command has been historically corrected to be no greater than the last line in a file; forexample, in a five-line file, the command1,6print would fail, but the command1print300 would succeed. POSIX.1-2024requires conformance to historical practice.

Historically, the use of flags inex commands could be obscure. General historical practice was as describedby POSIX.1-2024, but there were some special cases. For instance, thelist,number, andprint commands ignoredtrailing address offsets; for example,3p +++# would display line 3, and 3 would be the current line after theexecution of the command. Theopen andvisual commands ignored both the trailing offsets and the trailing flags.Also, flags specified to theopen andvisual commands interacted badly with thelist edit option, and settingand then unsetting it during the open/visual session would causevi to stop displayinglines in the specified format. For consistency and simplicity of specification, POSIX.1-2024 does not permit any of theseexceptions to the general rule.

POSIX.1-2024 uses the wordcopy in several places when discussing buffers. This is not intended to implyimplementation.

Historically,ex users could not specify numeric buffers because of the ambiguity this would cause; forexample, in the command3 delete 2, it is unclear whether 2 is a buffer name or acount. POSIX.1-2024requires conformance to historical practice by default, but does not preclude extensions.

Historically, the contents of the unnamed buffer were frequently discarded after commands that did not explicitlyaffect it; for example, when using theedit command to switch files. For consistency and simplicity of specification,POSIX.1-2024 does not permit this behavior.

Theex utility did not historically have access to the numeric buffers, and, furthermore, deleting lines inex did not modify their contents. For example, if, after doing a delete invi, theuser switched toex, did another delete, and then switched back tovi, thecontents of the numeric buffers would not have changed. POSIX.1-2024 requires conformance to historical practice. Numeric buffersare described in theex utility in order to confine the description of buffers to a single location in POSIX.1-2024.

The metacharacters that trigger shell expansion infile arguments match historical practice, as does themethod for doing shell expansion. Implementations wishing to provide users with the flexibility to alter the set of metacharactersare encouraged to provide ashellmeta string edit option.

Historically,ex commands executed fromvi refreshed the screenwhen it did not strictly need to do so; for example,:!date > /dev/null does not require a screen refreshbecause the output of the UNIXdate command requires only a single line of the screen.POSIX.1-2024 requires that the screen be refreshed if it has been overwritten, but makes no requirements as to how animplementation should make that determination. Implementations may prompt and refresh the screen regardless.

Abbreviate

Historical practice was that characters that were entered as part of an abbreviation replacement were subject tomap expansions, theshowmatch edit option, further abbreviation expansions, and so on; that is, they were logicallypushed onto the terminal input queue, and were not a simple replacement. POSIX.1-2024 requires conformance to historical practice.Historical practice was that whenever a non-word character (that had not been escaped by a <control>-V) was entered after aword character,vi would check for abbreviations. The check was based on the type of thecharacter entered before the word character of the word/non-word pair that triggered the check. The word character of theword/non-word pair that triggered the check and all characters entered before the trigger pair that were of that type were includedin the check, with the exception of <blank> characters, which always delimited the abbreviation.

This means that, for the abbreviation to work, thelhs must end with a word character, there can be notransitions from word to non-word characters (orvice versa) other than between the last and next-to-last characters in thelhs, and there can be no <blank> characters in thelhs. In addition, because of the historical quoting rules,it was impossible to enter a literal <control>-V in thelhs. POSIX.1-2024 requires conformance to historical practice.Historical implementations did not inform users when abbreviations that could never be used were entered; implementations arestrongly encouraged to do so.

For example, the following abbreviations will work:

:ab (p  REPLACE:ab p   REPLACE:ab ((p REPLACE

The following abbreviations will not work:

:ab (   REPLACE:ab (pp REPLACE

Historical practice is that words on thevi colon command line weresubject to abbreviation expansion, including the arguments to theabbrev (and more interestingly) theunabbrevcommand. Because there are implementations that do not do abbreviation expansion for the first argument to those commands, this ispermitted, but not required, by POSIX.1-2024. However, the following sequence:

:ab foo bar:ab foo baz

resulted in the addition of an abbreviation of"baz" for the string"bar" in historicalex/vi, and the sequence:

:ab foo1 bar:ab foo2 bar:unabbreviate foo2

deleted the abbreviation"foo1", not"foo2". These behaviors are not permitted by POSIX.1-2024because they clearly violate the expectations of the user.

It was historical practice that <control>-V, not <backslash>, characters be interpreted as escapingsubsequent characters in theabbreviate command. POSIX.1-2024 requires conformance to historical practice; however, itshould be noted that an abbreviation containing a <blank> will never work.

Append

Historically, any text following a <vertical-line> command separator after anappend,change,orinsert command became part of the insert text. For example, in the command:

:g/pattern/append|stuff1

a line containing the text"stuff1" would be appended to each line matching pattern. It was alsohistorically valid to enter:

:append|stuff1stuff2.

and the text on theex command line would be appended along with the text inserted after it. There was anhistorical bug, however, that the user had to enter two terminating lines (the'.' lines) to terminate text input mode inthis case. POSIX.1-2024 requires conformance to historical practice, but disallows the historical need for multiple terminatinglines.

Change

See the RATIONALE for theappend command. Historical practice for cursor positioning after the changecommand when no text is input, is as described in POSIX.1-2024. However, one System V implementation is known to have been modifiedsuch that the cursor is positioned on the first address specified, and not on the line before the first address. POSIX.1-2024disallows this modification for consistency.

Historically, thechange command did not support buffer arguments, although some implementations allow thespecification of an optional buffer. This behavior is neither required nor disallowed by POSIX.1-2024.

Change Directory

A common extension inex implementations is to use the elements of acdpath edit option as prefixdirectories forpath arguments tochdir that are relative pathnames and that do not have'.' or".." as their first component. Elements in thecdpath edit option are <colon>-separated. The initial value ofthecdpath edit option is the value of the shellCDPATH environment variable. This feature was not included inPOSIX.1-2024 because it does not exist in any of the implementations considered historical practice.

Copy

Historical implementations ofex permitted copies to lines inside of the specified range; for example,:2,5copy3 was a valid command. POSIX.1-2024 requires conformance to historical practice.

Delete

POSIX.1-2024 requires support for the historical parsing of adelete command followed by flags, without anyintervening <blank> characters. For example:

1dp
Deletes the first line and prints the line that was second.
1delep
As for1dp.
1d
Deletes the first line, saving it in bufferp.
1d p1l
(Pee-one-ell.) Deletes the first line, saving it in bufferp, and listing the line that was second.
Edit

Historically, anyex command could be entered as a+command argument to theeditcommand, although some (for example,insert andappend) were known to confuse historical implementations. Forconsistency and simplicity of specification, POSIX.1-2024 requires that any command be supported as an argument to theeditcommand.

Historically, the command argument was executed with the current line set to the last line of the file, regardlessof whether theedit command was executed from visual mode or not. POSIX.1-2024 requires conformance to historicalpractice.

Historically, the+command specified to theedit andnext commands was delimited by thefirst <blank>, and there was no way to quote them. For consistency, POSIX.1-2024 requires that the usualex backslashquoting be provided.

Historically, specifying the+command argument to the edit command required a filename to bespecified as well; for example,:edit +100 would always fail. For consistency and simplicity of specification,POSIX.1-2024 does not permit this usage to fail for that reason.

Historically, only the cursor position of the last file edited was remembered by the editor. POSIX.1-2024 requiresthat this be supported; however, implementations are permitted to remember and restore the cursor position for any file previouslyedited.

File

Historical versions of theex editorfile command displayed a current line and number of lines in theedit buffer of 0 when the file was empty, while thevi <control>-G commanddisplayed a current line and number of lines in the edit buffer of 1 in the same situation. POSIX.1-2024 does not permit thisdiscrepancy, instead requiring that a message be displayed indicating that the file is empty.

Global

The two-pass operation of theglobal andv commands is not intended to imply implementation, only therequired result of the operation.

The current line and column are set as specified for the individualex commands. This requirement iscumulative; that is, the current line and column must track across all the commands executed by theglobal orvcommands.

Insert

See the RATIONALE for theappend command.

Historically,insert could not be used with an address of zero; that is, not when the edit buffer was empty.POSIX.1-2024 requires that this command behave consistently with theappend command.

Join

The action of thejoin command in relation to the special characters is only defined for the POSIX localebecause the correct amount of white space after a period varies; in Japanese none is required, in French only a single space, andso on.

List

The historical output of thelist command was potentially ambiguous. The standard developers believedcorrecting this to be more important than adhering to historical practice, and POSIX.1-2024 requires unambiguous output.

Map

Historically, command mode maps only applied to command names; for example, if the character'x' wasmapped to'y', the commandfx searched for the'x' character, not the'y' character. POSIX.1-2024requires this behavior. Historically, entering <control>-V as the first character of avi command was an error. Several implementations have extended the semantics ofvi such that <control>-V means that the subsequent command character is not mapped. This ispermitted, but not required, by POSIX.1-2024. Regardless, using <control>-V to escape the second or later character in asequence of characters that might match amap command, or any character in text input mode, is historical practice, andstops the entered keys from matching a map. POSIX.1-2024 requires conformance to historical practice.

Historical implementations permitted digits to be used as amap commandlhs, but then ignored themap. POSIX.1-2024 requires that the mapped digits not be ignored.

The historical implementation of themap command did not permitmap commands that were more than asingle character in length if the first character was printable. This behavior is permitted, but not required, by POSIX.1-2024.

Historically, mapped characters were remapped unless theremap edit option was not set, or the prefix of themapped characters matched the mapping characters; for example, in themap:

:map ab abcd

the characters"ab" were used as is and were not remapped, but the characters"cd" were mapped ifappropriate. This can cause infinite loops in thevi mapping mechanisms. POSIX.1-2024requires conformance to historical practice, and that such loops be interruptible.

Text input maps had the same problems with expanding thelhs for theexmap! andunmap!command as did theexabbreviate andunabbreviate commands. See the RATIONALE for theexabbreviate command. POSIX.1-2024 requires similar modification of some historical practice for themap andunmap commands, as described for theabbreviate andunabbreviate commands.

Historically,maps that were subsets of othermaps behaved differently depending on the order inwhich they were defined. For example:

:map! ab     short:map! abc    long

would always translate the characters"ab" to"short", regardless of how fast the characters"abc" were entered. If the entry order was reversed:

:map! abc    long:map! ab     short

the characters"ab" would cause the editor to pause, waiting for the completing'c' character,and the characters might never be mapped to"short". For consistency and simplicity of specification, POSIX.1-2024requires that the shortest match be used at all times.

The length of time the editor spends waiting for the characters to complete thelhs is unspecified becausethe timing capabilities of systems are often inexact and variable, and it may depend on other factors such as the speed of theconnection. The time should be long enough for the user to be able to complete the sequence, but not long enough for the user tohave to wait. Some implementations ofvi have added akeytime option, whichpermits users to set the number of 0,1 seconds the editor waits for the completing characters. Because mapped terminal function andcursor keys tend to start with an <ESC> character, and <ESC> is the key endingvi text input mode,maps starting with <ESC> characters are generally exempted fromthis timeout period, or, at least timed out differently.

Mark

Historically, users were able to set the "previous context" marks explicitly. In addition, theex commands'' and'` and thevi commands'',``,`',and'` all referred to the same mark. In addition, the previous context marks were not set if the command, with which theaddress setting the mark was associated, failed. POSIX.1-2024 requires conformance to historical practice. Historically, if markedlines were deleted, the mark was also deleted, but would reappear if the change was undone. POSIX.1-2024 requires conformance tohistorical practice.

The description of the special events that set the` and' marks matches historical practice. Forexample, historically the command/a/,/b/ did not set the` and' marks, but the command/a/,/b/deletedid.

Next

Historically, anyex command could be entered as a+command argument to thenextcommand, although some (for example,insert andappend) were known to confuse historical implementations.POSIX.1-2024 requires that any command be permitted and that it behave as specified. Thenext command can accept more thanone file, so usage such as:

next `ls [abc] `

is valid; it need not be valid for theedit orread commands, for example, because they expect onlyone filename.

Historically, thenext command behaved differently from the:rewind command in that it ignored theforce flag if theautowrite flag was set. For consistency, POSIX.1-2024 does not permit this behavior.

Historically, thenext command positioned the cursor as if the file had never been edited before,regardless. POSIX.1-2024 does not permit this behavior, for consistency with theedit command.

Implementations wanting to provide a counterpart to thenext command that edited the previous file have usedthe commandprev[ious], which takes nofile argument. POSIX.1-2024 does not require this command.

Open

Historically, theopen command would fail if theopen edit option was not set. POSIX.1-2024 does notmention theopen edit option and does not require this behavior. Some historical implementations do not permit entering openmode from open or visual mode, only fromex mode. For consistency, POSIX.1-2024 does not permit this behavior.

Historically, entering open mode from the command line (that is,vi+open) resulted in anomalous behaviors; for example, theex file andset commands, and thevi command<control>-G did not work. For consistency, POSIX.1-2024 does not permit this behavior.

Historically, theopen command only permitted'/' characters to be used as the search patterndelimiter. For consistency, POSIX.1-2024 requires that the search delimiters used by thes,global, andvcommands be accepted as well.

Preserve

Thepreserve command does not historically cause the file to be considered unmodified for the purposes offuture commands that may exit the editor. POSIX.1-2024 requires conformance to historical practice.

Historical documentation stated that mail was not sent to the user when preserve was executed; however, historicalimplementations did send mail in this case. POSIX.1-2024 requires conformance to the historical implementations.

Print

The writing of NUL by theprint command is not specified as a special case because the standard developersdid not want to requireex to support NUL characters. Historically, characters were displayed using the ARPA standardmappings, which are as follows:

  1. Printable characters are left alone.
  2. Control characters less than \177 are represented as'^' followed by the character offset from the'@' character in the ASCII map; for example, \007 is represented as'^G'.
  3. \177 is represented as'^' followed by'?'.

The display of characters having their eighth bit set was less standard. Existing implementations use hex (0x00),octal (\000), and a meta-bit display. (The latter displayed bytes that had their eighth bit set as the two characters"M-"followed by the seven-bit display as described above.) The latter probably has the best claim to historical practice because it wasused for the-v option of 4 BSD and 4 BSD-derived versions of thecat utilitysince 1980.

No specific display format is required by POSIX.1-2024.

Explicit dependence on the ASCII character set has been avoided where possible, hence the use of the phrase an"implementation-defined multi-character sequence" for the display of non-printable characters in preference to the historicalusage of, for instance,"^I" for the <tab>. Implementations are encouraged to conform to historical practice in theabsence of any strong reason to diverge.

Historically, allex commands beginning with the letter'p' could be entered using capitalizedversions of the commands; for example,P[rint],Pre[serve], andPu[t] were all valid command names.POSIX.1-2024 permits, but does not require, this historical practice because capital forms of the commands are used by someimplementations for other purposes.

Put

Historically, anexput command, executed from open or visual mode, was the same as the open orvisual modeP command, if the buffer was named and was cut in character mode, and the same as thep command if thebuffer was named and cut in line mode. If the unnamed buffer was the source of the text, the entire line from which the text wastaken was usuallyput, and the buffer was handled as if in line mode, but it was possible to get extremely anomalousbehavior. In addition, using theQ command to switch intoex mode, and then doing aput often resulted inerrors as well, such as appending text that was unrelated to the (supposed) contents of the buffer. For consistency and simplicityof specification, POSIX.1-2024 does not permit these behaviors. Allexput commands are required to operate in linemode, and the contents of the buffers are not altered by changing the mode of the editor.

Read

Historically, anexread command executed from open or visual mode, executed in an empty file, leftan empty line as the first line of the file. For consistency and simplicity of specification, POSIX.1-2024 does not permit thisbehavior. Historically, aread in open or visual mode from a program left the cursor at the last line read in, not thefirst. For consistency, POSIX.1-2024 does not permit this behavior.

Historical implementations ofex were unable to undoread commands that read from the output of aprogram. For consistency, POSIX.1-2024 does not permit this behavior.

Historically, theex andvi message after a successfulreadorwrite command specified "characters", not "bytes". POSIX.1-2024 requires that the number of bytes be displayed, notthe number of characters, because it may be difficult in multi-byte implementations to determine the number of characters read.Implementations are encouraged to clarify the message displayed to the user.

Historically, reads were not permitted on files other than type regular, except that FIFO files could be read(probably only because they did not exist whenex andvi were originally written).Because the historicalex evaluatedread! andread ! equivalently, there can be no optional way to forcethe read. POSIX.1-2024 permits, but does not require, this behavior.

Recover

Some historical implementations of the editor permitted users to recover the edit buffer contents from a previousedit session, and then exit without saving those contents (or explicitly discarding them). The intent of POSIX.1-2024 in requiringthat the edit buffer be treated as already modified is to prevent this user error.

Rewind

Historical implementations supported therewind command when the user was editing the first file in thelist; that is, the file that therewind command would edit. POSIX.1-2024 requires conformance to historical practice.

Substitute

Historically,ex accepted anr option to thes command. The effect of ther option wasto use the last regular expression used in any command as the pattern, the same as the~ command. Ther option is notrequired by POSIX.1-2024. Historically, thec andg options were toggled; for example, the command:s/abc/def/was the same ass/abc/def/ccccgggg. For simplicity of specification, POSIX.1-2024 does not permit this behavior.

The tilde command is often used to replace the last search RE. For example, in the sequence:

s/red/blue//green~

the~ command is equivalent to:

s/green/blue/

Historically,ex accepted all of the following forms:

s/abc/def/s/abc/defs/abc/s/abc

POSIX.1-2024 requires conformance to this historical practice.

Thes command presumes that the'^' character only occupies a single column in the display. Much oftheex andvi specification presumes that the <space> only occupies a singlecolumn in the display. There are no known character sets for which this is not true.

Historically, the final column position for the substitute commands was based on previous column movements; asearch for a pattern followed by a substitution would leave the column position unchanged, while a 0 command followed by asubstitution would change the column position to the first non-<blank>. For consistency and simplicity of specification,POSIX.1-2024 requires that the final column position always be set to the first non-<blank>.

Set

Historical implementations redisplayed all of the options for each occurrence of theall keyword.POSIX.1-2024 permits, but does not require, this behavior.

Tag

No requirement is made as to whereex andvi shall look for thefile referenced by the tag entry. Historical practice has been to look for the path found in thetags file, based on thecurrent directory. A useful extension found in some implementations is to look based on the directory containing the tags file thatheld the entry, as well. No requirement is made as to which reference for the tag in the tags file is used. This is deliberate, inorder to permit extensions such as multiple entries in a tags file for a tag.

Because users often specify many different tags files, some of which need not be relevant or exist at anyparticular time, POSIX.1-2024 requires that error messages about problem tags files be displayed only if the requested tag is notfound, and then, only once for each time that thetag edit option is changed.

The requirement that the current edit buffer be unmodified is only necessary if the file indicated by the tag entryis not the same as the current file (as defined by the current pathname). Historically, the file would be reloaded if the filenamehad changed, as well as if the filename was different from the current pathname. For consistency and simplicity of specification,POSIX.1-2024 does not permit this behavior, requiring that the name be the only factor in the decision.

Historically,vi only searched for tags in the current file from thecurrent cursor to the end of the file, and therefore, if thewrapscan option was not set, tags occurring before the currentcursor were not found. POSIX.1-2024 considers this a bug, and implementations are required to search for the first occurrence inthe file, regardless.

Undo

Theundo description deliberately uses the word "modified". Theundo command is not intended toundo commands that replace the contents of the edit buffer, such asedit,next,tag, orrecover.

Cursor positioning after theundo command was inconsistent in the historicalvi, sometimes attempting to restore the original cursor position (global,undo, andv commands), and sometimes, in the presence of maps, placing the cursor on the last line added or changed instead of thefirst. POSIX.1-2024 requires a simplified behavior for consistency and simplicity of specification.

Version

Theversion command cannot be exactly specified since there is no widely-accepted definition of what theversion information should contain. Implementations are encouraged to do something reasonably intelligent.

Write

Historically, theex andvi message after a successfulreadorwrite command specified "characters", not "bytes". POSIX.1-2024 requires that the number of bytes be displayed, notthe number of characters because it may be difficult in multi-byte implementations to determine the number of characters written.Implementations are encouraged to clarify the message displayed to the user.

Implementation-defined tests are permitted so that implementations can make additional checks; for example, forlocks or file modification times.

Historically, attempting to append to a nonexistent file caused an error. It has been left unspecified inPOSIX.1-2024 to permit implementations to let thewrite succeed, so that the append semantics are similar to those of thehistoricalcsh.

Historicalvi permitted empty edit buffers to be written. However, sincethe wayvi got around dealing with "empty" files was to always have a line in the editbuffer, no matter what, it wrote them as files of a single, empty line. POSIX.1-2024 does not permit this behavior.

Historically,ex restored standard output and standard error to their values as of whenex wasinvoked, before writes to programs were performed. This could disturb the terminal configuration as well as be a security issue forsome terminals. POSIX.1-2024 does not permit this, requiring that the program output be captured and displayed as if by theexprint command.

Adjust Window

Historically, the line count was set to the value of thescroll option if the type character wasend-of-file. This feature was broken on most historical implementations long ago, however, and is not documented anywhere. For thisreason, POSIX.1-2024 is resolutely silent.

Historically, thez command was <blank>-sensitive andz + andz - diddifferent things thanz+ andz- because the type could not be distinguished from a flag. (The commandsz . andz = were historically invalid.) POSIX.1-2024 requires conformance to this historical practice.

Historically, thez command was further <blank>-sensitive in that thecount could not be<blank>-delimited; for example, the commandsz= 5 andz- 5 were also invalid. Because thecount is not ambiguous with respect to either the type character or the flags, this is not permitted by POSIX.1-2024.

Escape

Historically,ex filter commands only read the standard output of the commands, letting standard errorappear on the terminal as usual. Thevi utility, however, read both standard output andstandard error. POSIX.1-2024 requires the latter behavior for bothex andvi, forconsistency.

In Issue 8 thesystem() function was changed to require that thePOSIX shell be invoked with"sh","-c","--", andcommand arguments to make it easier to executeprograms with <hyphen-minus> ('-') or <plus-sign> ('+') as the first character of the program'sfilename. A similar request to have theexescape command do the same was not accepted. Unlikesystem() (which always invokes a POSIX shell),ex invokes the program named by theshell edit option. For example, thecsh andtcsh shells that are frequently used as login shells do notrecognize"--" after"-c" as an end-of-options indicator. The program need not even be one that recognizes anyPOSIX shell command line syntax. Some users invoke shell scripts to process lines that are being supplied to the specified utility.These utilities know that they will be given"-c" as a first argument and just ignore it. Any utilities used in thismanner would have to be modified to skip over another argument (the"--") to find the desired argument.

Shift Left and Shift Right

Historically, it was possible to add shift characters to increase the effect of the command; for example,<<< outdented (or>>> indented) the lines 3 levels of indentation instead of the default 1.POSIX.1-2024 requires conformance to historical practice.

<control>-D

Historically, the <control>-D command erased the prompt, providing the user with an unbroken presentation oflines from the edit buffer. This is not required by POSIX.1-2024; implementations are encouraged to provide it if possible.Historically, the <control>-D command took, and then ignored, acount. POSIX.1-2024 does not permit this behavior.

Write Line Number

Historically, theex= command, when executed inex mode in an empty edit buffer, reported 0,and from open or visual mode, reported 1. For consistency and simplicity of specification, POSIX.1-2024 does not permit thisbehavior.

Execute

Historically,ex did not correctly handle the inclusion of text input commands (that is,append,insert, andchange) in executed buffers. POSIX.1-2024 does not permit this exclusion for consistency.

Historically, the logical contents of the buffer being executed did not change if the buffer itself were modifiedby the commands being executed; that is, buffer execution did not support self-modifying code. POSIX.1-2024 requires conformance tohistorical practice.

Historically, the@ command took a range of lines, and the@ buffer was executed once per line, withthe current line ('.') set to each specified line. POSIX.1-2024 requires conformance to historical practice.

Some historical implementations did not notice if errors occurred during buffer execution. This, coupled with theability to specify a range of lines for theex@ command, makes it trivial to cause them to dropcore.POSIX.1-2024 requires that implementations stop buffer execution if any error occurs, if the specified line doesn't exist, or ifthe contents of the edit buffer itself are replaced (for example, the buffer executes theex:edit command).

Regular Expressions in ex

Historical practice is that the characters in the replacement part of the lasts command—that is, thosematched by entering a'~' in the regular expression—were not further expanded by the regular expression engine. So, if thecharacters contained the string"a.," they would match'a' followed by".," and not'a'followed by any character. POSIX.1-2024 requires conformance to historical practice.

Edit Options in ex

The following paragraphs describe the historical behavior of some edit options that were not, for whatever reason,included in POSIX.1-2024. Implementations are strongly encouraged to only use these names if the functionality described here isfully supported.

extended
Theextended edit option has been used in some implementations ofvi toprovide extended regular expressions instead of basic regular expressions This option was omitted from POSIX.1-2024 because it isnot widespread historical practice.
flash
Theflash edit option historically caused the screen to flash instead of beeping on error. This option was omitted fromPOSIX.1-2024 because it is not found in some historical implementations.
hardtabs
Thehardtabs edit option historically defined the number of columns between hardware tab settings. This option wasomitted from POSIX.1-2024 because it was believed to no longer be generally useful.
modeline
Themodeline (sometimes namedmodelines) edit option historically causedex orvi to read the five first and last lines of the file for editor commands. This option is asecurity problem, and vendors are strongly encouraged to delete it from historical implementations.
open
Theopen edit option historically disallowed theexopen andvisual commands. This edit option wasomitted because these commands are required by POSIX.1-2024.
optimize
Theoptimize edit option historically expedited text throughput by setting the terminal to not do automatic<carriage-return> characters when printing more than one logical line of output. This option was omitted from POSIX.1-2024because it was intended for terminals without addressable cursors, which are rarely, if ever, still used.
ruler
Theruler edit option has been used in some implementations ofvi to present acurrent row/column ruler for the user. This option was omitted from POSIX.1-2024 because it is not widespread historicalpractice.
sourceany
Thesourceany edit option historically causedex orvi to sourcestart-up files that were owned by users other than the user running the editor. This option is a security problem, and vendors arestrongly encouraged to remove it from their implementations.
timeout
Thetimeout edit option historically enabled the (now standard) feature of only waiting for a short period beforereturning keys that could be part of a macro. This feature was omitted from POSIX.1-2024 because its behavior is now standard, itis not widely useful, and it was rarely documented.
verbose
Theverbose edit option has been used in some implementations ofvi to causevi to output error messages for common errors; for example, attempting to move the cursorpast the beginning or end of the line instead of only alerting the screen. (The historicalvi only alerted the terminal and presented no message for such errors. The historical editoroptionterse did not select when to present error messages, it only made existing error messages more or less verbose.) Thisoption was omitted from POSIX.1-2024 because it is not widespread historical practice; however, implementors are encouraged to useit if they wish to provide error messages for naive users.
wraplen
Thewraplen edit option has been used in some implementations ofvi to specifyan automatic margin measured from the left margin instead of from the right margin. This is useful when multiple screen sizes arebeing used to edit a single file. This option was omitted from POSIX.1-2024 because it is not widespread historical practice;however, implementors are encouraged to use it if they add this functionality.
autoindent, ai

Historically, the command0a did not do any autoindentation, regardless of the current indentation of line1. POSIX.1-2024 requires that any indentation present in line 1 be used.

autoprint, ap

Historically, theautoprint edit option was not completely consistent or based solely on modifications tothe edit buffer. Exceptions were theread command (when reading from a file, but not from a filter), theappend,change,insert,global, andv commands, all of which were not affected byautoprint, and thetag command, which was affected byautoprint. POSIX.1-2024 requires conformance to historical practice.

Historically, theautoprint option only applied to the last of multiple commands entered using<vertical-line> delimiters; for example,delete <newline> was affected byautoprint, butdelete|version <newline> was not. POSIX.1-2024 requires conformance to historical practice.

autowrite, aw

Appending the'!' character to theexnext command to avoid performing an automatic writewas not supported in historical implementations. POSIX.1-2024 requires that the behavior match the otherex commands forconsistency.

ignorecase, ic

Historical implementations of case-insensitive matching (theignorecase edit option) lead tocounter-intuitive situations when uppercase characters were used in range expressions. Historically, the process was asfollows:

  1. Take a line of text from the edit buffer.
  2. Convert uppercase to lowercase in text line.
  3. Convert uppercase to lowercase in regular expressions, except in character class specifications.
  4. Match regular expressions against text.

This would mean that, withignorecase in effect, the text:

The cat sat on the mat

would be matched by

/^the/

but not by:

/^[A-Z]he/

For consistency with other commands implementing regular expressions, POSIX.1-2024 does not permit thisbehavior.

paragraphs, para

The ISO POSIX-2:1993 standard made the defaultparagraphs andsections edit optionsimplementation-defined, arguing they were historically oriented to the UNIX systemtroff text formatter, and a "portableuser" could use the{,},[[,]],(, and) commands in open or visual mode and have thecursor stop in unexpected places. POSIX.1-2024 specifies their values in the POSIX locale because the unusual grouping (they onlywork when grouped into two characters at a time) means that they cannot be used for general-purpose movement, regardless.

readonly

Implementations are encouraged to provide the best possible information to the user as to the read-only status ofthe file, with the exception that they should not consider the current special privileges of the process. This provides users witha safety net because they must force the overwrite of read-only files, even when running with additional privileges.

Thereadonly edit option specification largely conforms to historical practice. The only difference is thathistorical implementations did not notice that the user had set thereadonly edit option in cases where the file was alreadymarked read-only for some reason, and would therefore reinitialize thereadonly edit option the next time the contents ofthe edit buffer were replaced. This behavior is disallowed by POSIX.1-2024.

report

The requirement that lines copied to a buffer interact differently than deleted lines is historical practice. Forexample, if thereport edit option is set to 3, deleting 3 lines will cause a report to be written, but 4 lines must becopied before a report is written.

The requirement that theexglobal,v,open,undo, andvisual commandspresent reports based on the total number of lines added or deleted during the command execution, and that commands executed by theglobal andv commands not present reports, is historical practice. POSIX.1-2024 extends historical practice byrequiring that buffer execution be treated similarly. The reasons for this are two-fold. Historically, only the report by the lastcommand executed from the buffer would be seen by the user, as each new report would overwrite the last. In addition, the standarddevelopers believed that buffer execution had more in common withglobal andv commands than it did with otherex commands, and should behave similarly, for consistency and simplicity of specification.

showmatch, sm

The length of time the cursor spends on the matching character is unspecified because the timing capabilities ofsystems are often inexact and variable. The time should be long enough for the user to notice, but not long enough for the user tobecome annoyed. Some implementations ofvi have added amatchtime option thatpermits users to set the number of 0,1 second intervals the cursor pauses on the matching character.

showmode

Theshowmode option has been used in some historical implementations ofex andvi to display the current editing mode when in open or visual mode. The editing modes havegenerally included "command" and "input", and sometimes other modes such as "replace" and "change". The string was usuallydisplayed on the bottom line of the screen at the far right-hand corner. In addition, a preceding'*' character oftendenoted whether the contents of the edit buffer had been modified. The latter display has sometimes been part of theshowmode option, and sometimes based on another option. This option was not available in the 4 BSD historical implementationofvi, but was viewed as generally useful, particularly to novice users, and is requiredby POSIX.1-2024.

Thesmd shorthand for theshowmode option was not present in all historical implementations of theeditor. POSIX.1-2024 requires it, for consistency.

Not all historical implementations of the editor displayed a mode string for command mode, differentiating commandmode from text input mode by the absence of a mode string. POSIX.1-2024 permits this behavior for consistency with historicalpractice, but implementations are encouraged to provide a display string for both modes.

slowopen

Historically, theslowopen option was automatically set if the terminal baud rate was less than 1200 baud,or if the baud rate was 1200 baud and theredraw option was not set. Theslowopen option had two effects. First, wheninserting characters in the middle of a line, characters after the cursor would not be pushed ahead, but would appear to beoverwritten. Second, when creating a new line of text, lines after the current line would not be scrolled down, but would appear tobe overwritten. In both cases, ending text input mode would cause the screen to be refreshed to match the actual contents of theedit buffer. Finally, terminals that were sufficiently intelligent caused the editor to ignore theslowopen option.POSIX.1-2024 permits most historical behavior, extending historical practice to requireslowopen behaviors if the editoption is set by the user.

tags

The default path for tags files is left unspecified as implementations may have their owntagsimplementations that do not correspond to the historical ones. The defaulttags option value should probably at leastinclude the file./tags.

term

Historical implementations ofex andvi ignored changes to theterm edit option after the initial terminal information was loaded. This is permitted by POSIX.1-2024; however,implementations are encouraged to permit the user to modify their terminal type at any time.

terse

Historically, theterse edit option optionally provided a shorter, less descriptive error message, for someerror messages. This is permitted, but not required, by POSIX.1-2024. Historically, most common visual mode errors (for example,trying to move the cursor past the end of a line) did not result in an error message, but simply alerted the terminal.Implementations wishing to provide messages for novice users are urged to do so based on theedit optionverbose, andnotterse.

window

In historical implementations, the default for thewindow edit option was based on the baud rate asfollows:

  1. If the baud rate was less than 1200, theedit optionw300 set the window value; for example, theline:
    set w300=12

    would set the window option to 12 if the baud rate was less than 1200.

  2. If the baud rate was equal to 1200, theedit optionw1200 set the window value.
  3. If the baud rate was greater than 1200, theedit optionw9600 set the window value.

Thew300,w1200, andw9600 options do not appear in POSIX.1-2024 because of their dependenceon specific baud rates.

In historical implementations, the size of the window displayed by various commands was related to, but notnecessarily the same as, thewindow edit option. For example, the size of the window was set by theex commandvisual 10, but it did not change the value of thewindow edit option. However, changing the value of thewindow edit option did change the number of lines that were displayed when the screen was repainted. POSIX.1-2024 does notpermit this behavior in the interests of consistency and simplicity of specification, and requires that all commands that changethe number of lines that are displayed do it by setting the value of thewindow edit option.

wrapmargin, wm

Historically, thewrapmargin option did not affect maps inserting characters that also had associatedcounts; for example:map K 5aABC DEF. Unfortunately, there are widely used maps that depend on thisbehavior. For consistency and simplicity of specification, POSIX.1-2024 does not permit this behavior.

Historically,wrapmargin was calculated using the column display width of all characters on the screen. Forexample, an implementation using"^I" to represent <tab> characters when thelist edit option was set, where'^' and'I' each took up a single column on the screen, would calculate thewrapmargin based on a value of2 for each <tab>. Thenumber edit option similarly changed the effective length of the line as well. POSIX.1-2024requires conformance to historical practice.

Earlier versions of this standard allowed for implementations with bytes other than eight bits, but this has beenmodified in this version.

FUTURE DIRECTIONS

If this utility is directed to create a new directory entry that contains any bytes that have the encoded value of a<newline> character, implementations are encouraged to treat this as an error. A future version of this standard may requireimplementations to treat this as an error.

SEE ALSO

2.9.1.4 Command Search and Execution,ctags,ed,sed,sh,stty,vi

XBDEscape Sequences and Associated Actions,8. Environment Variables,9.3Basic Regular Expressions,12.2 Utility Syntax Guidelines

XSHaccess()

CHANGE HISTORY

First released in Issue 2.

Issue 5

The FUTURE DIRECTIONS section is added.

Issue 6

This utility is marked as part of the User Portability Utilities option.

The obsolescent SYNOPSIS is removed, removing the+command and- options.

The following new requirements on POSIX implementations derive from alignment with the Single UNIXSpecification:

Theex utility is extensively changed for alignment with the IEEE P1003.2b draft standard. Thisincludes changes as a result of the IEEE PASC Interpretations 1003.2 #31, #38, #49, #50, #51, #52, #55, #56, #57, #61, #62, #63,#64, #65, and #78.

The-l option is removed.

IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/23 is applied, correcting a URL.

IEEE Std 1003.1-2001/Cor 2-2004, item XCU/TC2/D6/8 is applied, making an editorial correction in theEXTENDED DESCRIPTION.

IEEE Std 1003.1-2001/Cor 2-2004, item XCU/TC2/D6/9 is applied, removing text describing behavior onsystems with bytes consisting of more than eight bits.

Issue 7

Austin Group Interpretation 1003.1-2001 #027 is applied, clarifying the behavior if an operand is'-'.

Austin Group Interpretation 1003.1-2001 #036 is applied, clarifying the behavior for BREs.

Austin Group Interpretation 1003.1-2001 #121 is applied, clarifying theexwrite command.

Austin Group Interpretation 1003.1-2001 #156 is applied.

SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.

POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0093 [584] is applied.

Issue 8

Austin Group Defect 251 is applied, encouraging implementations to disallow the creation of filenames containing any bytes thathave the encoded value of a <newline> character.

Austin Group Defect 1122 is applied, changing the description ofNLSPATH .

Austin Group Defect 1185 is applied, changing the SIGCONT entry in ASYNCHRONOUS EVENTS and adding a SIGWINCHentry.

Austin Group Defect 1251 is applied, clarifying theset command, changing "addr" to "2addr" in the! command synopsis, and adding spaces in some synopsis lines.

Austin Group Defect 1281 is applied, changing the description of thesubstitute command to clarify that itis an error if the substitution fails on every addressed line.

Austin Group Defect 1298 is applied, changing the CONSEQUENCES OF ERRORS section.

Austin Group Defect 1378 is applied, changing the description of theLC_MESSAGES environment variable.

Austin Group Defect 1529 is applied, changing the synopsis of theescape command and adding relatedparagraphs to the APPLICATION USAGE and RATIONALE sections.

Austin Group Defect 1642 is applied, changing the description of theredraw edit option.

Austin Group Defect 1662 is applied, clarifying requirements relating to delimiters in addresses and inscommands.

End of informative text.

 

return to top of page


<<<PreviousHomeNext>>>


[8]ページ先頭

©2009-2026 Movatter.jp