.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
.TH "EX" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" ex 
.SH NAME
ex \- text editor
.SH SYNOPSIS
.LP
\fBex\fP \fB[\fP\fB-rR\fP\fB][\fP\fB-s | -v\fP\fB][\fP\fB-c\fP
\fIcommand\fP\fB][\fP\fB-t\fP \fItagstring\fP\fB][\fP\fB-w\fP \fIsize\fP\fB][\fP\fIfile\fP
\fB\&...\fP\fB]\fP\fB\fP
.SH DESCRIPTION
.LP
The \fIex\fP utility is a line-oriented text editor. There are two
other modes of the editor-open and visual-in which
screen-oriented editing is available. This is described more fully
by the \fIex\fP \fBopen\fP and \fBvisual\fP commands and in
\fIvi\fP .
.LP
This section uses the term \fIedit buffer\fP to describe the current
working text. No specific implementation is implied by
this term. All editing changes are performed on the edit buffer, and
no changes to it shall affect any file until an editor command
writes the file.
.LP
Certain terminals do not have all the capabilities necessary to support
the complete \fIex\fP definition, such as the
full-screen editing commands ( \fIvisual mode\fP or \fIopen mode\fP).
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 implementation
may either accept the commands and produce results on the screen that
are the result of an unsuccessful attempt to meet the
requirements of this volume of IEEE\ Std\ 1003.1-2001 or report an
error describing the terminal-related deficiency.
.SH OPTIONS
.LP
The \fIex\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
.LP
The following options shall be supported:
.TP 7
\fB-c\ \fP \fIcommand\fP
Specify an initial command to be executed in the first edit buffer
loaded from an existing file (see the EXTENDED DESCRIPTION
section). Implementations may support more than a single \fB-c\fP
option. In such implementations, the specified commands shall be
executed in the order specified on the command line.
.TP 7
\fB-r\fP
Recover the named files (see the EXTENDED DESCRIPTION section). Recovery
information for a file shall be saved during an editor
or system crash (for example, when the editor is terminated by a signal
which the editor can catch), or after the use of an
\fIex\fP \fBpreserve\fP command. 
.LP
A \fIcrash\fP in this context is an unexpected failure of the system
or utility that requires restarting the failed system or
utility. A system crash implies that any utilities running at the
time also crash. In the case of an editor or system crash, the
number of changes to the edit buffer (since the most recent \fBpreserve\fP
command) that will be recovered is unspecified.
.LP
If no \fIfile\fP operands are given and the \fB-t\fP option is not
specified, all other options, the \fIEXINIT\fP variable,
and any \fB.exrc\fP files shall be ignored; a list of all recoverable
files available to the invoking user shall be written, and
the editor shall exit normally without further action.
.TP 7
\fB-R\fP
Set \fBreadonly\fP edit option.
.TP 7
\fB-s\fP
Prepare \fIex\fP for batch use by taking the following actions: 
.RS
.IP " *" 3
Suppress writing prompts and informational (but not diagnostic) messages.
.LP
.IP " *" 3
Ignore the value of \fITERM\fP and any implementation default terminal
type and assume the terminal is a type incapable of
supporting open or visual modes; see the \fBvisual\fP command and
the description of \fIvi\fP .
.LP
.IP " *" 3
Suppress the use of the \fIEXINIT\fP environment variable and the
reading of any \fB.exrc\fP file; see the EXTENDED
DESCRIPTION section.
.LP
.IP " *" 3
Suppress autoindentation, ignoring the value of the \fBautoindent\fP
edit option.
.LP
.RE
.TP 7
\fB-t\ \fP \fItagstring\fP
Edit the file containing the specified \fItagstring\fP; see \fIctags\fP
\&. The tags feature
represented by \fB-t\fP \fItagstring\fP and the \fBtag\fP command
is optional. It shall be provided on any system that also
provides a conforming implementation of \fIctags\fP; otherwise, the
use of \fB-t\fP
produces undefined results. On any system, it shall be an error to
specify more than a single \fB-t\fP option.
.TP 7
\fB-v\fP
Begin in visual mode (see \fIvi\fP ).
.TP 7
\fB-w\ \fP \fIsize\fP
Set the value of the \fIwindow\fP editor option to \fIsize\fP.
.sp
.SH OPERANDS
.LP
The following operand shall be supported:
.TP 7
\fIfile\fP
A pathname of a file to be edited.
.sp
.SH STDIN
.LP
The standard input consists of a series of commands and input text,
as described in the EXTENDED DESCRIPTION section. The
implementation may limit each line of standard input to a length of
{LINE_MAX}.
.LP
If the standard input is not a terminal device, it shall be as if
the \fB-s\fP option had been specified.
.LP
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.
.SH INPUT FILES
.LP
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 a
trailing . The editing of other forms of files may optionally
be allowed by \fIex\fP implementations.
.LP
The \fB.exrc\fP files and source files shall be text files consisting
of \fIex\fP commands; see the EXTENDED DESCRIPTION
section.
.LP
By default, the editor shall read lines from the files to be edited
without interpreting any of those lines as any form of
editor command.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIex\fP:
.TP 7
\fICOLUMNS\fP
Override the system-selected horizontal screen size. See the Base
Definitions volume of IEEE\ Std\ 1003.1-2001, Chapter 8, Environment
Variables for valid values and results when it is unset or null.
.TP 7
\fIEXINIT\fP
Determine a list of \fIex\fP commands that are executed on editor
start-up. See the EXTENDED DESCRIPTION section for more
details of the initialization phase.
.TP 7
\fIHOME\fP
Determine a pathname of a directory that shall be searched for an
editor start-up file named \fB.exrc\fP; see the EXTENDED
DESCRIPTION section.
.TP 7
\fILANG\fP
Provide a default value for the internationalization variables that
are unset or null. (See the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
for
the precedence of internationalization variables used to determine
the values of locale categories.)
.TP 7
\fILC_ALL\fP
If set to a non-empty string value, override the values of all the
other internationalization variables.
.TP 7
\fILC_COLLATE\fP
.sp
Determine the locale for the behavior of ranges, equivalence classes,
and multi-character collating elements within regular
expressions.
.TP 7
\fILC_CTYPE\fP
Determine the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files), the
behavior of character classes within regular expressions, the
classification of characters as uppercase or lowercase letters, the
case conversion of letters, and the detection of word
boundaries.
.TP 7
\fILC_MESSAGES\fP
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard
error.
.TP 7
\fILINES\fP
Override the system-selected vertical screen size, used as the number
of lines in a screenful and the vertical screen size in
visual mode. See the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
Chapter 8,
Environment Variables for valid values and results when it is unset
or null.
.TP 7
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP 
.TP 7
\fIPATH\fP
Determine the search path for the shell command specified in the \fIex\fP
editor commands \fB!\fP, \fBshell\fP, \fBread\fP,
and \fBwrite\fP, and the open and visual mode command \fB!\fP; see
the description of command search and execution in \fICommand Search
and Execution\fP .
.TP 7
\fISHELL\fP
Determine the preferred command line interpreter for use as the default
value of the \fBshell\fP edit option.
.TP 7
\fITERM\fP
Determine the name of the terminal type. If this variable is unset
or null, an unspecified default terminal type shall be
used.
.sp
.SH ASYNCHRONOUS EVENTS
.LP
The following term is used in this and following sections to specify
command and asynchronous event actions:
.TP 7
\fIcomplete\ write\fP
.sp
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 the
saving of the edit buffer caused by the user executing the \fIex\fP
\fBpreserve\fP command. Writing the contents of the edit
buffer to a temporary file that will be removed when the editor exits
shall not be considered a complete write.
.sp
.LP
The following actions shall be taken upon receipt of signals:
.TP 7
SIGINT
If the standard input is not a terminal device, \fIex\fP shall not
write the file or return to command or text input mode, and
shall exit with a non-zero exit status. 
.LP
Otherwise, if executing an open or visual text input mode command,
\fIex\fP in receipt of SIGINT shall behave identically to
its receipt of the  character.
.LP
Otherwise:
.RS
.IP " 1." 4
If executing an \fIex\fP text input mode command, all input lines
that have been completely entered shall be resolved into the
edit buffer, and any partially entered line shall be discarded.
.LP
.IP " 2." 4
If there is a currently executing command, it shall be aborted and
a message displayed. Unless otherwise specified by the
\fIex\fP or \fIvi\fP command descriptions, it is unspecified whether
any lines modified by the
executing command appear modified, or as they were before being modified
by the executing command, in the buffer.
.LP
If the currently executing command was a motion command, its associated
command shall be discarded.
.LP
.IP " 3." 4
If in open or visual command mode, the terminal shall be alerted.
.LP
.IP " 4." 4
The editor shall then return to command mode.
.LP
.RE
.TP 7
SIGCONT
The screen shall be refreshed if in open or visual mode.
.TP 7
SIGHUP
If the edit buffer has been modified since the last complete write,
\fIex\fP shall attempt to save the edit buffer so that it
can be recovered later using the \fB-r\fP option or the \fIex\fP \fBrecover\fP
command. The editor shall not write the file or
return to command or text input mode, and shall terminate with a non-zero
exit status.
.TP 7
SIGTERM
Refer to SIGHUP.
.sp
.LP
The action taken for all other signals is unspecified.
.SH STDOUT
.LP
The standard output shall be used only for writing prompts to the
user, for informational messages, and for writing lines from
the file.
.SH STDERR
.LP
The standard error shall be used only for diagnostic messages.
.SH OUTPUT FILES
.LP
The output from \fIex\fP shall be text files.
.SH EXTENDED DESCRIPTION
.LP
Only the \fIex\fP mode of the editor is described in this section.
See \fIvi\fP for additional editing
capabilities available in \fIex\fP.
.LP
When an error occurs, \fIex\fP shall write a message. If the terminal
supports a standout mode (such as inverse video), the
message shall be written in standout mode. If the terminal does not
support a standout mode, and the edit option \fBerrorbells\fP
is set, an alert action shall precede the error message.
.LP
By default, \fIex\fP shall start in command mode, which shall be indicated
by a \fB:\fP prompt; see the \fBprompt\fP command.
Text input mode can be entered by the \fBappend\fP, \fBinsert\fP,
or \fBchange\fP commands; it can be exited (and command mode
re-entered) by typing a period ( \fB'.'\fP ) alone at the beginning
of a line.
.SS Initialization in ex and vi
.LP
The following symbols are used in this and following sections to specify
locations in the edit buffer:
.TP 7
\fIalternate\ and\ current\ pathnames\fP
.sp
Two pathnames, named \fIcurrent\fP and \fIalternate\fP, are maintained
by the editor. Any \fIex\fP commands that take filenames
as arguments shall set them as follows: 
.RS
.IP " 1." 4
If a \fIfile\fP argument is specified to the \fIex\fP \fBedit\fP,
\fBex\fP, or \fBrecover\fP commands, or if an \fIex\fP
\fBtag\fP command replaces the contents of the edit buffer.
.RS
.IP " a." 4
If the command replaces the contents of the edit buffer, the current
pathname shall be set to the \fIfile\fP argument or the
file indicated by the tag, and the alternate pathname shall be set
to the previous value of the current pathname.
.LP
.IP " b." 4
Otherwise, the alternate pathname shall be set to the \fIfile\fP argument.
.LP
.RE
.LP
.IP " 2." 4
If a \fIfile\fP argument is specified to the \fIex\fP \fBnext\fP command:
.RS
.IP " a." 4
If the command replaces the contents of the edit buffer, the current
pathname shall be set to the first \fIfile\fP argument,
and the alternate pathname shall be set to the previous value of the
current pathname.
.LP
.RE
.LP
.IP " 3." 4
If a \fIfile\fP argument is specified to the \fIex\fP \fBfile\fP command,
the current pathname shall be set to the
\fIfile\fP argument, and the alternate pathname shall be set to the
previous value of the current pathname.
.LP
.IP " 4." 4
If a \fIfile\fP argument is specified to the \fIex\fP \fBread\fP and
\fBwrite\fP commands (that is, when reading or writing
a file, and not to the program named by the \fBshell\fP edit option),
or a \fIfile\fP argument is specified to the \fIex\fP
\fBxit\fP command:
.RS
.IP " a." 4
If the current pathname has no value, the current pathname shall be
set to the \fIfile\fP argument.
.LP
.IP " b." 4
Otherwise, the alternate pathname shall be set to the \fIfile\fP argument.
.LP
.RE
.LP
.RE
.LP
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.
.TP 7
\fIcurrent\ line\fP
.sp
The line of the edit buffer referenced by the cursor. Each command
description specifies the current line after the command has
been executed, as the \fIcurrent line value\fP. When the edit buffer
contains no lines, the current line shall be zero; see Addressing
in ex .
.TP 7
\fIcurrent\ column\fP
.sp
The current display line column occupied by the cursor. (The columns
shall be numbered beginning at 1.) Each command description
specifies the current column after the command has been executed,
as the \fIcurrent column\fP value. This column is an
\fIideal\fP column that is remembered over the lifetime of the editor.
The actual display line column upon which the cursor rests
may be different from the current column; see the cursor positioning
discussion in \fICommand
Descriptions in vi\fP .
.TP 7
\fIset\ to\ non-\fP
.sp
A description for a current column value, meaning that the current
column shall be set to the last display line column on which is
displayed any part of the first non-  of the line. If the line
has no non-  non- s, the
current column shall be set to the last display line column on which
is displayed any part of the last non-  in the
line. If the line is empty, the current column shall be set to column
position 1.
.sp
.LP
The length of lines in the edit buffer may be limited to {LINE_MAX}
bytes. In open and visual mode, the length of lines in the
edit buffer may be limited to the number of characters that will fit
in the display. If either limit is exceeded during editing, an
error message shall be written. If either limit is exceeded by a line
read in from a file, an error message shall be written and
the edit session may be terminated.
.LP
If the editor stops running due to any reason other than a user command,
and the edit buffer has been modified since the last
complete write, it shall be equivalent to a SIGHUP asynchronous event.
If the system crashes, it shall be equivalent to a SIGHUP
asynchronous event.
.LP
During initialization (before the first file is copied into the edit
buffer or any user commands from the terminal are
processed) the following shall occur:
.IP " 1." 4
If the environment variable \fIEXINIT\fP is set, the editor shall
execute the \fIex\fP commands contained in that
variable.
.LP
.IP " 2." 4
If the \fIEXINIT\fP variable is not set, and all of the following
are true:
.RS
.IP " a." 4
The \fIHOME\fP environment variable is not null and not empty.
.LP
.IP " b." 4
The file \fB.exrc\fP in the directory referred to by the \fIHOME\fP
environment variable:
.RS
.IP " 1." 4
Exists
.LP
.IP " 2." 4
Is owned by the same user ID as the real user ID of the process or
the process has appropriate privileges
.LP
.IP " 3." 4
Is not writable by anyone other than the owner
.LP
.RE
.LP
.RE
.LP
the editor shall execute the \fIex\fP commands contained in that file.
.LP
.IP " 3." 4
If and only if all of the following are true:
.RS
.IP " a." 4
The current directory is not referred to by the \fIHOME\fP environment
variable.
.LP
.IP " b." 4
A command in the \fIEXINIT\fP environment variable or a command in
the \fB.exrc\fP file in the directory referred to by the
\fIHOME\fP environment variable sets the editor option \fBexrc\fP.
.LP
.IP " c." 4
The \fB.exrc\fP file in the current directory:
.RS
.IP " 1." 4
Exists
.LP
.IP " 2." 4
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
.LP
.IP " 3." 4
Is not writable by anyone other than the owner
.LP
.RE
.LP
.RE
.LP
the editor shall attempt to execute the \fIex\fP commands contained
in that file.
.LP
.LP
Lines in any \fB.exrc\fP file that are blank lines shall be ignored.
If any \fB.exrc\fP file exists, but is not read for
ownership or permission reasons, it shall be an error.
.LP
After the \fIEXINIT\fP variable and any \fB.exrc\fP files are processed,
the first file specified by the user shall be edited,
as follows:
.IP " 1." 4
If the user specified the \fB-t\fP option, the effect shall be as
if the \fIex\fP \fBtag\fP command was entered with the
specified argument, with the exception that if tag processing does
not result in a file to edit, the effect shall be as described
in step 3. below.
.LP
.IP " 2." 4
Otherwise, if the user specified any command line \fIfile\fP arguments,
the effect shall be as if the \fIex\fP \fBedit\fP
command was entered with the first of those arguments as its \fIfile\fP
argument.
.LP
.IP " 3." 4
Otherwise, the effect shall be as if the \fIex\fP \fBedit\fP command
was entered with a nonexistent filename as its
\fIfile\fP argument. It is unspecified whether this action shall set
the current pathname. In an implementation where this action
does not set the current pathname, any editor command using the current
pathname shall fail until an editor command sets the
current pathname.
.LP
.LP
If the \fB-r\fP option was specified, the first time a file in the
initial argument list or a file specified by the \fB-t\fP
option is edited, if recovery information has previously been saved
about it, that information shall be recovered and the editor
shall behave as if the contents of the edit buffer have already been
modified. If there are multiple instances of the file to be
recovered, the one most recently saved shall be recovered, and an
informational message that there are previous versions of the
file that can be recovered shall be written. If no recovery information
about a file is available, an informational message to this
effect shall be written, and the edit shall proceed as usual.
.LP
If the \fB-c\fP option was specified, the first time a file that already
exists (including a file that might not exist but for
which recovery information is available, when the \fB-r\fP option
is specified) replaces or initializes the contents of the edit
buffer, the current line shall be set to the last line of the edit
buffer, the current column shall be set to non- ,
and the \fIex\fP commands specified with the \fB-c\fP option shall
be executed. In this case, the current line and current column
shall not be set as described for the command associated with the
replacement or initialization of the edit buffer contents.
However, if the \fB-t\fP option or a \fBtag\fP command is associated
with this action, the \fB-c\fP option commands shall be
executed and then the movement to the tag shall be performed.
.LP
The current argument list shall initially be set to the filenames
specified by the user on the command line. If no filenames are
specified by the user, the current argument list shall be empty. If
the \fB-t\fP option was specified, it is unspecified whether
any filename resulting from tag processing shall be prepended to the
current argument list. In the case where the filename is added
as a prefix to the current argument list, the current argument list
reference shall be set to that filename. In the case where the
filename is not added as a prefix to the current argument list, the
current argument list reference shall logically be located
before the first of the filenames specified on the command line (for
example, a subsequent \fIex\fP \fBnext\fP command shall edit
the first filename from the command line). If the \fB-t\fP option
was not specified, the current argument list reference shall be
to the first of the filenames on the command line.
.SS Addressing in ex
.LP
Addressing in \fIex\fP relates to the current line and the current
column; the address of a line is its 1-based line number,
the address of a column is its 1-based count from the beginning of
the line. Generally, the current line is the last line affected
by a command. The current line number is the address of the current
line. In each command description, the effect of the command on
the current line number and the current column is described.
.LP
Addresses are constructed as follows:
.IP " 1." 4
The character \fB'.'\fP (period) shall address the current line.
.LP
.IP " 2." 4
The character \fB'$'\fP shall address the last line of the edit buffer.
.LP
.IP " 3." 4
The positive decimal number \fIn\fP shall address the \fIn\fPth line
of the edit buffer.
.LP
.IP " 4." 4
The address \fB"'x"\fP refers to the line marked with the mark name
character \fB'x'\fP , which shall be a lowercase
letter from the portable character set or one of the characters \fB'`'\fP
or \fB'"\fP . It shall be an error if the line
that was marked is not currently present in the edit buffer or the
mark has not been set. Lines can be marked with the \fIex\fP
\fBmark\fP or \fBk\fP commands, or the \fIvi\fP \fBm\fP command.
.LP
.IP " 5." 4
A regular expression enclosed by slashes ( \fB'/'\fP ) shall address
the first line found by searching forwards from the line
following the current line toward the end of the edit buffer and stopping
at the first line for which the line excluding the
terminating  matches the regular expression. As stated in
Regular Expressions in ex ,
an address consisting of a null regular expression delimited by slashes
\fB"//"\fP shall address the next line for which the
line excluding the terminating  matches the last regular
expression encountered. In addition, the second slash can
be omitted at the end of a command line. If the \fBwrapscan\fP edit
option is set, the search shall wrap around to the beginning
of the edit buffer and continue up to and including the current line,
so that the entire edit buffer is searched. Within the
regular expression, the sequence \fB"\\/"\fP shall represent a literal
slash instead of the regular expression delimiter.
.LP
.IP " 6." 4
A regular expression enclosed in question marks ( \fB'?'\fP ) shall
address the first line found by searching backwards from
the line preceding the current line toward the beginning of the edit
buffer and stopping at the first line for which the line
excluding the terminating  matches the regular expression.
An address consisting of a null regular expression
delimited by question marks \fB"??"\fP shall address the previous
line for which the line excluding the terminating
 matches the last regular expression encountered. In addition,
the second question mark can be omitted at the end of
a command line. If the \fBwrapscan\fP edit option is set, the search
shall wrap around from the beginning of the edit buffer to
the end of the edit buffer and continue up to and including the current
line, so that the entire edit buffer is searched. Within
the regular expression, the sequence \fB"\\?"\fP shall represent a
literal question mark instead of the RE delimiter.
.LP
.IP " 7." 4
A plus sign ( \fB'+'\fP ) or a minus sign ( \fB'-'\fP ) followed by
a decimal number shall address the current line plus
or minus the number. A \fB'+'\fP or \fB'-'\fP not followed by a decimal
number shall address the current line plus or minus
1.
.LP
.LP
Addresses can be followed by zero or more address offsets, optionally
-separated. Address offsets are constructed
as follows:
.IP " 1." 4
A \fB'+'\fP or \fB'-'\fP immediately followed by a decimal number
shall add (subtract) the indicated number of lines to
(from) the address. A \fB'+'\fP or \fB'-'\fP not followed by a decimal
number shall add (subtract) 1 to (from) the
address.
.LP
.IP " 2." 4
A decimal number shall add the indicated number of lines to the address.
.LP
.LP
It shall not be an error for an intermediate address value to be less
than zero or greater than the last line in the edit
buffer. It shall be an error for the final address value to be less
than zero or greater than the last line in the edit buffer.
.LP
Commands take zero, one, or two addresses; see the descriptions of
\fI1addr\fP and \fI2addr\fP in Command Descriptions in ex . If more
than the required number of addresses are provided to a command that
requires zero addresses, it shall be an error. Otherwise, if more
than the required number of addresses are provided to a command,
the addresses specified first shall be evaluated and then discarded
until the maximum number of valid addresses remain.
.LP
Addresses shall be separated from each other by a comma ( \fB','\fP
) or a semicolon ( \fB';'\fP ). If no address is
specified before or after a comma or semicolon separator, it shall
be as if the address of the current line was specified before or
after the separator. In the case of a semicolon separator, the current
line ( \fB'.'\fP ) shall be set to the first address, and
only then will the next address be calculated. This feature can be
used to determine the starting line for forwards and backwards
searches (see rules 5. and 6.).
.LP
A percent sign ( \fB'%'\fP ) shall be equivalent to entering the two
addresses \fB"1,$"\fP .
.LP
Any delimiting s between addresses, address separators, or
address offsets shall be discarded.
.SS Command Line Parsing in ex
.LP
The following symbol is used in this and following sections to describe
parsing behavior:
.TP 7
\fIescape\fP
If a character is referred to as "backslash-escaped" or " -V-escaped,"
it shall mean that the character
acquired or lost a special meaning by virtue of being preceded, respectively,
by a backslash or -V character. Unless
otherwise specified, the escaping character shall be discarded at
that time and shall not be further considered for any
purpose.
.sp
.LP
Command-line parsing shall be done in the following steps. For each
step, characters already evaluated shall be ignored; that
is, the phrase "leading character" refers to the next character that
has not yet been evaluated.
.IP " 1." 4
Leading colon characters shall be skipped.
.LP
.IP " 2." 4
Leading s shall be skipped.
.LP
.IP " 3." 4
If the leading character is a double-quote character, the characters
up to and including the next non-backslash-escaped
 shall be discarded, and any subsequent characters shall
be parsed as a separate command.
.LP
.IP " 4." 4
Leading characters that can be interpreted as addresses shall be evaluated;
see Addressing in ex
\&.
.LP
.IP " 5." 4
Leading s shall be skipped.
.LP
.IP " 6." 4
If the next character is a vertical-line character or a :
.RS
.IP " a." 4
If the next character is a :
.RS
.IP " 1." 4
If \fIex\fP is in open or visual mode, the current line shall be set
to the last address specified, if any.
.LP
.IP " 2." 4
Otherwise, if the last command was terminated by a vertical-line character,
no action shall be taken; for example, the command
\fB"||"\fP shall execute two implied commands, not three.
.LP
.IP " 3." 4
Otherwise, step 6.b. shall apply.
.LP
.RE
.LP
.IP " b." 4
Otherwise, the implied command shall be the \fBprint\fP command. The
last \fB#\fP, \fBp\fP, and \fBl\fP flags specified to
any \fIex\fP command shall be remembered and shall apply to this implied
command. Executing the \fIex\fP \fBnumber\fP,
\fBprint\fP, or \fBlist\fP command shall set the remembered flags
to \fB#\fP, nothing, and \fBl\fP, respectively, plus any
other flags specified for that execution of the \fBnumber\fP, \fBprint\fP,
or \fBlist\fP command.
.LP
If \fIex\fP is not currently performing a \fBglobal\fP or \fBv\fP
command, and no address or count is specified, the current
line shall be incremented by 1 before the command is executed. If
incrementing the current line would result in an address past the
last line in the edit buffer, the command shall fail, and the increment
shall not happen.
.LP
.IP " c." 4
The  or vertical-line character shall be discarded and any
subsequent characters shall be parsed as a separate
command.
.LP
.RE
.LP
.IP " 7." 4
The command name shall be comprised of the next character (if the
character is not alphabetic), or the next character and any
subsequent alphabetic characters (if the character is alphabetic),
with the following exceptions:
.RS
.IP " a." 4
Commands that consist of any prefix of the characters in the command
name \fBdelete\fP, followed immediately by any of the
characters \fB'l'\fP , \fB'p'\fP , \fB'+'\fP , \fB'-'\fP , or \fB'#'\fP
shall be interpreted as a \fBdelete\fP
command, followed by a , followed by the characters that were
not part of the prefix of the \fBdelete\fP command. The
maximum number of characters shall be matched to the command name
\fBdelete\fP; for example, \fB"del"\fP shall not be treated
as \fB"de"\fP followed by the flag \fBl\fP.
.LP
.IP " b." 4
Commands that consist of the character \fB'k'\fP , followed by a character
that can be used as the name of a mark, shall be
equivalent to the mark command followed by a , followed by
the character that followed the \fB'k'\fP .
.LP
.IP " c." 4
Commands that consist of the character \fB's'\fP , followed by characters
that could be interpreted as valid options to the
\fBs\fP command, shall be the equivalent of the \fBs\fP command, without
any pattern or replacement values, followed by a
, followed by the characters after the \fB's'\fP .
.LP
.RE
.LP
.IP " 8." 4
The command name shall be matched against the possible command names,
and a command name that contains a prefix matching the
characters specified by the user shall be the executed command. In
the case of commands where the characters specified by the user
could be ambiguous, the executed command shall be as follows:
.TS C
center; l l l l l l l l.
\fBa\fP	\fBappend\fP	n	\fBnext\fP	\fBt\fP	t	\fB\ \fP	\fB\ \fP
\fBc\fP	\fBchange\fP	p	\fBprint\fP	\fBu\fP	undo	\fB\ \fP	\fB\ \fP
\fBch\fP	\fBchange\fP	pr	\fBprint\fP	\fBun\fP	undo	\fB\ \fP	\fB\ \fP
\fBe\fP	\fBedit\fP	r	\fBread\fP	\fBv\fP	v	\fB\ \fP	\fB\ \fP
\fBm\fP	\fBmove\fP	re	\fBread\fP	\fBw\fP	write	\fB\ \fP	\fB\ \fP
\fBma\fP	\fBmark\fP	s	\fBs\fP	\fB\ \fP	\ 	\fB\ \fP	\fB\ \fP
.TE
.LP
Implementation extensions with names causing similar ambiguities shall
not be checked for a match until all possible matches for
commands specified by IEEE\ Std\ 1003.1-2001 have been checked.
.LP
.IP " 9." 4
If the command is a \fB!\fP command, or if the command is a \fBread\fP
command followed by zero or more s and a
\fB!\fP, or if the command is a \fBwrite\fP command followed by one
or more s and a \fB!\fP, the rest of the
command shall include all characters up to a non-backslash-escaped
. The  shall be discarded and any
subsequent characters shall be parsed as a separate \fIex\fP command.
.LP
.IP "10." 4
Otherwise, if the command is an \fBedit\fP, \fBex\fP, or \fBnext\fP
command, or a \fBvisual\fP command while in open or
visual mode, the next part of the command shall be parsed as follows:
.RS
.IP " a." 4
Any \fB'!'\fP character immediately following the command shall be
skipped and be part of the command.
.LP
.IP " b." 4
Any leading s shall be skipped and be part of the command.
.LP
.IP " c." 4
If the next character is a \fB'+'\fP , characters up to the first
non-backslash-escaped  or
non-backslash-escaped  shall be skipped and be part of the
command.
.LP
.IP " d." 4
The rest of the command shall be determined by the steps specified
in paragraph 12.
.LP
.RE
.LP
.IP "11." 4
Otherwise, if the command is a \fBglobal\fP, \fBopen\fP, \fBs\fP,
or \fBv\fP command, the next part of the command shall be
parsed as follows:
.RS
.IP " a." 4
Any leading s shall be skipped and be part of the command.
.LP
.IP " b." 4
If the next character is not an alphanumeric, double-quote, ,
backslash, or vertical-line character:
.RS
.IP " 1." 4
The next character shall be used as a command delimiter.
.LP
.IP " 2." 4
If the command is a \fBglobal\fP, \fBopen\fP, or \fBv\fP command,
characters up to the first non-backslash-escaped
, or first non-backslash-escaped delimiter character, shall
be skipped and be part of the command.
.LP
.IP " 3." 4
If the command is an \fBs\fP command, characters up to the first non-backslash-escaped
, or second
non-backslash-escaped delimiter character, shall be skipped and be
part of the command.
.LP
.RE
.LP
.IP " c." 4
If the command is a \fBglobal\fP or \fBv\fP command, characters up
to the first non-backslash-escaped  shall be
skipped and be part of the command.
.LP
.IP " d." 4
Otherwise, the rest of the command shall be determined by the steps
specified in paragraph 12.
.LP
.RE
.LP
.IP "12." 4
Otherwise:
.RS
.IP " a." 4
If the command was a \fBmap\fP, \fBunmap\fP, \fBabbreviate\fP, or
\fBunabbreviate\fP command, characters up to the first
non- -V-escaped , vertical-line, or double-quote
character shall be skipped and be part of the
command.
.LP
.IP " b." 4
Otherwise, characters up to the first non-backslash-escaped ,
vertical-line, or double-quote character shall be
skipped and be part of the command.
.LP
.IP " c." 4
If the command was an \fBappend\fP, \fBchange\fP, or \fBinsert\fP
command, and the step 12.b. ended at a vertical-line
character, any subsequent characters, up to the next non-backslash-escaped
 shall be used as input text to the
command.
.LP
.IP " d." 4
If the command was ended by a double-quote character, all subsequent
characters, up to the next non-backslash-escaped
, shall be discarded.
.LP
.IP " e." 4
The terminating  or vertical-line character shall be discarded
and any subsequent characters shall be parsed as a
separate \fIex\fP command.
.LP
.RE
.LP
.LP
Command arguments shall be parsed as described by the Synopsis and
Description of each individual \fIex\fP command. This
parsing shall not be -sensitive, except for the \fB!\fP argument,
which must follow the command name without
intervening s, and where it would otherwise be ambiguous. For
example, \fIcount\fP and \fIflag\fP arguments need not
be -separated because \fB"d22p"\fP is not ambiguous, but \fIfile\fP
arguments to the \fIex\fP \fBnext\fP command
must be separated by one or more s. Any  in command
arguments for the \fBabbreviate\fP,
\fBunabbreviate\fP, \fBmap\fP, and \fBunmap\fP commands can be -V-escaped,
in which case the  shall
not be used as an argument delimiter. Any  in the command argument
for any other command can be backslash-escaped, in
which case that  shall not be used as an argument delimiter.
.LP
Within command arguments for the \fBabbreviate\fP, \fBunabbreviate\fP,
\fBmap\fP, and \fBunmap\fP commands, any character
can be -V-escaped. All such escaped characters shall be treated
literally and shall have no special meaning. Within
command arguments for all other \fIex\fP commands that are not regular
expressions or replacement strings, any character that
would otherwise have a special meaning can be backslash-escaped. Escaped
characters shall be treated literally, without special
meaning as shell expansion characters or \fB'!'\fP , \fB'%'\fP , and
\fB'#'\fP expansion characters. See Regular Expressions in ex and
Replacement Strings in ex for descriptions of
command arguments that are regular expressions or replacement strings.
.LP
Non-backslash-escaped \fB'%'\fP characters appearing in \fIfile\fP
arguments to any \fIex\fP command shall be replaced by
the current pathname; unescaped \fB'#'\fP characters shall be replaced
by the alternate pathname. It shall be an error if
\fB'%'\fP or \fB'#'\fP characters appear unescaped in an argument
and their corresponding values are not set.
.LP
Non-backslash-escaped \fB'!'\fP characters in the arguments to either
the \fIex\fP \fB!\fP command or the open and visual
mode \fB!\fP command, or in the arguments to the \fIex\fP \fBread\fP
command, where the first non-  after the
command name is a \fB'!'\fP character, or in the arguments to the
\fIex\fP \fBwrite\fP command where the command name is
followed by one or more s and the first non-  after
the command name is a \fB'!'\fP character, shall
be replaced with the arguments to the last of those three commands
as they appeared after all unescaped \fB'%'\fP , \fB'#'\fP
, and \fB'!'\fP characters were replaced. It shall be an error if
\fB'!'\fP characters appear unescaped in one of these
commands and there has been no previous execution of one of these
commands.
.LP
If an error occurs during the parsing or execution of an \fIex\fP
command:
.IP " *" 3
An informational message to this effect shall be written. Execution
of the \fIex\fP command shall stop, and the cursor (for
example, the current line and column) shall not be further modified.
.LP
.IP " *" 3
If the \fIex\fP command resulted from a map expansion, all characters
from that map expansion shall be discarded, except as
otherwise specified by the \fBmap\fP command.
.LP
.IP " *" 3
Otherwise, if the \fIex\fP command resulted from the processing of
an \fIEXINIT\fP environment variable, a \fB.exrc\fP file,
a \fB:source\fP command, a \fB-c\fP option, or a \fB+\fP \fIcommand\fP
specified to an \fIex\fP \fBedit\fP, \fBex\fP,
\fBnext\fP, or \fBvisual\fP command, no further commands from the
source of the commands shall be executed.
.LP
.IP " *" 3
Otherwise, if the \fIex\fP command resulted from the execution of
a buffer or a \fBglobal\fP or \fBv\fP command, no further
commands caused by the execution of the buffer or the \fBglobal\fP
or \fBv\fP command shall be executed.
.LP
.IP " *" 3
Otherwise, if the \fIex\fP command was not terminated by a ,
all characters up to and including the next
non-backslash-escaped  shall be discarded.
.LP
.SS Input Editing in ex
.LP
The following symbol is used in this and the following sections to
specify command actions:
.TP 7
\fIword\fP
In the POSIX locale, a word consists of a maximal sequence of letters,
digits, and underscores, delimited at both ends by
characters other than letters, digits, or underscores, or by the beginning
or end of a line or the edit buffer.
.sp
.LP
When accepting input characters from the user, in either \fIex\fP
command mode or \fIex\fP text input mode, \fIex\fP shall
enable canonical mode input processing, as defined in the System Interfaces
volume of IEEE\ Std\ 1003.1-2001.
.LP
If in \fIex\fP text input mode:
.IP " 1." 4
If the \fBnumber\fP edit option is set, \fIex\fP shall prompt for
input using the line number that would be assigned to the
line if it is entered, in the format specified for the \fIex\fP \fBnumber\fP
command.
.LP
.IP " 2." 4
If the \fBautoindent\fP edit option is set, \fIex\fP shall prompt
for input using \fBautoindent\fP characters, as described
by the \fBautoindent\fP edit option. \fBautoindent\fP characters shall
follow the line number, if any.
.LP
.LP
If in \fIex\fP command mode:
.IP " 1." 4
If the \fBprompt\fP edit option is set, input shall be prompted for
using a single \fB':'\fP character; otherwise, there
shall be no prompt.
.LP
.LP
The input characters in the following sections shall have the following
effects on the input line.
.SS Scroll
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBeof
\fP
.fi
.RE
.sp
.LP
See the description of the \fIstty\fP \fIeof\fP character in \fIstty\fP
\&.
.LP
If in \fIex\fP command mode:
If the \fIeof\fP character is the first character entered on the line,
the line shall be evaluated as if it contained
two characters: a -D and a . 
.LP
Otherwise, the \fIeof\fP character shall have no special meaning.
.sp
.LP
If in \fIex\fP text input mode:
If the cursor follows an \fBautoindent\fP character, the \fBautoindent\fP
characters in the line shall be modified so
that a part of the next text input character will be displayed on
the first column in the line after the previous \fBshiftwidth\fP
edit option column boundary, and the user shall be prompted again
for input for the same line. 
.LP
Otherwise, if the cursor follows a \fB'0'\fP , which follows an \fBautoindent\fP
character, and the \fB'0'\fP was the
previous text input character, the \fB'0'\fP and all \fBautoindent\fP
characters in the line shall be discarded, and the user
shall be prompted again for input for the same line.
.LP
Otherwise, if the cursor follows a \fB'^'\fP , which follows an \fBautoindent\fP
character, and the \fB'^'\fP was the
previous text input character, the \fB'^'\fP and all \fBautoindent\fP
characters in the line shall be discarded, and the user
shall be prompted again for input for the same line. In addition,
the \fBautoindent\fP level for the next input line shall be
derived from the same line from which the \fBautoindent\fP level for
the current input line was derived.
.LP
Otherwise, if there are no \fBautoindent\fP or text input characters
in the line, the \fIeof\fP character shall be
discarded.
.LP
Otherwise, the \fIeof\fP character shall have no special meaning.
.SS 
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB
.sp

-J
\fP
.fi
.RE
.sp
.LP
If in \fIex\fP command mode:
Cause the command line to be parsed; -J shall be mapped to
the  for this
purpose.
.LP
If in \fIex\fP text input mode:
Terminate the current line. If there are no characters other than
\fBautoindent\fP characters on the line, all
characters on the line shall be discarded. 
.LP
Prompt for text input on a new line after the current line. If the
\fBautoindent\fP edit option is set, an appropriate number
of \fBautoindent\fP characters shall be added as a prefix to the line
as described by the \fIex\fP \fBautoindent\fP edit
option.
.SS 
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB
\fP
.fi
.RE
.sp
.LP
Allow the entry of a subsequent  or -J as a literal
character, removing any special meaning that
it may have to the editor during text input mode. The backslash character
shall be retained and evaluated when the command line is
parsed, or retained and included when the input text becomes part
of the edit buffer.
.SS -V
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB-V
\fP
.fi
.RE
.sp
.LP
Allow the entry of any subsequent character as a literal character,
removing any special meaning that it may have to the editor
during text input mode. The -V character shall be discarded
before the command line is parsed or the input text
becomes part of the edit buffer.
.LP
If the "literal next" functionality is performed by the underlying
system, it is implementation-defined whether a character
other than -V performs this function.
.SS -W
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB-W
\fP
.fi
.RE
.sp
.LP
Discard the -W, and the word previous to it in the input
line, including any s following the word
and preceding the -W. If the "word erase" functionality is
performed by the underlying system, it is
implementation-defined whether a character other than -W
performs this function.
.SS Command Descriptions in ex
.LP
The following symbols are used in this section to represent command
modifiers. Some of these modifiers can be omitted, in which
case the specified defaults shall be used.
.TP 7
\fI1addr\fP
A single line address, given in any of the forms described in Addressing
in ex ; the default
shall be the current line ( \fB'.'\fP ), unless otherwise specified.
.LP
If the line address is zero, it shall be an error, unless otherwise
specified in the following command descriptions.
.LP
If the edit buffer is empty, and the address is specified with a command
other than \fB=\fP, \fBappend\fP, \fBinsert\fP,
\fBopen\fP, \fBput\fP, \fBread\fP, or \fBvisual\fP, or the address
is not zero, it shall be an error.
.TP 7
\fI2addr\fP
Two addresses specifying an inclusive range of lines. If no addresses
are specified, the default for \fI2addr\fP shall be the
current line only ( \fB".,."\fP ), unless otherwise specified in the
following command descriptions. If one address is
specified, \fI2addr\fP shall specify that line only, unless otherwise
specified in the following command descriptions. 
.LP
It shall be an error if the first address is greater than the second
address.
.LP
If the edit buffer is empty, and the two addresses are specified with
a command other than the \fB!\fP, \fBwrite\fP,
\fBwq\fP, or \fBxit\fP commands, or either address is not zero, it
shall be an error.
.TP 7
\fIcount\fP
A positive decimal number. If \fIcount\fP is specified, it shall be
equivalent to specifying an additional address to the
command, unless otherwise specified by the following command descriptions.
The additional address shall be equal to the last
address specified to the command (either explicitly or by default)
plus \fIcount\fP-1. 
.LP
If this would result in an address greater than the last line of the
edit buffer, it shall be corrected to equal the last line
of the edit buffer.
.TP 7
\fIflags\fP
One or more of the characters \fB'+'\fP , \fB'-'\fP , \fB'#'\fP ,
\fB'p'\fP , or \fB'l'\fP (ell). The flag
characters can be -separated, and in any order or combination.
The characters \fB'#'\fP , \fB'p'\fP , and
\fB'l'\fP shall cause lines to be written in the format specified
by the \fBprint\fP command with the specified \fIflags\fP. 
.LP
The lines to be written are as follows:
.RS
.IP " 1." 4
All edit buffer lines written during the execution of the \fIex\fP
\fB&\fP, \fB~\fP, \fBlist\fP, \fBnumber\fP,
\fBopen\fP, \fBprint\fP, \fBs\fP, \fBvisual\fP, and \fBz\fP commands
shall be written as specified by \fIflags\fP.
.LP
.IP " 2." 4
After the completion of an \fIex\fP command with a flag as an argument,
the current line shall be written as specified by
\fIflags\fP, unless the current line was the last line written by
the command.
.LP
.RE
.LP
The characters \fB'+'\fP and \fB'-'\fP cause the value of the current
line after the execution of the \fIex\fP command to
be adjusted by the offset address as described in Addressing in ex
\&. This adjustment shall occur
before the current line is written as described in 2. above.
.LP
The default for \fIflags\fP shall be none.
.TP 7
\fIbuffer\fP
One of a number of named areas for holding text. The named buffers
are specified by the alphanumeric characters of the POSIX
locale. There shall also be one "unnamed" buffer. When no buffer is
specified for editor commands that use a buffer, the unnamed
buffer shall be used. Commands that store text into buffers shall
store the text as it was before the command took effect, and
shall store text occurring earlier in the file before text occurring
later in the file, regardless of how the text region was
specified. Commands that store text into buffers shall store the text
into the unnamed buffer as well as any specified buffer. 
.LP
In \fIex\fP commands, buffer names are specified as the name by itself.
In open or visual mode commands the name is preceded by
a double quote ( \fB' )'\fP character.
.LP
If the specified buffer name is an uppercase character, and the buffer
contents are to be modified, the buffer shall be appended
to rather than being overwritten. If the buffer is not being modified,
specifying the buffer name in lowercase and uppercase shall
have identical results.
.LP
There shall also be buffers named by the numbers 1 through 9. In open
and visual mode, if a region of text including characters
from more than a single line is being modified by the \fIvi\fP \fBc\fP
or \fBd\fP commands,
the motion character associated with the \fBc\fP or \fBd\fP commands
specifies that the buffer text shall be in line mode, or the
commands \fB%\fP, \fB`\fP, \fB/\fP, \fB?\fP, \fB(\fP, \fB)\fP, \fBN\fP,
\fBn\fP, \fB{\fP, or \fB}\fP are used to define a
region of text for the \fBc\fP or \fBd\fP commands, the contents of
buffers 1 through 8 shall be moved into the buffer named by
the next numerically greater value, the contents of buffer 9 shall
be discarded, and the region of text shall be copied into buffer
1. This shall be in addition to copying the text into a user-specified
buffer or unnamed buffer, or both. Numeric buffers can be
specified as a source buffer for open and visual mode commands; however,
specifying a numeric buffer as the write target of an open
or visual mode command shall have unspecified results.
.LP
The text of each buffer shall have the characteristic of being in
either line or character mode. Appending text to a non-empty
buffer shall set the mode to match the characteristic of the text
being appended. Appending text to a buffer shall cause the
creation of at least one additional line in the buffer. All text stored
into buffers by \fIex\fP commands shall be in line mode.
The \fIex\fP commands that use buffers as the source of text specify
individually how buffers of different modes are handled. Each
open or visual mode command that uses buffers for any purpose specifies
individually the mode of the text stored into the buffer
and how buffers of different modes are handled.
.TP 7
\fIfile\fP
Command text used to derive a pathname. The default shall be the current
pathname, as defined previously, in which case, if no
current pathname has yet been established it shall be an error, except
where specifically noted in the individual command
descriptions that follow. If the command text contains any of the
characters \fB'~'\fP , \fB'{'\fP , \fB'['\fP ,
\fB'*'\fP , \fB'?'\fP , \fB'$'\fP , \fB'`'\fP , \fB'"\fP , \fB' ,'\fP
and \fB'\\'\fP , it shall be subjected
to the process of "shell expansions", as described below; if more
than a single pathname results and the command expects only
one, it shall be an error. 
.LP
The process of shell expansions in the editor shall be done as follows.
The \fIex\fP utility shall pass two arguments to the
program named by the shell edit option; the first shall be \fB-c\fP,
and the second shall be the string \fB"echo"\fP and the
command text as a single argument. The standard output and standard
error of that command shall replace the command text.
.TP 7
\fB!\fP
A character that can be appended to the command name to modify its
operation, as detailed in the individual command
descriptions. With the exception of the \fIex\fP \fBread\fP, \fBwrite\fP,
and \fB!\fP commands, the \fB'!'\fP character
shall only act as a modifier if there are no s between it and
the command name.
.TP 7
\fIremembered\ search\ direction\fP
.sp
The \fIvi\fP commands \fBN\fP and \fBn\fP begin searching in a forwards
or backwards
direction in the edit buffer based on a remembered search direction,
which is initially unset, and is set by the \fIex\fP
\fBglobal\fP, \fBv\fP, \fBs\fP, and \fBtag\fP commands, and the \fIvi\fP
\fB/\fP and
\fB?\fP commands.
.sp
.SS Abbreviate
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBab\fP\fB[\fP\fIbreviate\fP\fB][\fP\fIlhs rhs\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIlhs\fP and \fIrhs\fP are not specified, write the current list
of abbreviations and do nothing more.
.LP
Implementations may restrict the set of characters accepted in \fIlhs\fP
or \fIrh\fP, except that printable characters and
s shall not be restricted. Additional restrictions shall be
implementation-defined.
.LP
In both \fIlhs\fP and \fIrhs\fP, any character may be escaped with
a -V, in which case the character shall not
be used to delimit \fIlhs\fP from \fIrhs\fP, and the escaping -V
shall be discarded.
.LP
In open and visual text input mode, if a non-word or  character
that is not escaped by a -V character
is entered after a word character, a check shall be made for a set
of characters matching \fIlhs\fP, in the text input entered
during this command. If it is found, the effect shall be as if \fIrhs\fP
was entered instead of \fIlhs\fP.
.LP
The set of characters that are checked is defined as follows:
.IP " 1." 4
If there are no characters inserted before the word and non-word or
 characters that triggered the check, the set of
characters shall consist of the word character.
.LP
.IP " 2." 4
If the character inserted before the word and non-word or  characters
that triggered the check is a word character,
the set of characters shall consist of the characters inserted immediately
before the triggering characters that are word
characters, plus the triggering word character.
.LP
.IP " 3." 4
If the character inserted before the word and non-word or  characters
that triggered the check is not a word
character, the set of characters shall consist of the characters that
were inserted before the triggering characters that are
neither s nor word characters, plus the triggering word character.
.LP
.LP
It is unspecified whether the \fIlhs\fP argument entered for the \fIex\fP
\fBabbreviate\fP and \fBunabbreviate\fP commands
is replaced in this fashion. Regardless of whether or not the replacement
occurs, the effect of the command shall be as if the
replacement had not occurred.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Append
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBa\fP\fB[\fP\fBppend\fP\fB][\fP\fB!\fP\fB]\fP
.fi
.RE
.sp
.LP
Enter \fIex\fP text input mode; the input text shall be placed after
the specified line. If line zero is specified, the text
shall be placed at the beginning of the edit buffer.
.LP
This command shall be affected by the \fBnumber\fP and \fBautoindent\fP
edit options; following the command name with
\fB'!'\fP shall cause the \fBautoindent\fP edit option setting to
be toggled for the duration of this command only.
.LP
\fICurrent line\fP: Set to the last input line; if no lines were input,
set to the specified line, or to the first line of the
edit buffer if a line of zero was specified, or zero if the edit buffer
is empty.
.LP
\fICurrent column\fP: Set to non- .
.SS Arguments
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBar\fP\fB[\fP\fIgs\fP\fB]\fP
.fi
.RE
.sp
.LP
Write the current argument list, with the current argument-list entry,
if any, between \fB'['\fP and \fB']'\fP
characters.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Change
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBc\fP\fB[\fP\fBhange\fP\fB][\fP\fB!\fP\fB][\fP\fIcount\fP\fB]\fP
.fi
.RE
.sp
.LP
Enter \fIex\fP text input mode; the input text shall replace the specified
lines. The specified lines shall be copied into the
unnamed buffer, which shall become a line mode buffer.
.LP
This command shall be affected by the \fBnumber\fP and \fBautoindent\fP
edit options; following the command name with
\fB'!'\fP shall cause the \fBautoindent\fP edit option setting to
be toggled for the duration of this command only.
.LP
\fICurrent line\fP: Set to the last input line; if no lines were input,
set to the line before the first address, or to the
first line of the edit buffer if there are no lines preceding the
first address, or to zero if the edit buffer is empty.
.LP
\fICurrent column\fP: Set to non- .
.SS Change Directory
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBchd\fP\fB[\fP\fBir\fP\fB][\fP\fB!\fP\fB][\fP\fIdirectory\fP\fB]\fP\fBcd\fP\fB[\fP\fB!\fP\fB][\fP\fIdirectory\fP\fB]\fP
.fi
.RE
.sp
.LP
Change the current working directory to \fIdirectory\fP.
.LP
If no \fIdirectory\fP argument is specified, and the \fIHOME\fP environment
variable is set to a non-null and non-empty value,
\fIdirectory\fP shall default to the value named in the \fIHOME\fP
environment variable. If the \fIHOME\fP environment variable
is empty or is undefined, the default value of \fIdirectory\fP is
implementation-defined.
.LP
If no \fB'!'\fP is appended to the command name, and the edit buffer
has been modified since the last complete write, and the
current pathname does not begin with a \fB'/'\fP , it shall be an
error.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Copy
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBco\fP\fB[\fP\fBpy\fP\fB]\fP \fI1addr\fP \fB[\fP\fIflags\fP\fB]
[\fP\fI2addr\fP\fB]\fP \fBt\fP \fI1addr\fP \fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Copy the specified lines after the specified destination line; line
zero specifies that the lines shall be placed at the
beginning of the edit buffer.
.LP
\fICurrent line\fP: Set to the last line copied.
.LP
\fICurrent column\fP: Set to non- .
.SS Delete
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBd\fP\fB[\fP\fBelete\fP\fB][\fP\fIbuffer\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Delete the specified lines into a buffer (defaulting to the unnamed
buffer), which shall become a line-mode buffer.
.LP
Flags can immediately follow the command name; see Command Line Parsing
in ex .
.LP
\fICurrent line\fP: Set to the line following the deleted lines, or
to the last line in the edit buffer if that line is past
the end of the edit buffer, or to zero if the edit buffer is empty.
.LP
\fICurrent column\fP: Set to non- .
.SS Edit
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBe\fP\fB[\fP\fBdit\fP\fB][\fP\fB!\fP\fB][\fP\fB+\fP\fIcommand\fP\fB][\fP\fIfile\fP\fB]\fP\fBex\fP\fB[\fP\fB!\fP\fB][\fP\fB+\fP\fIcommand\fP\fB][\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If no \fB'!'\fP is appended to the command name, and the edit buffer
has been modified since the last complete write, it
shall be an error.
.LP
If \fIfile\fP is specified, replace the current contents of the edit
buffer with the current contents of \fIfile\fP, and set
the current pathname to \fIfile\fP. If \fIfile\fP is not specified,
replace the current contents of the edit buffer with the
current contents of the file named by the current pathname. If for
any reason the current contents of the file cannot be accessed,
the edit buffer shall be empty.
.LP
The \fB+\fP \fIcommand\fP option shall be -delimited; s
within \fB+\fP \fIcommand\fP can be
escaped by preceding them with a backslash character. The \fB+\fP
\fIcommand\fP shall be interpreted as an \fIex\fP command
immediately after the contents of the edit buffer have been replaced
and the current line and column have been set.
.LP
If the edit buffer is empty:
.LP
\fICurrent line\fP: Set to 0.
.LP
\fICurrent column\fP: Set to 1.
.LP
Otherwise, if executed while in \fIex\fP command mode or if the \fB+\fP
\fIcommand\fP argument is specified:
.LP
\fICurrent line\fP: Set to the last line of the edit buffer.
.LP
\fICurrent column\fP: Set to non- .
.LP
Otherwise, if \fIfile\fP is omitted or results in the current pathname:
.LP
\fICurrent line\fP: Set to the first line of the edit buffer.
.LP
\fICurrent column\fP: Set to non- .
.LP
Otherwise, if \fIfile\fP is the same as the last file edited, the
line and column shall be set as follows; if the file was
previously edited, the line and column may be set as follows:
.LP
\fICurrent line\fP: Set to the last value held when that file was
last edited. If this value is not a valid line in the new
edit buffer, set to the first line of the edit buffer.
.LP
\fICurrent column\fP: If the current line was set to the last value
held when the file was last edited, set to the last value
held when the file was last edited. Otherwise, or if the last value
is not a valid column in the new edit buffer, set to non-
.
.LP
Otherwise:
.LP
\fICurrent line\fP: Set to the first line of the edit buffer.
.LP
\fICurrent column\fP: Set to non- .
.SS File
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBf\fP\fB[\fP\fBile\fP\fB][\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If a \fIfile\fP argument is specified, the alternate pathname shall
be set to the current pathname, and the current pathname
shall be set to \fIfile\fP.
.LP
Write an informational message. If the file has a current pathname,
it shall be included in this message; otherwise, the message
shall indicate that there is no current pathname. If the edit buffer
contains lines, the current line number and the number of
lines in the edit buffer shall be included in this message; otherwise,
the message shall indicate that the edit buffer is empty. If
the edit buffer has been modified since the last complete write, this
fact shall be included in this message. If the
\fBreadonly\fP edit option is set, this fact shall be included in
this message. The message may contain other unspecified
information.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Global
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBg\fP\fB[\fP\fBlobal\fP\fB]\fP \fB/\fP\fIpattern\fP\fB/\fP \fB[\fP\fIcommands\fP\fB]
[\fP\fI2addr\fP\fB]\fP \fBv /\fP\fIpattern\fP\fB/\fP \fB[\fP\fIcommands\fP\fB]\fP
.fi
.RE
.sp
.LP
The optional \fB'!'\fP character after the \fBglobal\fP command shall
be the same as executing the \fBv\fP command.
.LP
If \fIpattern\fP is empty (for example, \fB"//"\fP ) or not specified,
the last regular expression used in the editor
command shall be used as the \fIpattern\fP. The \fIpattern\fP can
be delimited by slashes (shown in the Synopsis), as well as any
non-alphanumeric or non-  other than backslash, vertical line,
double quote, or .
.LP
If no lines are specified, the lines shall default to the entire file.
.LP
The \fBglobal\fP and \fBv\fP commands are logically two-pass operations.
First, mark the lines within the specified lines for
which the line excluding the terminating  matches ( \fBglobal\fP)
or does not match ( \fBv\fP or \fBglobal!\fP)
the specified pattern. Second, execute the \fIex\fP commands given
by \fIcommands\fP, with the current line ( \fB'.'\fP ) set
to each marked line. If an error occurs during this process, or the
contents of the edit buffer are replaced (for example, by the
\fIex\fP \fB:edit\fP command) an error message shall be written and
no more commands resulting from the execution of this command
shall be processed.
.LP
Multiple \fIex\fP 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  with a backslash.
.LP
If no commands are specified:
.IP " 1." 4
If in \fIex\fP command mode, it shall be as if the \fBprint\fP command
were specified.
.LP
.IP " 2." 4
Otherwise, no command shall be executed.
.LP
.LP
For the \fBappend\fP, \fBchange\fP, and \fBinsert\fP commands, the
input text shall be included as part of the command, and
the terminating period can be omitted if the command ends the list
of commands. The \fBopen\fP and \fBvisual\fP commands can be
specified as one of the commands, in which case each marked line shall
cause the editor to enter open or visual mode. If open or
visual mode is exited using the \fIvi\fP \fBQ\fP command, the current
line shall be set to the
next marked line, and open or visual mode reentered, until the list
of marked lines is exhausted.
.LP
The \fBglobal\fP, \fBv\fP, and \fBundo\fP commands cannot be used
in \fIcommands\fP. Marked lines may be deleted by commands
executed for lines occurring earlier in the file than the marked lines.
In this case, no commands shall be executed for the deleted
lines.
.LP
If the remembered search direction is not set, the \fBglobal\fP and
\fBv\fP commands shall set it to forward.
.LP
The \fBautoprint\fP and \fBautoindent\fP edit options shall be inhibited
for the duration of the \fBg\fP or \fBv\fP
command.
.LP
\fICurrent line\fP: If no commands executed, set to the last marked
line. Otherwise, as specified for the executed \fIex\fP
commands.
.LP
\fICurrent column\fP: If no commands are executed, set to non- ;
otherwise, as specified for the individual
\fIex\fP commands.
.SS Insert
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBi\fP\fB[\fP\fBnsert\fP\fB][\fP\fB!\fP\fB]\fP
.fi
.RE
.sp
.LP
Enter \fIex\fP text input mode; the input text shall be placed before
the specified line. If the line is zero or 1, the text
shall be placed at the beginning of the edit buffer.
.LP
This command shall be affected by the \fBnumber\fP and \fBautoindent\fP
edit options; following the command name with
\fB'!'\fP shall cause the \fBautoindent\fP edit option setting to
be toggled for the duration of this command only.
.LP
\fICurrent line\fP: Set to the last input line; if no lines were input,
set to the line before the specified line, or to the
first line of the edit buffer if there are no lines preceding the
specified line, or zero if the edit buffer is empty.
.LP
\fICurrent column\fP: Set to non- .
.SS Join
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBj\fP\fB[\fP\fBoin\fP\fB][\fP\fB!\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIcount\fP is specified:
If no address was specified, the \fBjoin\fP command shall behave as
if \fI2addr\fP were the current line and the
current line plus \fIcount\fP (.,. + \fIcount\fP). 
.LP
If one address was specified, the \fBjoin\fP command shall behave
as if \fI2addr\fP were the specified address and the
specified address plus \fIcount\fP ( \fIaddr\fP, \fIaddr\fP + \fIcount\fP).
.LP
If two addresses were specified, the \fBjoin\fP command shall behave
as if an additional address, equal to the last address
plus \fIcount\fP -1 ( \fIaddr1\fP, \fIaddr2\fP, \fIaddr2\fP + \fIcount\fP
-1), was specified.
.LP
If this would result in a second address greater than the last line
of the edit buffer, it shall be corrected to be equal to the
last line of the edit buffer.
.LP
If no \fIcount\fP is specified:
If no address was specified, the \fBjoin\fP command shall behave as
if \fI2addr\fP were the current line and the next
line (.,. +1). 
.LP
If one address was specified, the \fBjoin\fP command shall behave
as if \fI2addr\fP were the specified address and the next
line ( \fIaddr\fP, \fIaddr\fP +1).
.LP
Join the text from the specified lines together into a single line,
which shall replace the specified lines.
.LP
If a \fB'!'\fP character is appended to the command name, the \fBjoin\fP
shall be without modification of any line,
independent of the current locale.
.LP
Otherwise, in the POSIX locale, set the current line to the first
of the specified lines, and then, for each subsequent line,
proceed as follows:
.IP " 1." 4
Discard leading s from the line to be joined.
.LP
.IP " 2." 4
If the line to be joined is now empty, delete it, and skip steps 3
through 5.
.LP
.IP " 3." 4
If the current line ends in a , or the first character of the
line to be joined is a \fB')'\fP character, join
the lines without further modification.
.LP
.IP " 4." 4
If the last character of the current line is a \fB'.'\fP , join the
lines with two s between them.
.LP
.IP " 5." 4
Otherwise, join the lines with a single  between them.
.LP
.LP
\fICurrent line\fP: Set to the first line specified.
.LP
\fICurrent column\fP: Set to non- .
.SS List
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBl\fP\fB[\fP\fBist\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
This command shall be equivalent to the \fIex\fP command:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBp\fP\fB[\fP\fBrint\fP\fB][\fP\fIcount\fP\fB]\fP \fBl\fP\fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.LP
See Print .
.SS Map
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBmap\fP\fB[\fP\fB!\fP\fB][\fP\fIlhs rhs\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIlhs\fP and \fIrhs\fP are not specified:
.IP " 1." 4
If \fB'!'\fP is specified, write the current list of text input mode
maps.
.LP
.IP " 2." 4
Otherwise, write the current list of command mode maps.
.LP
.IP " 3." 4
Do nothing more.
.LP
.LP
Implementations may restrict the set of characters accepted in \fIlhs\fP
or \fIrhs\fP, except that printable characters and
s shall not be restricted. Additional restrictions shall be
implementation-defined. In both \fIlhs\fP and \fIrhs\fP,
any character can be escaped with a -V, in which case the
character shall not be used to delimit \fIlhs\fP from
\fIrhs\fP, and the escaping -V shall be discarded.
.LP
If the character \fB'!'\fP is appended to the \fBmap\fP command name,
the mapping shall be effective during open or visual
text input mode rather than \fBopen\fP or \fBvisual\fP command mode.
This allows \fIlhs\fP to have two different \fBmap\fP
definitions at the same time: one for command mode and one for text
input mode.
.LP
For command mode mappings:
When the \fIlhs\fP is entered as any part of a \fIvi\fP command in
open or visual
mode (but not as part of the arguments to the command), the action
shall be as if the corresponding \fIrhs\fP had been entered. 
.LP
If any character in the command, other than the first, is escaped
using a -V character, that character shall not
be part of a match to an \fIlhs\fP.
.LP
It is unspecified whether implementations shall support \fBmap\fP
commands where the \fIlhs\fP is more than a single character
in length, where the first character of the \fIlhs\fP is printable.
.LP
If \fIlhs\fP contains more than one character and the first character
is \fB'#'\fP , followed by a sequence of digits
corresponding to a numbered function key, then when this function
key is typed it shall be mapped to \fIrhs\fP. Characters other
than digits following a \fB'#'\fP character also represent the function
key named by the characters in the \fIlhs\fP following
the \fB'#'\fP and may be mapped to \fIrhs\fP. It is unspecified how
function keys are named or what function keys are
supported.
.LP
For text input mode mappings:
When the \fIlhs\fP is entered as any part of text entered in open
or visual text input modes, the action shall be as
if the corresponding \fIrhs\fP had been entered. 
.LP
If any character in the input text is escaped using a -V
character, that character shall not be part of a match
to an \fIlhs\fP.
.LP
It is unspecified whether the \fIlhs\fP text entered for subsequent
\fBmap\fP or \fBunmap\fP commands is replaced with the
\fIrhs\fP text for the purposes of the screen display; regardless
of whether or not the display appears as if the corresponding
\fIrhs\fP text was entered, the effect of the command shall be as
if the \fIlhs\fP text was entered.
.LP
If only part of the \fIlhs\fP is entered, it is unspecified how long
the editor will wait for additional, possibly matching
characters before treating the already entered characters as not matching
the \fIlhs\fP.
.LP
The \fIrhs\fP characters shall themselves be subject to remapping,
unless otherwise specified by the \fBremap\fP edit option,
except that if the characters in \fIlhs\fP occur as prefix characters
in \fIrhs\fP, those characters shall not be remapped.
.LP
On block-mode terminals, the mapping need not occur immediately (for
example, it may occur after the terminal transmits a group
of characters to the system), but it shall achieve the same results
as if it occurred immediately.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Mark
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBma\fP\fB[\fP\fBrk\fP\fB]\fP \fIcharacter
\fP\fB[\fP\fI1addr\fP\fB]\fP \fBk\fP \fIcharacter\fP
.fi
.RE
.sp
.LP
Implementations shall support \fIcharacter\fP values of a single lowercase
letter of the POSIX locale and the characters
\fB'`'\fP and \fB'"\fP ; support of other characters is implementation-defined.
.LP
If executing the \fIvi\fP \fBm\fP command, set the specified mark
to the current line and
1-based numbered character referenced by the current column, if any;
otherwise, column position 1.
.LP
Otherwise, set the specified mark to the specified line and 1-based
numbered first non-  non-  in
the line, if any; otherwise, the last non-  in the line,
if any; otherwise, column position 1.
.LP
The mark shall remain associated with the line until the mark is reset
or the line is deleted. If a deleted line is restored by
a subsequent \fBundo\fP command, any marks previously associated with
the line, which have not been reset, shall be restored as
well. Any use of a mark not associated with a current line in the
edit buffer shall be an error.
.LP
The marks \fB`\fP and \fB'\fP shall be set as described previously,
immediately before the following events occur in the
editor:
.IP " 1." 4
The use of \fB'$'\fP as an \fIex\fP address
.LP
.IP " 2." 4
The use of a positive decimal number as an \fIex\fP address
.LP
.IP " 3." 4
The use of a search command as an \fIex\fP address
.LP
.IP " 4." 4
The use of a mark reference as an \fIex\fP address
.LP
.IP " 5." 4
The use of the following open and visual mode commands: -],
\fB%\fP, \fB(\fP, \fB)\fP, \fB[\fP, \fB]\fP,
\fB{\fP, \fB}\fP
.LP
.IP " 6." 4
The use of the following open and visual mode commands: \fB'\fP, \fBG\fP,
\fBH\fP, \fBL\fP, \fBM\fP, \fBz\fP if the
current line will change as a result of the command
.LP
.IP " 7." 4
The use of the open and visual mode commands: \fB/\fP, \fB?\fP, \fBN\fP,
\fB`\fP, \fBn\fP if the current line or column
will change as a result of the command
.LP
.IP " 8." 4
The use of the \fIex\fP mode commands: \fBz\fP, \fBundo\fP, \fBglobal\fP,
\fBv\fP
.LP
.LP
For rules 1., 2., 3., and 4., the \fB`\fP and \fB'\fP marks shall
not be set if the \fIex\fP command is parsed as specified
by rule 6.a. in Command Line Parsing in ex .
.LP
For rules 5., 6., and 7., the \fB`\fP and \fB'\fP marks shall not
be set if the commands are used as motion commands in open
and visual mode.
.LP
For rules 1., 2., 3., 4., 5., 6., 7., and 8., the \fB`\fP and \fB'\fP
marks shall not be set if the command fails.
.LP
The \fB`\fP and \fB'\fP marks shall be set as described previously,
each time the contents of the edit buffer are replaced
(including the editing of the initial buffer), if in open or visual
mode, or if in \fBex\fP mode and the edit buffer is not empty,
before any commands or movements (including commands or movements
specified by the \fB-c\fP or \fB-t\fP options or the \fB+\fP
\fIcommand\fP argument) are executed on the edit buffer. If in open
or visual mode, the marks shall be set as if executing the \fIvi\fP
\fBm\fP command; otherwise, as if executing the \fIex\fP \fBmark\fP
command.
.LP
When changing from \fBex\fP mode to open or visual mode, if the \fB`\fP
and \fB'\fP marks are not already set, the \fB`\fP
and \fB'\fP marks shall be set as described previously.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Move
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBm\fP\fB[\fP\fBove\fP\fB]\fP \fI1addr\fP \fB\fP\fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Move the specified lines after the specified destination line. A destination
of line zero specifies that the lines shall be
placed at the beginning of the edit buffer. It shall be an error if
the destination line is within the range of lines to be
moved.
.LP
\fICurrent line\fP: Set to the last of the moved lines.
.LP
\fICurrent column\fP: Set to non- .
.SS Next
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBn\fP\fB[\fP\fBext\fP\fB][\fP\fB!\fP\fB][\fP\fB+\fP\fIcommand\fP\fB][\fP\fIfile\fP \fB...\fP\fB]\fP
.fi
.RE
.sp
.LP
If no \fB'!'\fP is appended to the command name, and the edit buffer
has been modified since the last complete write, it
shall be an error, unless the file is successfully written as specified
by the \fBautowrite\fP option.
.LP
If one or more files is specified:
.IP " 1." 4
Set the argument list to the specified filenames.
.LP
.IP " 2." 4
Set the current argument list reference to be the first entry in the
argument list.
.LP
.IP " 3." 4
Set the current pathname to the first filename specified.
.LP
.LP
Otherwise:
.IP " 1." 4
It shall be an error if there are no more filenames in the argument
list after the filename currently referenced.
.LP
.IP " 2." 4
Set the current pathname and the current argument list reference to
the filename after the filename currently referenced in the
argument list.
.LP
.LP
Replace the contents of the edit buffer with the contents of the file
named by the current pathname. If for any reason the
contents of the file cannot be accessed, the edit buffer shall be
empty.
.LP
This command shall be affected by the \fBautowrite\fP and \fBwriteany\fP
edit options.
.LP
The \fB+\fP \fIcommand\fP option shall be -delimited; s
can be escaped by preceding them with a
backslash character. The \fB+\fP \fIcommand\fP shall be interpreted
as an \fIex\fP command immediately after the contents of the
edit buffer have been replaced and the current line and column have
been set.
.LP
\fICurrent line\fP: Set as described for the \fBedit\fP command.
.LP
\fICurrent column\fP: Set as described for the \fBedit\fP command.
.SS Number
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBnu\fP\fB[\fP\fBmber\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]
[\fP\fI2addr\fP\fB]\fP \fB#\fP\fB[\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
These commands shall be equivalent to the \fIex\fP command:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBp\fP\fB[\fP\fBrint\fP\fB][\fP\fIcount\fP\fB]\fP \fB#\fP\fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.LP
See Print .
.SS Open
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBo\fP\fB[\fP\fBpen\fP\fB]\fP \fB/\fP\fIpattern\fP\fB/\fP \fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
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.
.LP
Enter open mode.
.LP
The trailing delimiter can be omitted from \fIpattern\fP at the end
of the command line. If \fIpattern\fP is empty (for
example, \fB"//"\fP ) or not specified, the last regular expression
used in the editor shall be used as the pattern. The pattern
can be delimited by slashes (shown in the Synopsis), as well as any
alphanumeric, or non-  other than backslash,
vertical line, double quote, or .
.LP
\fICurrent line\fP: Set to the specified line.
.LP
\fICurrent column\fP: Set to non- .
.SS Preserve
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBpre\fP\fB[\fP\fBserve\fP\fB]\fP
.fi
.RE
.sp
.LP
Save the edit buffer in a form that can later be recovered by using
the \fB-r\fP option or by using the \fIex\fP
\fBrecover\fP command. After the file has been preserved, a mail message
shall be sent to the user. This message shall be readable
by invoking the \fImailx\fP utility. The message shall contain the
name of the file, the
time of preservation, and an \fIex\fP command that could be used to
recover the file. Additional information may be included in
the mail message.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Print
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBp\fP\fB[\fP\fBrint\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Write the addressed lines. The behavior is unspecified if the number
of columns on the display is less than the number of
columns required to write any single character in the lines being
written.
.LP
Non-printable characters, except for the , shall be written as
implementation-defined multi-character sequences.
.LP
If the \fB#\fP flag is specified or the \fBnumber\fP edit option is
set, each line shall be preceded by its line number in the
following format:
.sp
.RS
.nf

\fB"%6d  ", <\fP\fIline number\fP\fB>
\fP
.fi
.RE
.LP
If the \fBl\fP flag is specified or the \fBlist\fP edit option is
set:
.IP " 1." 4
The characters listed in the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
Table 5-1, Escape Sequences and
Associated Actions shall be written as the corresponding escape sequence.
.LP
.IP " 2." 4
Non-printable characters not in the Base Definitions volume of IEEE\ Std\ 1003.1-2001,
Table 5-1, Escape Sequences and
Associated Actions shall be written as one three-digit octal number
(with a preceding backslash) for each byte in the character
(most significant byte first). If the size of a byte on the system
is greater than 9 bits, the format used for non-printable
characters is implementation-defined.
.LP
.IP " 3." 4
The end of each line shall be marked with a \fB'$'\fP , and literal
\fB'$'\fP characters within the line shall be written
with a preceding backslash.
.LP
.LP
Long lines shall be folded; the length at which folding occurs is
unspecified, but should be appropriate for the output
terminal, considering the number of columns of the terminal.
.LP
If a line is folded, and the \fBl\fP flag is not specified and the
\fBlist\fP edit option is not set, it is unspecified
whether a multi-column character at the folding position is separated;
it shall not be discarded.
.LP
\fICurrent line\fP: Set to the last written line.
.LP
\fICurrent column\fP: Unchanged if the current line is unchanged;
otherwise, set to non- .
.SS Put
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBpu\fP\fB[\fP\fBt\fP\fB][\fP\fIbuffer\fP\fB]\fP
.fi
.RE
.sp
.LP
Append text from the specified buffer (by default, the unnamed buffer)
to the specified line; line zero specifies that the text
shall be placed at the beginning of the edit buffer. Each portion
of a line in the buffer shall become a new line in the edit
buffer, regardless of the mode of the buffer.
.LP
\fICurrent line\fP: Set to the last line entered into the edit buffer.
.LP
\fICurrent column\fP: Set to non- .
.SS Quit
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBq\fP\fB[\fP\fBuit\fP\fB][\fP\fB!\fP\fB]\fP
.fi
.RE
.sp
.LP
If no \fB'!'\fP is appended to the command name:
.IP " 1." 4
If the edit buffer has been modified since the last complete write,
it shall be an error.
.LP
.IP " 2." 4
If there are filenames in the argument list after the filename currently
referenced, and the last command was not a \fBquit\fP,
\fBwq\fP, \fBxit\fP, or \fBZZ\fP (see \fIExit\fP ) command, it shall
be an error.
.LP
.LP
Otherwise, terminate the editing session.
.SS Read
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBr\fP\fB[\fP\fBead\fP\fB][\fP\fB!\fP\fB][\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fB'!'\fP is not the first non-  to follow the command name,
a copy of the specified file shall be appended
into the edit buffer after the specified line; line zero specifies
that the copy shall be placed at the beginning of the edit
buffer. The number of lines and bytes read shall be written. If no
\fIfile\fP is named, the current pathname shall be the default.
If there is no current pathname, then \fIfile\fP shall become the
current pathname. If there is no current pathname or \fIfile\fP
operand, it shall be an error. Specifying a \fIfile\fP that is not
of type regular shall have unspecified results.
.LP
Otherwise, if \fIfile\fP is preceded by \fB'!'\fP , the rest of the
line after the \fB'!'\fP shall have \fB'%'\fP ,
\fB'#'\fP , and \fB'!'\fP characters expanded as described in Command
Line Parsing in ex .
.LP
The \fIex\fP utility shall then pass two arguments to the program
named by the shell edit option; the first shall be \fB-c\fP
and the second shall be the expanded arguments to the \fBread\fP command
as a single argument. The standard input of the program
shall be set to the standard input of the \fIex\fP program when it
was invoked. The standard error and standard output of the
program shall be appended into the edit buffer after the specified
line.
.LP
Each line in the copied file or program output (as delimited by s
or the end of the file or output if it is not
immediately preceded by a ), shall be a separate line in
the edit buffer. Any occurrences of 
and  pairs in the output shall be treated as single s.
.LP
The special meaning of the \fB'!'\fP following the \fBread\fP command
can be overridden by escaping it with a backslash
character.
.LP
\fICurrent line\fP: If no lines are added to the edit buffer, unchanged.
Otherwise, if in open or visual mode, set to the first
line entered into the edit buffer. Otherwise, set to the last line
entered into the edit buffer.
.LP
\fICurrent column\fP: Set to non- .
.SS Recover
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBrec\fP\fB[\fP\fBover\fP\fB][\fP\fB!\fP\fB]\fP \fIfile\fP
.fi
.RE
.sp
.LP
If no \fB'!'\fP is appended to the command name, and the edit buffer
has been modified since the last complete write, it
shall be an error.
.LP
If no \fIfile\fP operand is specified, then the current pathname shall
be used. If there is no current pathname or \fIfile\fP
operand, it shall be an error.
.LP
If no recovery information has previously been saved about \fIfile\fP,
the \fBrecover\fP command shall behave identically to
the \fBedit\fP command, and an informational message to this effect
shall be written.
.LP
Otherwise, set the current pathname to \fIfile\fP, and replace the
current contents of the edit buffer with the recovered
contents of \fIfile\fP. If there are multiple instances of the file
to be recovered, the one most recently saved shall be
recovered, and an informational message that there are previous versions
of the file that can be recovered shall be written. The
editor shall behave as if the contents of the edit buffer have already
been modified.
.LP
\fICurrent file\fP: Set as described for the \fBedit\fP command.
.LP
\fICurrent column\fP: Set as described for the \fBedit\fP command.
.SS Rewind
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBrew\fP\fB[\fP\fBind\fP\fB][\fP\fB!\fP\fB]\fP
.fi
.RE
.sp
.LP
If no \fB'!'\fP is appended to the command name, and the edit buffer
has been modified since the last complete write, it
shall be an error, unless the file is successfully written as specified
by the \fBautowrite\fP option.
.LP
If the argument list is empty, it shall be an error.
.LP
The current argument list reference and the current pathname shall
be set to the first filename in the argument list.
.LP
Replace the contents of the edit buffer with the contents of the file
named by the current pathname. If for any reason the
contents of the file cannot be accessed, the edit buffer shall be
empty.
.LP
This command shall be affected by the \fBautowrite\fP and \fBwriteany\fP
edit options.
.LP
\fICurrent line\fP: Set as described for the \fBedit\fP command.
.LP
\fICurrent column\fP: Set as described for the \fBedit\fP command.
.SS Set
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBse\fP\fB[\fP\fBt\fP\fB][\fP\fIoption\fP\fB[\fP\fB=\fP\fB[\fP\fIvalue\fP\fB]]\fP \fB...\fP\fB][\fP\fBno\fP\fIoption\fP \fB...\fP\fB][\fP\fIoption\fP\fB? ...\fP\fB][\fP\fBall\fP\fB]\fP
.fi
.RE
.sp
.LP
When no arguments are specified, write the value of the \fBterm\fP
edit option and those options whose values have been changed
from the default settings; when the argument \fIall\fP is specified,
write all of the option values.
.LP
Giving an option name followed by the character \fB'?'\fP shall cause
the current value of that option to be written. The
\fB'?'\fP can be separated from the option name by zero or more s.
The \fB'?'\fP shall be necessary only for
Boolean valued options. Boolean options can be given values by the
form \fBset\fP \fIoption\fP to turn them on or \fBset\fP
\fBno\fP \fIoption\fP to turn them off; string and numeric options
can be assigned by the form \fBset\fP \fIoption\fP=
\fIvalue\fP. Any s in strings can be included as is by preceding
each  with an escaping backslash. More
than one option can be set or listed by a single set command by specifying
multiple arguments, each separated from the next by one
or more s.
.LP
See Edit Options in ex for details about specific options.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Shell
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBsh\fP\fB[\fP\fBell\fP\fB]\fP
.fi
.RE
.sp
.LP
Invoke the program named in the \fBshell\fP edit option with the single
argument \fB-i\fP (interactive mode). Editing shall be
resumed when the program exits.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Source
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBso\fP\fB[\fP\fBurce\fP\fB]\fP \fIfile\fP
.fi
.RE
.sp
.LP
Read and execute \fIex\fP commands from \fIfile\fP. Lines in the file
that are blank lines shall be ignored.
.LP
\fICurrent line\fP: As specified for the individual \fIex\fP commands.
.LP
\fICurrent column\fP: As specified for the individual \fIex\fP commands.
.SS Substitute
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBs\fP\fB[\fP\fBubstitute\fP\fB][\fP\fB/\fP\fIpattern\fP\fB/\fP\fIrepl\fP\fB/\fP\fB[\fP\fIoptions\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]]\fP\fB
.br

\fP\fB[\fP\fI2addr\fP\fB]\fP \fB&\fP\fB[\fP\fIoptions\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]]\fP\fB
.br

\fP\fB[\fP\fI2addr\fP\fB]\fP \fB~\fP\fB[\fP\fIoptions\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]]\fP
.fi
.RE
.sp
.LP
Replace the first instance of the pattern \fIpattern\fP by the string
\fIrepl\fP on each specified line. (See Regular Expressions in ex
and Replacement Strings in ex .) Any
non-alphabetic, non-  delimiter other than \fB'\\'\fP , \fB'|'\fP
, double quote, or  can be used
instead of \fB'/'\fP . Backslash characters can be used to escape
delimiters, backslash characters, and other special
characters.
.LP
The trailing delimiter can be omitted from \fIpattern\fP or from \fIrepl\fP
at the end of the command line. If both
\fIpattern\fP and \fIrepl\fP are not specified or are empty (for example,
\fB"//"\fP ), the last \fBs\fP command shall be
repeated. If only \fIpattern\fP is not specified or is empty, the
last regular expression used in the editor shall be used as the
pattern. If only \fIrepl\fP is not specified or is empty, the pattern
shall be replaced by nothing. If the entire replacement
pattern is \fB'%'\fP , the last replacement pattern to an \fBs\fP
command shall be used.
.LP
Entering a  in \fIrepl\fP (which requires an escaping
backslash in \fIex\fP mode and an escaping
-V in open or \fIvi\fP mode) shall split the line at that
point, creating a new
line in the edit buffer. The  shall be discarded.
.LP
If \fIoptions\fP includes the letter \fB'g'\fP ( \fBglobal\fP), all
non-overlapping instances of the pattern in the line
shall be replaced.
.LP
If \fIoptions\fP includes the letter \fB'c'\fP ( \fBconfirm\fP), then
before each substitution the line shall be written;
the written line shall reflect all previous substitutions. On the
following line, s shall be written beneath the
characters from the line that are before the \fIpattern\fP to be replaced,
and \fB'^'\fP characters written beneath the
characters included in the \fIpattern\fP to be replaced. The \fIex\fP
utility shall then wait for a response from the user. An
affirmative response shall cause the substitution to be done, while
any other input shall not make the substitution. An affirmative
response shall consist of a line with the affirmative response (as
defined by the current locale) at the beginning of the line.
This line shall be subject to editing in the same way as the \fIex\fP
command line.
.LP
If interrupted (see the ASYNCHRONOUS EVENTS section), any modifications
confirmed by the user shall be preserved in the edit
buffer after the interrupt.
.LP
If the remembered search direction is not set, the \fBs\fP command
shall set it to forward.
.LP
In the second Synopsis, the \fB&\fP command shall repeat the previous
substitution, as if the \fB&\fP command were
replaced by:
.sp
.RS
.nf

\fBs/\fP\fIpattern\fP\fB/\fP\fIrepl\fP\fB/
\fP
.fi
.RE
.LP
where \fIpattern\fP and \fIrepl\fP are as specified in the previous
\fBs\fP, \fB&\fP, or \fB~\fP command.
.LP
In the third Synopsis, the \fB~\fP command shall repeat the previous
substitution, as if the \fB'~'\fP were
replaced by:
.sp
.RS
.nf

\fBs/\fP\fIpattern\fP\fB/\fP\fIrepl\fP\fB/
\fP
.fi
.RE
.LP
where \fIpattern\fP shall be the last regular expression specified
to the editor, and \fIrepl\fP shall be from the previous
substitution (including \fB&\fP and \fB~\fP) command.
.LP
These commands shall be affected by the \fILC_MESSAGES\fP environment
variable.
.LP
\fICurrent line\fP: Set to the last line in which a substitution occurred,
or, unchanged if no substitution occurred.
.LP
\fICurrent column\fP: Set to non- .
.SS Suspend
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBsu\fP\fB[\fP\fBspend\fP\fB][\fP\fB!\fP\fB]\fP\fBst\fP\fB[\fP\fBop\fP\fB][\fP\fB!\fP\fB]\fP
.fi
.RE
.sp
.LP
Allow control to return to the invoking process; \fIex\fP shall suspend
itself as if it had received the SIGTSTP signal. The
suspension shall occur only if job control is enabled in the invoking
shell (see the description of \fIset\fP \fB-m\fP).
.LP
These commands shall be affected by the \fBautowrite\fP and \fBwriteany\fP
edit options.
.LP
The current \fBsusp\fP character (see \fIstty\fP ) shall be equivalent
to the \fBsuspend\fP
command.
.SS Tag
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBta\fP\fB[\fP\fBg\fP\fB][\fP\fB!\fP\fB]\fP \fItagstring\fP
.fi
.RE
.sp
.LP
The results are unspecified if the format of a tags file is not as
specified by the \fIctags\fP utility (see \fIctags\fP ) description.
.LP
The \fBtag\fP command shall search for \fItagstring\fP in the tag
files referred to by the \fBtag\fP edit option, in the
order they are specified, until a reference to \fItagstring\fP is
found. Files shall be searched from beginning to end. If no
reference is found, it shall be an error and an error message to this
effect shall be written. If the reference is not found, or if
an error occurs while processing a file referred to in the \fBtag\fP
edit option, it shall be an error, and an error message shall
be written at the first occurrence of such an error.
.LP
Otherwise, if the tags file contained a pattern, the pattern shall
be treated as a regular expression used in the editor; for
example, for the purposes of the \fBs\fP command.
.LP
If the \fItagstring\fP is in a file with a different name than the
current pathname, set the current pathname to the name of
that file, and replace the contents of the edit buffer with the contents
of that file. In this case, if no \fB'!'\fP is appended
to the command name, and the edit buffer has been modified since the
last complete write, it shall be an error, unless the file is
successfully written as specified by the \fBautowrite\fP option.
.LP
This command shall be affected by the \fBautowrite\fP, \fBtag\fP,
\fBtaglength\fP, and \fBwriteany\fP edit options.
.LP
\fICurrent line\fP: If the tags file contained a line number, set
to that line number. If the line number is larger than the
last line in the edit buffer, an error message shall be written and
the current line shall be set as specified for the \fBedit\fP
command.
.LP
If the tags file contained a pattern, set to the first occurrence
of the pattern in the file. If no matching pattern is found,
an error message shall be written and the current line shall be set
as specified for the \fBedit\fP command.
.LP
\fICurrent column\fP: If the tags file contained a line-number reference
and that line-number was not larger than the last line
in the edit buffer, or if the tags file contained a pattern and that
pattern was found, set to non- . Otherwise, set
as specified for the \fBedit\fP command.
.SS Unabbreviate
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBuna\fP\fB[\fP\fBbbrev\fP\fB]\fP \fIlhs\fP
.fi
.RE
.sp
.LP
If \fIlhs\fP is not an entry in the current list of abbreviations
(see Abbreviate ), it shall be
an error. Otherwise, delete \fIlhs\fP from the list of abbreviations.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Undo
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBu\fP\fB[\fP\fBndo\fP\fB]\fP
.fi
.RE
.sp
.LP
Reverse the changes made by the last command that modified the contents
of the edit buffer, including \fBundo\fP. For this
purpose, the \fBglobal\fP, \fBv\fP, \fBopen\fP, and \fBvisual\fP commands,
and commands resulting from buffer executions and
mapped character expansions, are considered single commands.
.LP
If no action that can be undone preceded the \fBundo\fP command, it
shall be an error.
.LP
If the \fBundo\fP command restores lines that were marked, the mark
shall also be restored unless it was reset subsequent to
the deletion of the lines.
.LP
\fICurrent line\fP:
.IP " 1." 4
If lines are added or changed in the file, set to the first line added
or changed.
.LP
.IP " 2." 4
Set to the line before the first line deleted, if it exists.
.LP
.IP " 3." 4
Set to 1 if the edit buffer is not empty.
.LP
.IP " 4." 4
Set to zero.
.LP
.LP
\fICurrent column\fP: Set to non- .
.SS Unmap
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBunm\fP\fB[\fP\fBap\fP\fB][\fP\fB!\fP\fB]\fP \fIlhs\fP
.fi
.RE
.sp
.LP
If \fB'!'\fP is appended to the command name, and if \fIlhs\fP is
not an entry in the list of text input mode map
definitions, it shall be an error. Otherwise, delete \fIlhs\fP from
the list of text input mode map definitions.
.LP
If no \fB'!'\fP is appended to the command name, and if \fIlhs\fP
is not an entry in the list of command mode map
definitions, it shall be an error. Otherwise, delete \fIlhs\fP from
the list of command mode map definitions.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Version
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBve\fP\fB[\fP\fBrsion\fP\fB]\fP
.fi
.RE
.sp
.LP
Write a message containing version information for the editor. The
format of the message is unspecified.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Visual
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBvi\fP\fB[\fP\fBsual\fP\fB][\fP\fItype\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIex\fP is currently in open or visual mode, the Synopsis and
behavior of the visual command shall be the same as the
\fBedit\fP command, as specified by Edit .
.LP
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.
.LP
If \fIcount\fP is specified, the value of the \fBwindow\fP edit option
shall be set to \fIcount\fP (as described in window ). If the \fB'^'\fP
type character was also specified, the \fBwindow\fP edit option shall
be set
before being used by the type character.
.LP
Enter visual mode. If \fItype\fP is not specified, it shall be as
if a \fItype\fP of \fB'+'\fP was specified. The
\fItype\fP shall cause the following effects:
.TP 7
\fB+\fP
Place the beginning of the specified line at the top of the display.
.TP 7
\fB-\fP
Place the end of the specified line at the bottom of the display.
.TP 7
\fB\&.\fP
Place the beginning of the specified line in the middle of the display.
.TP 7
\fB^\fP
If the specified line is less than or equal to the value of the \fBwindow\fP
edit option, set the line to 1; otherwise,
decrement the line by the value of the \fBwindow\fP edit option minus
1. Place the beginning of this line as close to the bottom
of the displayed lines as possible, while still displaying the value
of the \fBwindow\fP edit option number of lines.
.sp
.LP
\fICurrent line\fP: Set to the specified line.
.LP
\fICurrent column\fP: Set to non- .
.SS Write
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBw\fP\fB[\fP\fBrite\fP\fB][\fP\fB!\fP\fB][\fP\fB>>\fP\fB][\fP\fIfile\fP\fB]
[\fP\fI2addr\fP\fB]\fP \fBw\fP\fB[\fP\fBrite\fP\fB][\fP\fB!\fP\fB][\fP\fIfile\fP\fB]
[\fP\fI2addr\fP\fB]\fP \fBwq\fP\fB[\fP\fB!\fP\fB][\fP\fB>>\fP\fB][\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If no lines are specified, the lines shall default to the entire file.
.LP
The command \fBwq\fP shall be equivalent to a \fBwrite\fP command
followed by a \fBquit\fP command; \fBwq!\fP shall be
equivalent to \fBwrite!\fP followed by \fBquit\fP. In both cases,
if the \fBwrite\fP command fails, the \fBquit\fP shall not be
attempted.
.LP
If the command name is not followed by one or more s, or \fIfile\fP
is not preceded by a \fB'!'\fP character,
the \fBwrite\fP shall be to a file.
.IP " 1." 4
If the \fB>>\fP argument is specified, and the file already exists,
the lines shall be appended to the file instead of
replacing its contents. If the \fB>>\fP argument is specified, and
the file does not already exist, it is unspecified
whether the write shall proceed as if the \fB>>\fP argument had not
been specified or if the write shall fail.
.LP
.IP " 2." 4
If the \fBreadonly\fP edit option is set (see readonly ), the \fBwrite\fP
shall fail.
.LP
.IP " 3." 4
If \fIfile\fP is specified, and is not the current pathname, and the
file exists, the \fBwrite\fP shall fail.
.LP
.IP " 4." 4
If \fIfile\fP is not specified, the current pathname shall be used.
If there is no current pathname, the \fBwrite\fP command
shall fail.
.LP
.IP " 5." 4
If the current pathname is used, and the current pathname has been
changed by the \fBfile\fP or \fBread\fP commands, and the
file exists, the \fBwrite\fP shall fail. If the \fBwrite\fP is successful,
subsequent \fBwrite\fPs shall not fail for this
reason (unless the current pathname is changed again).
.LP
.IP " 6." 4
If the whole edit buffer is not being written, and the file to be
written exists, the \fBwrite\fP shall fail.
.LP
.LP
For rules 1., 2., 4., and 5., the \fBwrite\fP can be forced by appending
the character \fB'!'\fP to the command name.
.LP
For rules 2., 4., and 5., the \fBwrite\fP can be forced by setting
the \fBwriteany\fP edit option.
.LP
Additional, implementation-defined tests may cause the \fBwrite\fP
to fail.
.LP
If the edit buffer is empty, a file without any contents shall be
written.
.LP
An informational message shall be written noting the number of lines
and bytes written.
.LP
Otherwise, if the command is followed by one or more s, and
the file is preceded by \fB'!'\fP , the rest of the
line after the \fB'!'\fP shall have \fB'%'\fP , \fB'#'\fP , and \fB'!'\fP
characters expanded as described in Command Line Parsing in ex .
.LP
The \fIex\fP utility shall then pass two arguments to the program
named by the \fBshell\fP edit option; the first shall be
\fB-c\fP and the second shall be the expanded arguments to the \fBwrite\fP
command as a single argument. The specified lines
shall be written to the standard input of the command. The standard
error and standard output of the program, if any, shall be
written as described for the \fBprint\fP command. If the last character
in that output is not a , a 
shall be written at the end of the output.
.LP
The special meaning of the \fB'!'\fP following the \fBwrite\fP command
can be overridden by escaping it with a backslash
character.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Write and Exit
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBx\fP\fB[\fP\fBit\fP\fB][\fP\fB!\fP\fB][\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If the edit buffer has not been modified since the last complete \fBwrite\fP,
\fBxit\fP shall be equivalent to the \fBquit\fP
command, or if a \fB'!'\fP is appended to the command name, to \fBquit!\fP.
.LP
Otherwise, \fBxit\fP shall be equivalent to the \fBwq\fP command,
or if a \fB'!'\fP is appended to the command name, to
\fBwq!\fP.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Yank
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fBya\fP\fB[\fP\fBnk\fP\fB][\fP\fIbuffer\fP\fB][\fP\fIcount\fP\fB]\fP
.fi
.RE
.sp
.LP
Copy the specified lines to the specified buffer (by default, the
unnamed buffer), which shall become a line-mode buffer.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Adjust Window
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fBz\fP\fB[\fP\fB!\fP\fB][\fP\fItype\fP \fB...\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
If no line is specified, the current line shall be the default; if
\fItype\fP is omitted as well, the current line value shall
first be incremented by 1. If incrementing the current line would
cause it to be greater than the last line in the edit buffer, it
shall be an error.
.LP
If there are s between the \fItype\fP argument and the preceding
\fBz\fP command name or optional \fB'!'\fP
character, it shall be an error.
.LP
If \fIcount\fP is specified, the value of the \fBwindow\fP edit option
shall be set to \fIcount\fP (as described in window ). If \fIcount\fP
is omitted, it shall default to 2 times the value of the \fBscroll\fP
edit
option, or if \fB!\fP was specified, the number of lines in the display
minus 1.
.LP
If \fItype\fP is omitted, then \fIcount\fP lines starting with the
specified line shall be written. Otherwise, \fIcount\fP
lines starting with the line specified by the \fItype\fP argument
shall be written.
.LP
The \fItype\fP argument shall change the lines to be written. The
possible values of \fItype\fP are as follows:
.TP 7
\fB-\fP
The specified line shall be decremented by the following value: 
.sp
.RS
.nf

\fB(((number of "-" characters) x\fP \fIcount\fP\fB) -1)
\fP
.fi
.RE
.LP
If the calculation would result in a number less than 1, it shall
be an error. Write lines from the edit buffer, starting at the
new value of line, until \fIcount\fP lines or the last line in the
edit buffer has been written.
.TP 7
\fB+\fP
The specified line shall be incremented by the following value: 
.sp
.RS
.nf

\fB(((number of "+" characters) -1) x\fP \fIcount\fP\fB) +1
\fP
.fi
.RE
.LP
If the calculation would result in a number greater than the last
line in the edit buffer, it shall be an error. Write lines
from the edit buffer, starting at the new value of line, until \fIcount\fP
lines or the last line in the edit buffer has been
written.
.TP 7
\fB=\fP,\fB.\fP
If more than a single \fB'.'\fP or \fB'='\fP is specified, it shall
be an error. The following steps shall be taken: 
.RS
.IP " 1." 4
If \fIcount\fP is zero, nothing shall be written.
.LP
.IP " 2." 4
Write as many of the \fIN\fP lines before the current line in the
edit buffer as exist. If \fIcount\fP or \fB'!'\fP was
specified, \fIN\fP shall be:
.sp
.RS
.nf

\fB(\fP\fIcount\fP \fB-1) /2
\fP
.fi
.RE
.LP
Otherwise, \fIN\fP shall be:
.sp
.RS
.nf

\fB(\fP\fIcount\fP \fB-3) /2
\fP
.fi
.RE
.LP
If \fIN\fP is a number less than 3, no lines shall be written.
.LP
.IP " 3." 4
If \fB'='\fP was specified as the type character, write a line consisting
of the smaller of the number of columns in the
display divided by two, or 40 \fB'-'\fP characters.
.LP
.IP " 4." 4
Write the current line.
.LP
.IP " 5." 4
Repeat step 3.
.LP
.IP " 6." 4
Write as many of the \fIN\fP lines after the current line in the edit
buffer as exist. \fIN\fP shall be defined as in step 2.
If \fIN\fP is a number less than 3, no lines shall be written. If
\fIcount\fP is less than 3, no lines shall be written.
.LP
.RE
.TP 7
\fB^\fP
The specified line shall be decremented by the following value: 
.sp
.RS
.nf

\fB(((number of "^" characters) +1) x\fP \fIcount\fP\fB) -1
\fP
.fi
.RE
.LP
If the calculation would result in a number less than 1, it shall
be an error. Write lines from the edit buffer, starting at the
new value of line, until \fIcount\fP lines or the last line in the
edit buffer has been written.
.sp
.LP
\fICurrent line\fP: Set to the last line written, unless the type
is \fB=\fP, in which case, set to the specified line.
.LP
\fICurrent column\fP: Set to non- .
.SS Escape
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB!\fP \fIcommand
\fP\fB[\fP\fIaddr\fP\fB]\fP\fB!\fP \fIcommand\fP
.fi
.RE
.sp
.LP
The contents of the line after the \fB'!'\fP shall have \fB'%'\fP
, \fB'#'\fP , and \fB'!'\fP characters expanded as
described in Command Line Parsing in ex . If the expansion causes
the text of the line to change, it
shall be redisplayed, preceded by a single \fB'!'\fP character.
.LP
The \fIex\fP utility shall execute the program named by the \fBshell\fP
edit option. It shall pass two arguments to the
program; the first shall be \fB-c\fP, and the second shall be the
expanded arguments to the \fB!\fP command as a single
argument.
.LP
If no lines are specified, the standard input, standard output, and
standard error of the program shall be set to the standard
input, standard output, and standard error of the \fIex\fP program
when it was invoked. In addition, a warning message shall be
written if the edit buffer has been modified since the last complete
write, and the \fBwarn\fP edit option is set.
.LP
If lines are specified, they shall be passed to the program as standard
input, and the standard output and standard error of the
program shall replace those lines in the edit buffer. Each line in
the program output (as delimited by s or the end
of the output if it is not immediately preceded by a ), shall
be a separate line in the edit buffer. Any occurrences
of  and  pairs in the output shall be treated
as single s. The specified lines
shall be copied into the unnamed buffer before they are replaced,
and the unnamed buffer shall become a line-mode buffer.
.LP
If in \fIex\fP mode, a single \fB'!'\fP character shall be written
when the program completes.
.LP
This command shall be affected by the \fBshell\fP and \fBwarn\fP edit
options. If no lines are specified, this command shall
be affected by the \fBautowrite\fP and \fBwriteany\fP edit options.
If lines are specified, this command shall be affected by the
\fBautoprint\fP edit option.
.LP
\fICurrent line\fP:
.IP " 1." 4
If no lines are specified, unchanged.
.LP
.IP " 2." 4
Otherwise, set to the last line read in, if any lines are read in.
.LP
.IP " 3." 4
Otherwise, set to the line before the first line of the lines specified,
if that line exists.
.LP
.IP " 4." 4
Otherwise, set to the first line of the edit buffer if the edit buffer
is not empty.
.LP
.IP " 5." 4
Otherwise, set to zero.
.LP
.LP
\fICurrent column\fP: If no lines are specified, unchanged. Otherwise,
set to non- .
.SS Shift Left
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fB<\fP\fB[\fP\fB< ...\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Shift the specified lines to the start of the line; the number of
column positions to be shifted shall be the number of command
characters times the value of the \fBshiftwidth\fP edit option. Only
leading s shall be deleted or changed into other
s in shifting; other characters shall not be affected.
.LP
Lines to be shifted shall be copied into the unnamed buffer, which
shall become a line-mode buffer.
.LP
This command shall be affected by the \fBautoprint\fP edit option.
.LP
\fICurrent line\fP: Set to the last line in the lines specified.
.LP
\fICurrent column\fP: Set to non- .
.SS Shift Right
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fB>\fP\fB[\fP\fB> ...\fP\fB][\fP\fIcount\fP\fB][\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
Shift the specified lines away from the start of the line; the number
of column positions to be shifted shall be the number of
command characters times the value of the \fBshiftwidth\fP edit option.
The shift shall be accomplished by adding s
as a prefix to the line or changing leading s into other s.
Empty lines shall not be changed.
.LP
Lines to be shifted shall be copied into the unnamed buffer, which
shall become a line-mode buffer.
.LP
This command shall be affected by the \fBautoprint\fP edit option.
.LP
\fICurrent line\fP: Set to the last line in the lines specified.
.LP
\fICurrent column\fP: Set to non- .
.SS -D
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB-D
\fP
.fi
.RE
.sp
.LP
Write the next \fIn\fP lines, where \fIn\fP is the minimum of the
values of the \fBscroll\fP edit option and the number of
lines after the current line in the edit buffer. If the current line
is the last line of the edit buffer it shall be an error.
.LP
\fICurrent line\fP: Set to the last line written.
.LP
\fICurrent column\fP: Set to non- .
.SS Write Line Number
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI1addr\fP\fB]\fP \fB=\fP \fB[\fP\fIflags\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIline\fP is not specified, it shall default to the last line
in the edit buffer. Write the line number of the specified
line.
.LP
\fICurrent line\fP: Unchanged.
.LP
\fICurrent column\fP: Unchanged.
.SS Execute
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB[\fP\fI2addr\fP\fB]\fP \fB@\fP \fIbuffer\fP\fB[\fP\fI2addr\fP\fB]\fP \fB*\fP \fIbuffer\fP
.fi
.RE
.sp
.LP
If no buffer is specified or is specified as \fB'@'\fP or \fB'*'\fP
, the last buffer executed shall be used. If no
previous buffer has been executed, it shall be an error.
.LP
For each line specified by the addresses, set the current line ( \fB'.'\fP
) to the specified line, and execute the contents
of the named \fIbuffer\fP (as they were at the time the \fB@\fP command
was executed) as \fIex\fP commands. For each line of a
line-mode buffer, and all but the last line of a character-mode buffer,
the \fIex\fP command parser shall behave as if the line
was terminated by a .
.LP
If an error occurs during this process, or a line specified by the
addresses does not exist when the current line would be set
to it, or more than a single line was specified by the addresses,
and the contents of the edit buffer are replaced (for example, by
the \fIex\fP \fB:edit\fP command) an error message shall be written,
and no more commands resulting from the execution of this
command shall be processed.
.LP
\fICurrent line\fP: As specified for the individual \fIex\fP commands.
.LP
\fICurrent column\fP: As specified for the individual \fIex\fP commands.
.SS Regular Expressions in ex
.LP
The \fIex\fP utility shall support regular expressions that are a
superset of the basic regular expressions described in the
Base Definitions volume of IEEE\ Std\ 1003.1-2001, Section 9.3, Basic
Regular Expressions. A null regular expression ( \fB"//"\fP ) shall
be equivalent to the last regular expression
encountered.
.LP
Regular expressions can be used in addresses to specify lines and,
in some commands (for example, the \fBsubstitute\fP
command), to specify portions of a line to be substituted.
.LP
The following constructs can be used to enhance the basic regular
expressions:
.TP 7
\fB\\<\fP
Match the beginning of a \fIword\fP. (See the definition of \fIword\fP
at the beginning of Command
Descriptions in ex .)
.TP 7
\fB\\>\fP
Match the end of a \fIword\fP.
.TP 7
\fB~\fP
Match the replacement part of the last \fBsubstitute\fP command. The
tilde ( \fB'~'\fP ) character can be escaped in a
regular expression to become a normal character with no special meaning.
The backslash shall be discarded.
.sp
.LP
When the editor option \fBmagic\fP is not set, the only characters
with special meanings shall be \fB'^'\fP at the beginning
of a pattern, \fB'$'\fP at the end of a pattern, and \fB'\\'\fP .
The characters \fB'.'\fP , \fB'*'\fP , \fB'['\fP ,
and \fB'~'\fP shall be treated as ordinary characters unless preceded
by a \fB'\\'\fP ; when preceded by a \fB'\\'\fP
they shall regain their special meaning, or in the case of backslash,
be handled as a single backslash. Backslashes used to escape
other characters shall be discarded.
.SS Replacement Strings in ex
.LP
The character \fB'&'\fP ( \fB'\\&'\fP if the editor option \fBmagic\fP
is not set) in the replacement string shall
stand for the text matched by the pattern to be replaced. The character
\fB'~'\fP ( \fB'\\~'\fP if \fBmagic\fP is
not set) shall be replaced by the replacement part of the previous
\fBsubstitute\fP command. The sequence \fB'\\n'\fP , where
\fIn\fP is an integer, shall be replaced by the text matched by the
pattern enclosed in the \fIn\fPth set of parentheses
\fB'\\('\fP and \fB'\\)'\fP .
.LP
The strings \fB'\\l'\fP , \fB'\\u'\fP , \fB'\\L'\fP , and \fB'\\U'\fP
can be used to modify the case of elements in the
replacement string (using the \fB'\\&'\fP or \fB"\\"\fP digit) notation.
The string \fB'\\l'\fP ( \fB'\\u'\fP ) shall
cause the character that follows to be converted to lowercase (uppercase).
The string \fB'\\L'\fP ( \fB'\\U'\fP ) shall cause
all characters subsequent to it to be converted to lowercase (uppercase)
as they are inserted by the substitution until the string
\fB'\\e'\fP or \fB'\\E'\fP , or the end of the replacement string,
is encountered.
.LP
Otherwise, any character following a backslash shall be treated as
that literal character, and the escaping backslash shall be
discarded.
.LP
An example of case conversion with the \fBs\fP command is as follows:
.sp
.RS
.nf

\fB:\fP\fBp
\fP\fBThe cat sat on the mat.
:\fP\fBs/\\<.at\\>/\\u&/gp
\fP\fBThe Cat Sat on the Mat.
:\fP\fBs/S\\(.*\\)M/S\\U\\1\\eM/p
\fP\fBThe Cat SAT ON THE Mat.\fP
.fi
.RE
.SS Edit Options in ex
.LP
The \fIex\fP utility has a number of options that modify its behavior.
These options have default settings, which can be
changed using the \fBset\fP command.
.LP
Options are Boolean unless otherwise specified.
.SS autoindent, ai
.LP
[Default \fIunset\fP]
.LP
If \fBautoindent\fP is set, each line in input mode shall be indented
(using first as many s as possible, as
determined by the editor option \fBtabstop\fP, and then using s)
to align with another line, as follows:
.IP " 1." 4
If in open or visual mode and the text input is part of a line-oriented
command (see the EXTENDED DESCRIPTION in \fIvi\fP ), align to the
first column.
.LP
.IP " 2." 4
Otherwise, if in open or visual mode, indentation for each line shall
be set as follows:
.RS
.IP " a." 4
If a line was previously inserted as part of this command, it shall
be set to the indentation of the last inserted line by
default, or as otherwise specified for the -D character in
\fIInput Mode Commands
in vi\fP .
.LP
.IP " b." 4
Otherwise, it shall be set to the indentation of the previous current
line, if any; otherwise, to the first column.
.LP
.RE
.LP
.IP " 3." 4
For the \fIex\fP \fBa\fP, \fBi\fP, and \fBc\fP commands, indentation
for each line shall be set as follows:
.RS
.IP " a." 4
If a line was previously inserted as part of this command, it shall
be set to the indentation of the last inserted line by
default, or as otherwise specified for the \fIeof\fP character in
Scroll .
.LP
.IP " b." 4
Otherwise, if the command is the \fIex\fP \fBa\fP command, it shall
be set to the line appended after, if any; otherwise to
the first column.
.LP
.IP " c." 4
Otherwise, if the command is the \fIex\fP \fBi\fP command, it shall
be set to the line inserted before, if any; otherwise to
the first column.
.LP
.IP " d." 4
Otherwise, if the command is the \fIex\fP \fBc\fP command, it shall
be set to the indentation of the line replaced.
.LP
.RE
.LP
.SS autoprint, ap
.LP
[Default \fIset\fP]
.LP
If \fBautoprint\fP is set, the current line shall be written after
each \fIex\fP command that modifies the contents of the
current edit buffer, and after each \fBtag\fP command for which the
tag search pattern was found or tag line number was valid,
unless:
.IP " 1." 4
The command was executed while in open or visual mode.
.LP
.IP " 2." 4
The command was executed as part of a \fBglobal\fP or \fBv\fP command
or \fB@\fP buffer execution.
.LP
.IP " 3." 4
The command was the form of the \fBread\fP command that reads a file
into the edit buffer.
.LP
.IP " 4." 4
The command was the \fBappend\fP, \fBchange\fP, or \fBinsert\fP command.
.LP
.IP " 5." 4
The command was not terminated by a .
.LP
.IP " 6." 4
The current line shall be written by a flag specified to the command;
for example, \fBdelete #\fP shall write the current line
as specified for the flag modifier to the \fBdelete\fP command, and
not as specified by the \fBautoprint\fP edit option.
.LP
.SS autowrite, aw
.LP
[Default \fIunset\fP]
.LP
If \fBautowrite\fP is set, and the edit buffer has been modified since
it was last completely written to any file, the contents
of the edit buffer shall be written as if the \fIex\fP \fBwrite\fP
command had been specified without arguments, before each
command affected by the \fBautowrite\fP edit option is executed. Appending
the character \fB'!'\fP to the command name of any
of the \fIex\fP commands except \fB'!'\fP shall prevent the write.
If the write fails, it shall be an error and the command
shall not be executed.
.SS beautify, bf
.LP
[Default \fIunset\fP]
.LP
If \fBbeautify\fP is set, all non-printable characters, other than
s, s, and s,
shall be discarded from text read in from files. 
.SS directory, dir
.LP
[Default \fIimplementation-defined\fP]
.LP
The value of this option specifies the directory in which the editor
buffer is to be placed. If this directory is not writable
by the user, the editor shall quit.
.SS edcompatible, ed
.LP
[Default \fIunset\fP]
.LP
Causes the presence of \fBg\fP and \fBc\fP suffixes on substitute
commands to be remembered, and toggled by repeating the
suffixes.
.SS errorbells, eb
.LP
[Default \fIunset\fP]
.LP
If the editor is in \fIex\fP mode, and the terminal does not support
a standout mode (such as inverse video), and
\fBerrorbells\fP is set, error messages shall be preceded by alerting
the terminal.
.SS exrc
.LP
[Default \fIunset\fP]
.LP
If \fBexrc\fP is set, \fIex\fP shall access any \fB.exrc\fP file in
the current directory, as described in Initialization in ex and vi
\&. If \fBexrc\fP is not set, \fIex\fP shall ignore any \fB.exrc\fP
file in the
current directory during initialization, unless the current directory
is that named by the \fIHOME\fP environment variable.
.SS ignorecase, ic
.LP
[Default \fIunset\fP]
.LP
If \fBignorecase\fP is set, characters that have uppercase and lowercase
representations shall have those representations
considered as equivalent for purposes of regular expression comparison.
.LP
The \fBignorecase\fP edit option shall affect all remembered regular
expressions; for example, unsetting the \fBignorecase\fP
edit option shall cause a subsequent \fIvi\fP \fBn\fP command to search
for the last basic
regular expression in a case-sensitive fashion.
.SS list
.LP
[Default \fIunset\fP]
.LP
If \fBlist\fP is set, edit buffer lines written while in \fIex\fP
command mode shall be written as specified for the
\fBprint\fP command with the \fBl\fP flag specified. In open or visual
mode, each edit buffer line shall be displayed as
specified for the \fIex\fP \fBprint\fP command with the \fBl\fP flag
specified. In open or visual text input mode, when the
cursor does not rest on any character in the line, it shall rest on
the \fB'$'\fP marking the end of the line.
.SS magic
.LP
[Default \fIset\fP]
.LP
If \fBmagic\fP is set, modify the interpretation of characters in
regular expressions and substitution replacement strings (see
Regular Expressions in ex and Replacement Strings in ex ).
.SS mesg
.LP
[Default \fIset\fP]
.LP
If \fBmesg\fP is set, the permission for others to use the \fBwrite\fP
or \fBtalk\fP commands to write to the terminal shall
be turned on while in open or visual mode. The shell-level command
\fImesg\fP \fBn\fP shall
take precedence over any setting of the \fIex\fP \fBmesg\fP option;
that is, if \fBmesg y\fP was issued before the editor
started (or in a shell escape), such as:
.sp
.RS
.nf

\fB:!mesg y
\fP
.fi
.RE
.LP
the \fBmesg\fP option in \fIex\fP shall suppress incoming messages,
but the \fBmesg\fP option shall not enable incoming
messages if \fBmesg n\fP was issued.
.SS number, nu
.LP
[Default \fIunset\fP]
.LP
If \fBnumber\fP is set, edit buffer lines written while in \fIex\fP
command mode shall be written with line numbers, in the
format specified by the \fBprint\fP command with the \fB#\fP flag
specified. In \fIex\fP text input mode, each line shall be
preceded by the line number it will have in the file.
.LP
In open or visual mode, each edit buffer line shall be displayed with
a preceding line number, in the format specified