ex(1)ex(1)NAME
ex, edit - extended line-oriented text editor
SYNOPSIS
tag] size] command] [file ...]
UNIX Standard Synopsis
command] tag] size] [file ...]
Obsolescent Options
command] tag] size] [file ...]
tag] size] command] [file ...]
Remarks
The program names and are separate personalities of the same program.
This manual entry describes the behavior of the personality. On many
HP-UX and other similar systems, is a synonym for
DESCRIPTION
The program is the line-oriented personality of a text editor that also
supports screen-oriented editing (see vi(1)).
(UNIX Standard only, see standards(5)) Certain block-mode terminals do
not have all the capabilities necessary to support the complete defini‐
tion, such as the full-screen editing commands (mode or mode). When
these commands cannot be supported on such terminals, this condition
shall neither produce an error message such as "not an editor command"
nor report a syntax error.
The program is identical to except that some editor option defaults are
altered to make the editor somewhat friendlier for beginning and casual
users (see Editor Options below).
Options and Arguments
recognizes the following command-line options and arguments:
(Obsolescent) Suppress all interactive-user feedback. This is useful
when editor commands are taken from scripts.
(UNIX Standard only, see
standards(5))
Suppress all interactive-user feedback. This is useful when
editor commands are taken from scripts.
Ignore the value of the and any implementation terminal type and
assume the terminal is a type incapable of supporting visual
mode.
Suppress the use of the environment variable and the reading of
the file.
Set the
editor option (see Editor Options below).
Recover the specified
files after an editor or system crash. If no file is specified,
a list of all saved files is printed. You must be the owner of
the saved file in order to recover it (superuser cannot recover
files owned by other users).
Set the
editor option to prevent overwriting a file inadvertently (see
Editor Options below).
(UNIX Standard only, see
standards(5)) Edit the file containing the specified tag and
proceed as if the first command were tag. The tags represented
by the tag and the command is optional. It shall be provided on
any system that also provides a confirming implementation of
Otherwise, the use of the produces undefined results.
Execute the tag command to load and position a predefined file.
See the command in Command Descriptions and the editor option in
Editor Options below.
Invoke visual mode
Set the value of the
editor option to size (see Editor Options below). If size is
omitted, it defaults to
Set encryption mode.
You are prompted for a key to initiate the creation or editing
of an encrypted file (see the command in Command Descriptions
below).
Encryption option. Same as the
option, except that all text read in is assumed to have been
encrypted.
(UNIX Standard only, see
standards(5))
(Obsolescent)
Begin editing by executing the specified search or positioning
command.
file Specify the file or files to be edited. If more than one file
is specified, they are processed in the order given. If the
option is also specified, the files are read from the recovery
area.
(UNIX Standard only, see standards(5)) If both the tag and command
options are given, the tag shall be processed first;i.e, the file con‐
taining the tag is selected by the and then the command is executed.
Definitions
The name of the file being edited by is called the current file. Text
from the current file is read into a work area, and all editing changes
are performed on this work area. Changes do not affect the original
file until the work area is explicitly written back to the file. If
the character is used as a file name, it is replaced by the current
file name.
The alternate file is the name of the last file mentioned in an editor
command, or the previous current file name if the last file mentioned
becomes the current file. If the character is used as a file name, it
is replaced by the alternate file name.
Twenty-six buffers named through can be used for saving blocks of text
during the edit. If the buffer name is specified in uppercase, text is
appended to the existing buffer contents rather than overwriting it.
The flag can be cleared from within the editor by setting the editor
option (see Editor Options below). Writing to a different file is
allowed even when the flag is set. Also, a write can be forced to a
file by using after the write command (see the command in Command
Descriptions below).
If an interrupt signal is received, and commands are being supplied
from a keyboard, returns to command mode. If editor commands are com‐
ing from a file, an interrupt signal causes to abort.
If the system crashes or aborts due to an internal error or unexpected
signal, attempts to preserve the work area if any unwritten changes
were made. Use the command-line option to retrieve the saved changes.
starts up in command mode, as indicated by the colon prompt. switches
to input mode whenever an or command is encountered. To terminate
input mode and return to command mode, type a period alone at the
beginning of a line.
Command lines beginning with a quotation mark () are ignored (this is
useful for placing comments in an editor script).
can be combined on a single line by separating them with a vertical bar
character However, global commands, comments, and the shell escape com‐
mand must be the last command on a line because they cannot be termi‐
nated by a character.
Addressing
(UNIX Standard only, see standards(5)) Addressing in relates to the
current line. In general, the current line shall be the last line
affected by the command; the exact effect on the current line is dis‐
cussed under the description of each command. When the buffer contains
no lines, the current line shall be set to zero.
recognizes the following line address forms:
Dot or period refers to the current line. There is always a
current line whose position can be the result of
an explicit movement command or the result of a
command that affects multiple lines (in which
case it is usually the last line affected).
n The nth line in the work area. Lines are num‐
bered sequentially, starting at line 1.
The last line in the work area.
Abbreviation for
meaning the entire work area.
An offset relative to the current line or the pre‐
ceding line specification.
means forward; means backward. For
example, the forms and are equiva‐
lent.
The line containing the pattern
re, scanning forward
or backward The
trailing or can be
omitted if the line
is only being dis‐
played. If re is
omitted, uses the
more recently set of
either the scanning
string or the substi‐
tution string (see
Regular Expressions
below).
Lines can be marked using single
lowercase letters (see the
command in Command
Descriptions below).
refers to the line
marked with x. In
addition, the previ‐
ous current line is
marked before each
nonrelative motion.
This line can be
referred to by using
for x (thus refers to
the previous current
line).
(UNIX Standard only,
see standards(5))
Commands require
zero, one or two
addresses. Commands
that require zero
addresses shall
regard the presence
of an address as an
error.
(UNIX Standard only, see standards(5))
Adjacent address in a shall be separated
from each other by a comma (,) or a semi‐
colon(;). In the latter case, the current
line(.) shall be set to the first address,
and only then is the second address calcu‐
lated. This feature can be ued to determine
the starting line for forwards and back‐
wards searches. The second address of any
two-address sequence shall correspond to
the first address. The first address shall
be less than or equal to the second
address. The first address shall be greater
than or equal to the first line of the
editing buffer, and the last address shall
be less than or equal to the last line of
the editing buffer. Any other case shall
be an error.
Addresses for commands consist of a series
of line addresses (specified as above),
separated by a comma or semicolon Such
address lists are evaluated left-to-right.
When the separator is a semicolon, the cur‐
rent line is set to the value of the previ‐
ous address before the next address is
interpreted. If more addresses are given
than the command requires, then all but the
last one or two are ignored. Where a com‐
mand requires two addresses, the first line
addressed must precede the second one in
the work area. A null (missing) address in
a list defaults to the current line.
Regular Expression
The editor maintains copies of two regular
expression strings at all times: the sub‐
stitution string, and the scanning string.
The substitute command sets the substitu‐
tion string to the regular expression used.
Both the global-command and the regular-
expression form of line addressing (see
Addressing above) for all commands set the
scanning string to the regular expression
used. These strings are used as default
regular expressions as described under
Addressing, the command, and the command.
The editor supports Basic Regular Expres‐
sions (see regexp(5)) with the following
modifications:
The matches the beginning of
a "word"; that is, the
matched string must
begin in a letter,
digit, or underline, and
must be preceded by the
beginning of the line or
a character other than
the above. This con‐
struct can only be used
at the beginning of a
regular expression (as
in \<word), but not in
the middle (word1
\<word2).
The matches the end of a
"word" (see previous
paragraph). This con‐
struct can only be used
at the end of a regular
expression (as in
word\>), but not in the
middle (word1\> word2).
Match the replacement part of the
last
command.
The positional quoting within
bracket expressions defined by Basic
Regular Expressions is
replaced by the use of
the backslash to quote
bracket-expression spe‐
cial characters.
When the editor option
is set, the only charac‐
ters with special mean‐
ings are at the begin‐
ning of a pattern, at
the end of a pattern,
and \. The characters
., *, and lose their
special meanings unless
escaped by a
Replacement Strings
The character in the replacement string
stands for the text matched by the pattern
to be replaced. Use if the editor option
is set.
The character is replaced by the replace‐
ment part of the previous command. Use if
the editor option is set.
The sequence where n is an integer, is
replaced by the text matched by the subpat‐
tern enclosed in the nth set of parentheses
and
The sequence (causes the immediately fol‐
lowing character in the replacement to be
converted to uppercase (lowercase), if the
character is a letter. The sequence (turns
case conversion on, until the sequence or
is encountered, or the end of the replace‐
ment string is reached.
Command Names and Abbreviations
The following table summarizes the line-
mode commands. The commands whose names
are enclosed in parentheses are available
only in their abbreviated forms.
┌────────────────────┬───────────────────────┬──────────────────────────┐
│Command Abbr. │ Command Abbr. │ Command Abbr. │
├────────────────────┼───────────────────────┼──────────────────────────┤
│abbreviate ab │ next n │ tag ta │
│append a │ number nu # │ unabbreviate una │
│args ar │ open o │ undo u │
│change c │ pop │ unmap unm │
│chdir chd cd │ preserve pre │ version ve │
├────────────────────┼───────────────────────┼──────────────────────────┤
│copy co t │ print p │ visual vi │
│crypt cr X │ put pu │ write w wq │
│delete d │ quit q │ xit x │
│edit e ex │ read r │ yank ya │
│file f │ recover rec │ │
├────────────────────┼───────────────────────┼──────────────────────────┤
│global g v │ rewind rew │ (execute buffer) * @ │
│insert i │ set se │ (line number) = │
│join j │ shell sh │ (left shift) < │
│list l │ source so │ (right shift) > │
│map │ stop st ^Z │ (scroll) ^D │
├────────────────────┼───────────────────────┼──────────────────────────┤
│mark ma k │ substitute s sr & ~ │ (shell escape) ! │
│move m │ suspend su ^Z │ (window) z │
└────────────────────┴───────────────────────┴──────────────────────────┘
Command Descriptions
In the following command descriptions, some
arguments appear frequently. They are
described below.
line A single line address, in
any of the forms described
in Addressing above. The
default is the current
line.
range A pair of line addresses
separated by a comma or
semicolon, as described in
Addressing above. The
default is the current
line
count A positive integer speci‐
fying the number of lines
to be affected by the com‐
mand. The default is 1 or
the number of lines in
range.
When count is specified,
range is ineffective.
Instead, only a line num‐
ber should be specified to
indicate the first line
affected by the command.
(If a range is given, the
last line of the range is
interpreted as the start‐
ing line for the command.)
flags One or more of the charac‐
ters and The corresponding
command to print the line
is executed after the com‐
mand completes. Any num‐
ber of or characters can
also be given with these
flags. The default is no
flags.
These modifiers are all optional.
When only a line or a range is specified
(with a null command), the implied command
is If a null line is entered, the next line
is printed (equivalent to
buffer (UNIX Standard only, see
standards(5)) One of a
number of named areas for
saving text. The named
buffers are specified by
the lowercase letters of
the POSIX locale. Specify‐
ing shall cause the area
of the text affected by
the command to be stored
into the buffer as it was
before the command took
effect. This argument is
also used on the command
and the visual mode "put"
commands to specify the
buffer that shall provide
the text to insert.
If the buffer name is
specified in uppercase,
and the buffer is to be
modified, the buffer shall
be appended to rather than
being overwritten. If the
buffer is not to be modi‐
fied, the buffer name can
be specified in lowercase
or uppercase with the same
results. There shall be
also one unnamed buffer,
which is the repository
for all text deleteed or
yanked when no buffer is
specified.
There are also numbered
buffers, 1 through 9,
which shall be accessible
only from visual mode.
These buffers are special
in that, in the visual
mode, when deleted text is
placed in the unnamed buf‐
fer, it also shall be
placed in buffer 1, the
previous contents buffer 1
shall be placed in buffer
2 and so on. Any text in
the buffer 9 shall be
lost. Text that is yanked
into the unnamed buffer
shall not modify the num‐
bered buffers. Text can‐
not be placed directly
into the numbered
buffered, although it can
be retrieved from them by
using a visual mode "put"
command with the buffer
name given as s number.
When the buffer modifier
is not used in the com‐
mands below, the unnamed
buffer shall be the
default.
word (UNIX Standard only, see
standards(5)) In the POSIX
Locale, a consists of a
maximal sequence of let‐
ters, digits and under‐
scores, delimited at both
ends by characters other
than letters, digits, or
underscores, or by the
beginning or end of a word
or the file. A character
that can be appended to
the command to modify its
operation, as detailed in
the individual command
descriptions.
If both a and is specified
for a command that uses
them, the number of lines
affected shall be taken
from the value rather than
the The starting line for
the command shall be taken
to be the first line
addressed by the range.
When only a or is speci‐
fied with no command, the
implied command shall be
either or ( or The command
selected shall be the last
of these three commands to
be used. When no range or
count is specified and the
command line is a blank
line, the current line
shall be written, and the
current line shall be set
to
Zero or mode <blank> char‐
acters can precede or fol‐
low the addresses, count
or command name. Any
object following a command
name (such as buffer, file
etc) that begins with an
alphabetic character shall
be separated from the com‐
mand name with at least
one <blank>.
For each of the commands listed below, the
command can be entered as the abbreviation
(those characters in the Synopsis command
word preceding the [), the full command
(all characters shown for the command word,
omitting the [ and ]), or any subset of the
characters of the full command down to the
abbreviation.
word replacement
Add the named abbrevia‐
tion to the current list.
In visual mode, if word
is typed as a complete
word during input, it is
replaced by the string
replacement.
line
Enter input mode; the
input text is placed
after the specified line.
If line 0 is specified,
the text is placed at the
beginning of the work
area. The last input
line becomes the current
line, or the target line
if no lines are input.
Appending to the command
toggles the editor option
setting for this insert
only.
Prints the argu‐
ment, placing the
current argument
between
and
range count
Enter input mode; the
input text replaces the
specified lines. The
last input line becomes
the current line; if no
lines are input, the
effect is the same as a
delete.
Appending to the command
toggles the editor option
setting for this insert
only.
directory]
directory]
Change the working direc‐
tory to directory. If
directory is omitted, the
value of the environment
variable is used. If the
work area has been modi‐
fied since the last write
and the name of the file
being edited does not
begin with a slash a
warning is issued and the
working directory is not
changed. To force a
change of directory in
this case, append the
character to the command.
range line flags
A copy of the specified
lines (range) is placed
after the specified des‐
tination line; line 0
specifies that the lines
are to be placed at the
beginning of the work
area. (The letter is an
alternative abbreviation
for the command.)
The user is
prompted for a key
with which to
enter encryption
mode.
This command can also be
used to change the key
entered from a previous
command or the command
line option. If no key
is supplied in response
to the prompt (that is,
only carriage return is
pressed), encryption mode
is canceled and the work
area is written out in
plain-text form by subse‐
quent write commands.
While in encryption mode,
all file input is
decrypted using the cur‐
rent key. However, while
an input file is being
processed, if a block of
text (approximately 1024
bytes) is encountered
that contains only 7-bit
ASCII characters, that
block of text is assumed
to be plain-text and is
not decrypted. All file
output, except that piped
via a shell escape to
another command, is
encrypted using the cur‐
rent key.
The temporary file used
by the editor to manage
the work area is not
encrypted until the cur‐
rent work area is dis‐
carded (or written out)
and editing begins on a
new file. When creating
a new file that requires
encryption protection,
ensure that the work area
file is also encrypted by
specifying the option
when invoking the editor.
Encryption option. Same
as the command, except
that all text read in is
assumed to have been
encrypted.
range buffer count
The specified lines are
deleted from the work
area. If a named buffer
is specified, the deleted
text is saved in it. If
no buffer is specified,
the unnamed buffer is
used (that is, the buffer
where the most recently
deleted or yanked text is
placed by default). The
new current line is the
line after the deleted
lines or the last line of
the file if the deleted
lines were at the end of
the file.
line] file
line] file
Begin editing a new file
is an alternative name
for the command). If the
current work area has
been modified since the
last write, a warning is
printed and the command
is aborted. This action
can be overridden by
appending the character
to the command file).
The current line is the
last line of the work
area unless it is exe‐
cuted from within vi, in
which case the current
line is the first line of
the work area. If the
option is specified, the
current line is set to
the specified position,
where line can be a num‐
ber (or or specified as
or
Print the current
file name and
other information,
including the num‐
ber
of lines and the current
position.
range command...
range command...
Perform command on lines
within range (or on the
entire work area if no
range is given) that con‐
tain re. First mark the
lines within the given
range that match the pat‐
tern re. If the pattern
is omitted, the more
recently set of either
the substitution string
or the scanning string is
used (see Regular Expres‐
sions above). Then the
given commands are exe‐
cuted with set to each
marked line. Any charac‐
ter other than a letter
or a digit can be used to
delimit the pattern
instead of the
command can be specified
on multiple lines by hid‐
ing new-lines with a
backslash. If command is
omitted, each line is
printed. and commands
are allowed; the termi‐
nating dot can be omitted
if it ends command or
commands. The command is
also permitted (unless
the command itself has
been issued from visual
mode), and takes input
from the terminal. (If
command contains a vis‐
ual-mode command (that
is, or the visual-mode
command must be termi‐
nated by the visual-mode
command in order to pro‐
ceed to the next marked
line.)
The command itself and
the command are not
allowed in command. The
editor options and are
inhibited.
Appending a to the com‐
mand (that is, or using
the alternate name causes
command to be run on the
lines within range that
do not match the pattern.
line
Enter input mode; the
input text is placed
before the specified
line. The last line
input becomes the current
line, or the line before
the target line, if no
lines are input.
Appending to the command
toggles the editor option
setting for this insert
only.
range count flags
Join together the text
from the specified lines
into one line. White
space is adjusted to pro‐
vide at least one blank
character (two if a
period appears at the end
of a line, or none if the
first character of a line
is a closing parenthesis
Extra white space at the
beginning of a line is
discarded.
Appending a to the com‐
mand causes a simpler
join with no white-space
processing.
range ount flags
Print the specified lines
with tabs displayed as
and the end of each line
marked with a trailing
(The only useful flag is
for line numbers.) The
last line printed becomes
the current line.
key| n action
key|n action
The and commands define
macros for use in visual
mode. The first argu‐
ment, key, can be a sin‐
gle character or a multi‐
character sequence. In
the special sequence, n
is a digit referring to
the function key n. Spe‐
cial characters, white‐
space, and newline must
be escaped with a to be
entered in the arguments.
The key argument cannot
contain a colon as its
first character, nor can
a multicharacter sequence
begin with an alphabetic
character.
Macros defined by are
effective in visual com‐
mand mode. Macros
defined by are effective
in visual input mode.
When key or the function
key corresponding to is
entered, the editor
interprets the operation
as though action were
typed.
The or command without
options displays the cor‐
responding current list
of macros.
See also the editor
options and in Editor
Options below.
x
The specified line is
given the specified mark
x, which must be a single
lowercase letter x must
be preceded by a space or
tab. The current line
position is not affected.
is an alternate name for
range line
Move the specified lines
(range) to follow the
target line. The first
line moved becomes the
current line.
file ...]
The next file from the
command line argument
list is edited. Append‐
ing a to the command
overrides the warning
about the work area hav‐
ing been modified since
the last write (and dis‐
cards any changes unless
the editor option is
set). The argument list
can be replaced by speci‐
fying a new one on this
command line.
range count flags
(The character is an
alternative abbreviation
for the command.) Print
the lines, each preceded
by its line number (the
only useful flag is The
last line printed becomes
the current line.
line flags
Enter open mode, which is
similar to visual mode
with a one-line window.
All the visual-mode com‐
mands are available. If
a match is found in line
for the optional regular
expression, the cursor is
placed at the start of
the matching pattern.
Use the visual mode com‐
mand to exit from open
mode. For more informa‐
tion, see vi(1).
Load the file
whose name is
stored at the top
of the tag stack
and set the current line
to the stored location.
The top entry of the tag
stack is deleted. (The
current file name is
placed on the stack when
you execute the line mode
command or the visual
mode command.)
overrides the warning
about the work area hav‐
ing been modified since
the last write; any
changes are discarded
unless the editor option
is set).
The current editor
work area is saved
as if the system
had just crashed.
Use this command in emer‐
gencies, for example when
a write does not work and
the work area cannot be
saved in any other way.
Use the command-line
option to recover the
file. After the file has
been preserved, a mail
message shall be sent to
the user. The message
shall contain the name of
the file, the time of
preservation and an com‐
mand that could be used
to recover the file.
Additional information
may be included in the
mail message.
count
Print the specified
lines, with non-printing
characters printed as
control characters in the
form DEL is represented
as The last line printed
becomes the current line.
line buffer
Place deleted or "yanked"
lines after line. A buf‐
fer can be specified;
otherwise, the text in
the unnamed buffer (that
is, the buffer in which
deleted or yanked text is
placed by default) is
restored. The current
line indicator shall be
set to the first line put
back.
Terminate the
edit.
If the work area has been
modified since the last
write, a warning is
printed and the command
fails. To force termina‐
tion without preserving
changes, append to the
command.
line file
Place a copy of the spec‐
ified file in the work
area after the target
line (which can be line 0
to place text at the
beginning). If no file
is named, the current
file is the default. If
no current file exists,
file becomes the current
file. The last line read
becomes the current line
except in visual mode
where the first line read
becomes the current line.
If is given as string is
interpreted as a system
command and passed to the
command interpreter; the
resultant output is read
into the work area. A
blank or tab must precede
the
file
Recover file from the
save area, after an acci‐
dental hangup or a system
crash. If the current
work area has been modi‐
fied since the last
write, a warning is
printed and the command
is aborted. This action
can be overridden by
appending the character
to the command file).
The argument list
is rewound,
and the first file in the
list is edited. This
shall be equivalent to a
command with the current
argument list as its op‐
erands. If the current
buffer has been modified
since the last write, a
warning shall be written
and the command shall be
aborted. Any warnings
can be overridden by
appending a The current
indicator line shall be
affected by the editor
options, and
boolean-option
Set and display the val‐
ues of the editor options
(see Editor Options
below).
With no arguments, the
command prints those edi‐
tor options whose values
have been changed from
the default settings. If
is specified, it prints
all current option val‐
ues.
The second and third
forms display the current
value of the specified
option. The is necessary
only for Boolean options.
The fourth form turns a
Boolean option on. The
fifth form turns a Bool‐
ean option off.
The sixth form assigns
values to string and
numeric options. Spaces
and tabs in strings must
be escaped with a leading
backslash
The last five forms can
be combined; interpreta‐
tion is left-to-right.
Execute the com‐
mand interpreter
specified by the
editor option (see Editor
Options below). Editing
is resumed when you exit
from the command inter‐
preter.
file
Read and execute commands
from the specified file.
commands can be nested.
The maximum supported
nesting depths is imple‐
mentation defined, but
shall be at least one.
range options count flags
On each specified line,
the first instance of the
pattern re is replaced by
the string repl. (See
Regular Expressions and
Replacement Strings
above.) Any character
other than a letter or a
digit can be used to
delimit the pattern
instead of the
If you include the
(global) option, all
instances of the pattern
in the line are substi‐
tuted.
If you include the (con‐
firm) option, you are
queried about whether to
perform each individual
substitution, as follows:
Before each substitution
the line is displayed
with the pattern to be
replaced marked under‐
neath with carets Type to
cause the substitution to
be performed; any other
input to abort it. The
last line substituted
becomes the current line.
If the substitution pat‐
tern re is omitted the
more recently set of
either the substitution
string or the scanning
string is used (see Regu‐
lar Expressions above).
If the or forms of the
command are used, the
substitution pattern
defaults to the previous
substitution string and
the replacement string
defaults to the previous
replacement string used.
If the or forms of the
command are used, the
substitution pattern
defaults to the more
recently set of either
the substitution string
or the scanning string
and the replacement
string defaults to the
previous replacement
string used.
The form is equivalent to
where scan-re is the pre‐
vious scanning string.
The form is equivalent to
where subs-re is the pre‐
vious substitution
string.
susp
Suspend the editor
job and return to
the calling shell.
and susp are
equivalent to susp
is the user
process control
suspend character,
which is typically
the character
(ASCII SUB) (see
stty(1)). This
command is dis‐
abled if the call‐
ing shell does not
support job con‐
trol or has dis‐
abled it.
The work area is
written to the
current file
before the editor
is suspended if
the editor option
is set, the editor
option is not set,
and the work area
has been modified
since the last
write. To over‐
ride this action,
append the charac‐
ter to the or com‐
mand.
tag
Search the files
specified by the
editor option (see
Editor Options
below) sequen‐
tially until a tag
definition for tag
is found. If tag
is found, load the
associated file
into the work area
and set the cur‐
rent position to
the address speci‐
fied in the tag
definition.
The work area is
written to the
current file
before the new
file is loaded if
the new file is
different from the
current file, the
editor option is
set, the editor
option is not set,
and the work area
has been modified
since the last
write. To over‐
ride this action,
append the charac‐
ter to the com‐
mand.
If the editor
option is set, the
current file name
and line number is
pushed onto the
tag stack for
later recall with
the line mode com‐
mand or the visual
mode command.
word
Delete word from
the list of abbre‐
viations (see the
command above).
Reverse the
changes
made by the
previous
editing
command.
For this purpose,
and are considered
single commands.
Commands that
affect the exter‐
nal environment,
such as and cannot
be undone. An can
itself be
reversed.
key
The macro defini‐
tion for key is
removed (see the
command above).
Print the
current
version
information
for the
editor.
line type count flags
Enter visual mode
at the specified
line.
The type can be
one of the charac‐
ters or as in the
(window) command,
to specify the
position of the
specified line on
the screen window
The default is to
place the line at
the top of the
screen window.
A count specifies
an initial window
size; the default
is the value of
the editor option
The flags and
(ell) cause the
lines in the vis‐
ual window to be
displayed in the
corresponding mode
(see the and com‐
mands).
Use the command to
exit visual mode.
For more informa‐
tion, see vi(1).
[range] file
[range] file
Write the speci‐
fied lines (or the
entire work area,
if no range is
given) out to
file, printing the
number of lines
and characters
written. If file
is not specified,
the default is the
current file (the
command fails with
an error message
if there is no
current file and
no file is speci‐
fied).
If an alternate
file is specified
and the file
exists, the write
fails, but can be
forced by append‐
ing to the com‐
mand. To append
to an existing
file, append to
the command. If
the file does not
exist, an error is
reported.
If the file is
specified as
string is inter‐
preted as a system
command, the com‐
mand interpreter
is invoked, and
the specified
lines are passed
as standard input
to the command.
The command is
equivalent to a
followed by a is
equivalent to fol‐
lowed by is equiv‐
alent to followed
by
file
If changes have
been made to the
work area, a com‐
mand is executed
with any options
(such as or file)
used by the com‐
mand. Then (in
any case) the com‐
mand is executed.
range buffer count
Place the speci‐
fied lines in the
named buffer. If
no buffer is spec‐
ified, the unnamed
buffer is used
(that is, the buf‐
fer where the most
recently deleted
or yanked text is
placed by
default).
(execute buffer) [buffer]
[buffer]
Execute the con‐
tents of buffer as
an editor command.
buffer can be the
letter of a named
buffer or or The
and the forms of
this command are
equivalent. If a
buffer is not
specified or buf‐
fer is or the buf‐
fer last named in
a or command is
executed.
(line number)
Print the line
number of the
specified line.
The default is the
last line. The
current line posi‐
tion is not
affected.
(scroll)
Print the next n
lines, where n is
the value of the
editor option.
(shell escape)
Pass the remainder
of the line after
the to the system
command inter‐
preter for execu‐
tion. A warning
is issued if the
work area has been
changed since the
last write. A
single is printed
when the command
completes. The
current line posi‐
tion is not
affected.
Within the text of
command, and are
expanded as file
names, and is
replaced with the
text of the previ‐
ous command.
Thus, repeats the
previous command.
When such expan‐
sion is performed,
the expanded line
is echoed.
If you specify
range, the speci‐
fied lines are
passed to the com‐
mand interpreter
as standard input.
The output from
the command
replaces the spec‐
ified lines.
(shift left)
Shift the speci‐
fied lines to the
left. The number
of spaces to be
deleted is deter‐
mined by the edi‐
tor option Only
whitespace (blanks
and tabs) is lost
in shifting; other
characters are not
affected. The
last line changed
becomes the cur‐
rent line.
(shift right)
Shift the speci‐
fied lines to the
right by inserting
whitespace The
number of spaces
inserted is deter‐
mined by the edi‐
tor option The
last line changed
becomes the cur‐
rent line.
(window)
The number of
lines specified by
count are dis‐
played. The
default for count
is the value of
the editor option
If type is omit‐
ted, count lines
following the
specified line are
printed.
If type is speci‐
fied, it must be
one of the follow‐
ing characters:
Display a window
of lines following
the addressed
line.
Place the
addressed line
at the bot‐
tom of the
window of
displayed
lines.
Place the
addressed line at
the center of the
window.
Display a window
of lines
that is two
windows
prior to
the
addressed
line.
Display the
addressed line at
the center of the
window
with a line
of dashes
above and
below the
addressed
line.
The last line
printed becomes
the current line,
except for the
where the
addressed line
becomes the cur‐
rent line.
Editor Options
The command has a number of options
that modify its behavior. These
options have default settings, which
can be changed using the command
(see above). Options can also be
set at startup by putting a command
string in the environment variable
or in the file in the directory, or
in in the current directory. If
exists, the file in the directory is
not executed. If the current direc‐
tory is not the directory and the
editor option is set (see below),
the file in the current directory is
executed after or the directory
The editor obtains the horizontal
and vertical size of the terminal
screen from the database (see ter‐
minfo(4)). These values can be
overridden by setting the and envi‐
ronment variables. See the editor
option below for more information.
These values can also be changed to
adhere to the UNIX Standard environ‐
ment (see standards(5)).
The following table shows the
defaults that differ for the various
editor personalities:
│
Name │ Default Editor Options
──────┼─────────────────────────────────────────────────────────
edit │ nomagic novice noreadonly report=1 showmode
ex │ magic nonovice noreadonly report=5 noshowmode
vedit │ nomagic novice noreadonly report=1 showmode
vi │ magic nonovice noreadonly report=5 noshowmode
view │ magic nonovice readonly report=5 noshowmode
Editor options are Boolean unless
otherwise specified. Abbreviations
are shown in parentheses.
Indent each line in input mode
(using blanks
and tabs) to
align with the
previous line.
Indentation
begins after the
line appended,
or before the
line inserted or
the first line
changed. Addi‐
tional indenta‐
tion can be pro‐
vided as usual.
Succeeding lines
are automati‐
cally indented
to the new
alignment.
Reducing the
indent is
achieved by typ‐
ing one or more
times: the cur‐
sor is moved
back to the next
multiple of spa‐
ces for each A
followed by a
removes all
indentation tem‐
porarily for the
current line. A
followed by a
removes all
indentation.
Reversed by The
default is
The current line is printed after
each command that changes work area
text.
Autoprint is
suppressed in
commands.
Reversed by The
default is
The work area is written out to the
current file
if the work area
has been modi‐
fied and a or
command is
given. Reversed
by The default
is
Cause all control characters other
than tab,
newline, and
formfeed to be
discarded from
the input text.
Reversed by The
default is
Specify the directory in which the
editor work area should be placed.
This option only
takes effect
when a new work
area is created.
It should be set
in or to affect
the location of
the work area
file for the
edit file speci‐
fied on the com‐
mand line. The
default is
If the specified
directory is set
from or a file
and is not
writable by the
user, the editor
quits; if set
interactively by
the user, the
editor issues an
error message.
When set, two consecutive ESC
(escape) characters
are required to
leave input
mode. In input
mode, a single
ESC character
followed by a
different char‐
acter causes to
issue an audible
or visual warn‐
ing (see the
editor option)
and insert both
characters into
the work area.
Reversed by The
default is
The character
sequences trans‐
mitted by the
keyboard editing
keys of some
terminals are
identical to
some sequences
of user com‐
mands. If the
mapping of these
keys is enabled
(see the and
options), might
not be able to
reliably distin‐
guish between
the character
sequence trans‐
mitted by an
editing key and
the same charac‐
ter sequence
typed by a user.
This problem is
most likely to
occur when the
user types ESC
to terminate
input mode imme‐
diately followed
by another com‐
mand. If you
set the option,
the ambiguity of
this case is
removed.
Cause the presence of
and suffixes on
substitute com‐
mands to be
remembered, and
toggled by
repeating the
suffixes.
Reversed by The
default is
When set, error messages are pre‐
ceded with a bell
only on termi‐
nals that do not
support a stand‐
out or high‐
lighting mode
such as inverse
video. If the
terminal sup‐
ports highlight‐
ing, the bell is
never used prior
to error mes‐
sages and this
option has no
effect. Note
that visual-mode
errors are sig‐
naled by the
bell (regardless
of the setting
of this option)
without an
accompanying
error message.
Reversed by The
default is
When set, the file in the cur‐
rent directory
is processed
during editor
initialization
if the current
directory is not
the directory.
This option is
not set by
default and must
be set in the
environment
variable or the
directory file
to have any
effect. See the
Editor Options
introductory
text above.
Reversed by The
default is
When set, the screen flashes instead
of beeping,
provided an
appropriate
entry is present
in the database
for the terminal
being used.
Reversed by The
default is
Define the spacing between hardware
tab settings
and the number
of spaces used
by the system
when expanding
tab characters.
Tab stops are
placed in each
column number
(starting at the
left edge of the
screen) that
corresponds to
an integer mul‐
tiple of number.
The default is
All uppercase characters in the text
are mapped to
lowercase in
regular expres‐
sion matching.
Also, all upper‐
case characters
in regular
expressions are
mapped to lower‐
case, except in
character class
specifications.
Reversed by The
default is
When set, any keyboard editing key
mappings
that are loaded
automatically at
initialization
for command-mode
use are enabled.
If not set,
these mappings
are disabled
(but not
deleted). Use
the command to
get a list of
the currently
enabled command-
mode mappings.
Reversed by The
default is
When set, the keyboard editing key
mappings
automatically
loaded at ini‐
tialization for
input mode use
are enabled. If
not set, these
mappings are
disabled (but
not deleted).
Use the command
to list the cur‐
rently enabled
input-mode map‐
pings. Reversed
by The default
is for terminals
whose keyboard
editing keys
send HP-style
escape sequences
(an ESC followed
by a single let‐
ter). The
default is for
all other termi‐
nals.
Modify mode and the and
commands in vis‐
ual mode for
source code.
Reversed by The
default is
Display all printed lines with tabs
shown as
and the end of
line marked by a
Reversed by The
default is
Affect the interpretation of charac‐
ters in regular expressions
and substitution
replacement
strings (see
Regular Expres‐
sions and
Replacement
Strings above).
Reversed by The
and default is
The and default
is
Allows other users to use the
command (see
write(1)) to
send messages to
your terminal,
possibly dis‐
rupting the
screen display.
Unsetting this
option blocks
write permission
to your terminal
from other sys‐
tem users while
you are using
the editor.
Reversed by The
default is
If set when the editor reads in a
file, any
commands embed‐
ded in the first
five and last
five lines of
the file are
executed after
and commands are
processed but
before editing
control is given
to the user.
The commands
must be prefixed
by or and termi‐
nated by in a
single line.
Any number of
other characters
with the excep‐
tion of the
colon can pre‐
cede or follow
the embedded
command.
Reversed by The
default is
Use the version of the editor avail‐
able for novices, known as
or Reversed by
The and default
is The and
default is
Cause lines to be printed with line
numbers.
Reversed by The
default is
Suppress automatic carriage returns
on terminals
that do not sup‐
port direct cur‐
sor addressing.
This streamlines
text output in
certain situa‐
tions such as
when printing
multiple lines
that contain
leading white‐
space. Reversed
by The default
is
The value of this option is a string
whose successive
pairs of charac‐
ters specify the
names of text-
processing
macros that
begin para‐
graphs. (A
macro appears in
the text in the
form where the
is the first
character in the
line.)
If any macros
have a single-
character name,
use a space
character to
substitute for
the missing sec‐
ond character in
the name. To
type a space
character in
such situations,
precede the
space with a
backslash to
prevent the edi‐
tor from inter‐
preting it as a
delimiter.
The default is
When set, command mode input is
prompted for with a colon
when unset, no
prompt is dis‐
played.
Reversed by The
default is
Set the flag for the
file being
edited, thus
preventing acci‐
dental overwrit‐
ing at the end
of the session.
This option is
equivalent to
invoking or with
the option or
using the com‐
mand. Reversed
by The and
default is The
default is
Simulate an intelligent terminal on
a dumb terminal.
During input
mode, lines are
continuously
reprinted as
text is entered.
Since this is
likely to
require a large
amount of output
to the terminal,
it is useful
only at high
transmission
speeds. If is
set, lines are
reprinted only
when input mode
is terminated
and deleted
lines are marked
with an in the
left margin.
Reversed by The
default is
If set, macro translation allows for
macros defined in terms of
other macros;
translation con‐
tinues until the
final product is
obtained. If
unset, a one-
step translation
only is done.
Reversed by The
default is
The value of n gives the num‐
ber of lines
that must be
changed by a
command before a
report is dis‐
played on the
number of lines
affected. If n
is 5, then
changes are
reported for 6
or more lines.
The and default
is The and
default is
The value of n determines the
number of lines
scrolled by a
command and the
number of lines
displayed by the
command (twice
the value of
scroll). The
default is half
the value of the
option.
The value of this option is a
string,
in that succes‐
sive pairs of
characters spec‐
ify the names of
text-processing
macros that
begin sections.
See the editor
option above.
The default is
Set the file name of the shell to be
used for the
shell escape and
the command. It
defaults to the
value of your
environment
variable, if
set, and other‐
wise to
Sets the indentation step value used
by
and the shift
and commands.
The default is
In visual mode, jump momentarily to
the matching
or when you type
a or if the
match is still
on the screen.
Reversed by The
default is
Display the current editor mode
(such as
in the lower
right-hand cor‐
ner of the
screen during
visual and open
mode. Reversed
by The and
default is The
and default is
In visual mode, prevents screen
updates during
input to improve
throughput on
unintelligent
terminals.
Reversed by The
default is
Sets the spacing of the software tab
stops
used by the edi‐
tor to expand
tabs in the
input file. The
default is
Set the maximum number of characters
that should be
treated as sig‐
nificant in a
tag. Characters
beyond the limit
are ignored. A
value of zero
means that all
characters in
the tag are sig‐
nificant. The
default is
Specify the tags files to be used by
the
command and the
command-line
option. The
default is spec‐
ifying the file
in the current
directory and
the file File
names are sepa‐
rated by white‐
space.
Each line of a
tags file con‐
tains the fol‐
lowing three
fields separated
by whitespace:
the tag name,
the name of the
file to be
edited, and an
address specifi‐
cation (see
Addressing
above). A file
must be sorted
in order by tag
name.
The command (see
ctags(1)) cre‐
ates tags files
from C, Pascal
and FORTRAN
source files.
Enable the pushdown stack of acti‐
vated tags.
Reversed by The
default is
When you enter a
line mode com‐
mand or visual
mode command,
the current line
number and file
name are stored
on the tag
stack. A future
line mode com‐
mand or visual
mode command
will return to
the stored file
name at the
stored line num‐
ber.
If the tag stack
is disabled and
then reenabled
again, the stack
continues where
it left off.
The command does
not work when
the tag stack is
disabled.
Define the type of terminal being
used with the editor.
The default
value is
obtained from
the environment
variable. If is
unset or null,
is set to There
is no difference
between the and
editor options.
Setting either
one results in
both being
changed.
Use shorter error messages.
Reversed by The
default is
If set, require that all the charac‐
ters of a multicharacter macro name
(the first argu‐
ment in a com‐
mand) must be
received within
the amount of
time specified
by the option in
order to be
accepted as a
match for the
macro name. If
not set, no
limit is placed
on how long to
wait for the
completion of a
macro name.
Reversed by The
default is
Set, in milliseconds (ms),
the length of
the macro time‐
out period (see
the editor
option). This
option has no
effect unless is
set. The value
of n must be at
least 1. The
default is (half
a second).
Define the type of terminal being
used with the editor.
See the editor
option for
details. There
is no difference
between the and
editor options.
Setting either
one results in
both being
changed.
Before executing a or command
escape, display
the message if
the work area
has been modi‐
fied since it
was last loaded
or fully written
to a file.
Reversed by The
default is
Set the number of lines in a text
window in visual mode.
The default
value is one
less than the
size of your
terminal screen
(as defined by
the environment
variable, if
set, or the
entry for your
terminal in the
terminfo(4) data
base otherwise).
However, if the
terminal baud
rate (see
stty(1) is set
to less than
1200 or 2400,
the default
value is reduced
to a maximum of
8 or 16 lines,
respectively.
The startup
value can be
specified with
the command-line
option.
If the terminal baud rate is less
than 1200, set the
editor option to
the value speci‐
fied.
If the terminal baud rate is greater
than or equal to 1200
but less than
2400, set the
editor option to
the value speci‐
fied.
If the terminal baud rate is greater
than or equal to 2400, set the
editor option to
the value speci‐
fied.
In visual mode only, if
n is greater
than zero, a
newline is auto‐
matically
inserted in an
input line at a
word boundary,
so that lines
end at least n
spaces from the
right margin of
the terminal
screen. The
default is
When set, editor searches using
(or continue
silently from
the beginning
(or end) of the
file upon reach‐
ing the end (or
beginning) of
the file (that
is, the scan
"wraps around").
When unset, edi‐
tor searches
stop at the
beginning or the
end of the file,
as appropriate.
Reversed by The
default is
Inhibits the checks otherwise made
before write commands,
allowing a write
to any file
(provided the
system allows
it). Reversed
by The default
is
EXTERNAL INFLUENCES
Environment Variables
This variable shall override the
system-selected horizontal screen
size.
overrides the system-selected verti‐
cal screen size, used as the number
of lines in a screenful and as the
vertical screen size in visual mode.
determines the search path for the
shell command specified in the edi‐
tor commands, and
is variable that shall be inter‐
preted as the preferred command-line
interpreter for use in and other
commands with an operand of the form
For the command, the program shall
be invoked with the single argument
For all others, it shall be invoked
with the two arguments and string.
If no environment variable is set,
or it is set to a null string, the
utility shall be used.
is a variable that shall be inter‐
preted as the name of the terminal
type. If this variable is unset or
null, an unspecified default termi‐
nal type shall be used.
is a variable that shall be inter‐
preted to contain a list of commands
that are executed on editor startup,
before reading the first file. The
list can contain multiple commands
by separating then using a vertical
line (|) character.
shall be interpreted as a pathname
of a directory that shall be
searched for an editor startup file
name
determines the collating sequence
used in evaluating regular expres‐
sions and in processing the file.
If it is not specified or is null,
it defaults to the value of
determines the interpretation of
text as single and/or multibyte
characters, the classification of
characters as uppercase or lowercase
letters, the shifting of the case of
letters, and the characters matched
by character class expressions in
regular expressions. If it is not
specified or is null, it defaults to
the value of
determines the language in which
messages are displayed. If it is
not specified or is null, it
defaults to "C" (see lang(5)).
determines the locale to be used to
override any values for locale cate‐
gories specified by the setting of
or any environment variable (begin‐
ning with ).
determines the processing of affir‐
mative responses and the language in
which messages should be written.
If any internationalization variable
contains an invalid setting, all
internationalization variables
default to "C" (see environ(5)).
When set, the environment variable
specifies a directory to be used for
temporary files, overriding the
default directory
International Code Set Support
Single- and multibyte character code
sets are supported.
ASYNCHRONOUS EVENTS (UNIX Standard Only)
For information about the UNIX stan‐
dard environment, see standards(5).
The following actions shall be taken
upon receipt of signals:
When an interrupt occurs,
shall alert the terminal and
write a message. The current
editor command shall be
aborted, and shall return to
the command level and prompt
for another command. If the
standard input is not a ter‐
minal device, shall exit at
the interrupt and return a
nonzero exit status.
The screen shall be refreshed.
If the current buffer has changed
since the last
or command, shall attempt to
save the current file in a
state such that it can be
recovered later by an com‐
mand.
The action taken for all other sig‐
nals is unspecified.
EXTENDED DESCRIPTION (UNIX Standard Only)
For information about the UNIX stan‐
dard environment, see standards(5).
The pathname of the file being
edited by is referred to as the
file. The text of the file shall be
read into a working version of the
file (called in this clause), and
all editing changes shall be per‐
formed on that version; the changes
shall have no effect on the original
file until an command causes the
file to be written out. Lines in the
buffer may be limited to 4096 char‐
acters including 2-3 bytes for over‐
head. Thus a line length up to 4092
characters should cause no problem.
An error message may be written if
the limit is exceeded during edit‐
ing.
The pathname is the name of the last
file mentioned in an editor command,
or the previous current pathname if
the last file mentioned became the
current file. When the appears in a
pathname entered as part of a com‐
mand argument, it shall be replaced
by the altername pathname. Any char‐
acter, including and shall retain
its literal value when preceded by a
backslash.
When an error occurs, shall alert
ther terminal and write a message.
If the system crashes, shall attempt
to preserve the buffer if any
unwritten changes were made. The
command-line option can be used to
retrieve the saved changes.
During initialization (before the
first file is read or any user com‐
mands from the terminal are pro‐
cessed), if the environment variable
is set, the editor shall execute
commands contained in that variable.
If the variable is not set, shall
attempt to read commands from the If
and only if or sets the editor
option exrc, ex finally shall
attempt to read commands from a file
in the current directory. In the
event that is not set and the cur‐
rent directory is the home directory
of the user, any file shall only be
processed once. No shall be read
unless it is owned by the same user
ID as the effective user ID of the
process. After any files are pro‐
cessed, any commands specified by
the option shall be processed.
By default, shall start in the com‐
mand mode, which shall be indicated
by the ":" prompt. The input mode
can be entered by or commands. There
is one other mode, visual mode, in
which full screen editing is avail‐
able. This is described more fully
under the command. The command line
can consist of multiple commands
separated by vertical-line charac‐
ters(|). The use of commands that
enter input or visual modes in this
manner, unless they are the final
command on the line, produces unde‐
fined results.
Command lines beginning with the
double-quote character (") shall be
ignored. This can be used for com‐
ments in an editor script.
WARNINGS
The command causes all marks to be
lost on lines that are changed and
then restored.
The command prints a number of logi‐
cal rather than physical lines.
More than a screenful of output can
result if long lines are present.
Null characters are discarded in
input files and cannot appear in
resultant files.
On some systems, the recovery of an
edit file with the option is possi‐
ble only if certain system-dependent
actions are taken when the system is
restarted.
Edit preserve files can only be
recovered on systems running the
same HP-UX release in which they
were preserved. Preserve files are
not recoverable across different
releases.
On HP terminals, the attribute field
of any function key specified by a
command should be set to rather than
to the default of
Do not use the option to edit unen‐
crypted files. The option is meant
to be used only on files that are
already encrypted. If the option is
used on files which are not yet
encrypted, a write in the edit ses‐
sion is likely to corrupt the file.
For information about line length
limits, file size limits, etc., see
the WARNINGS section of vi(1).
EXIT STATUS (UNIX Standard Only)
For information about the UNIX stan‐
dard environment, see standards(5).
The utility shall exit with one of
the following values:
Successful completion.
An error occurred.
AUTHOR
was developed by the University of
California, Berkeley. The 16-bit
extensions to are based in part on
software of the Toshiba Corporation.
FILES
Primary editor initialization file
Secondary editor initialization file
Preserve command
Recover command
Description of terminal capabilities
Preservation directory
Editor temporary file
Named buffer temporary file
SEE ALSOctags(1), ed(1), stty(1), vi(1),
write(1), terminfo(4), environ(5),
lang(5), regexp(5), standards(5).
Benjamin/Cummings Publishing Com‐
pany, Inc., ISBN 0-8053-4460-8, HP
part number 97005-90015.
STANDARDS COMPLIANCEex(1)