ex(1) ex(1)
NAME
ex - command and display editor
SYNOPSIS
ex [option ...] [file ...]
DESCRIPTION
ex is a line-based text editor. ex offers you various operating modes:
⊕ In the ex input mode you enter text directly.
⊕ In the ex command mode you enter commands. Among other things, com-
mands enable you to:
- position the cursor
- search for (and replace) text patterns with the aid of regular
expressions
- switch to another file
- invoke a shell
You also have the option of switching from the line editor ex to the
screen editor vi.
Layout of this description
The description of how to call ex on Reliant UNIX shell level is fol-
lowed by the sections:
Functionality of ex
- Operating modes of ex
- Saving the editor buffer and quitting ex
- Presetting ex
- Current and alternate files
- Regular expressions
- Replacement strings
- Buffers
- Error and signal handling
Page 1 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
ex commands
- Addressing
- Parameters
- Commands
ex options
OPTIONS
-s (silent) All interactive output of the editor is suppressed. The
-s option must be set when ex is to read its commands from a com-
mand script.
The -s option has replaced the old - option.
-t tag
(tag) ex loads the file containing the tag for editing and posi-
tions the tag definition under the cursor at the center of the
screen. The tags file containing the search strings for the
definitions must be in the same directory. This option is typi-
cally used by C programmers to quickly locate the definition of a
function or macro on calling the editor. The tags file needed for
this purpose must first be built with the ctags(1) command.
-r file
(recover) Restores the ex session in which you were editing file
if ex or the system crashed during your session.
Changes that are only in the editor buffer are not copied to the
edited file after a system or editor crash. Reliant UNIX does,
however, try to back up the buffer contents by creating a copy of
it, if possible. file is recovered, including any changes made
prior to the crash, and is retrieved into the ex buffer. You can
now continue editing the file or write the changes to another file.
-L Lists the names of all files saved following an editor or system
crash.
-R (readonly) The named file is opened in readonly mode. This mode
prevents the original file from being accidentally overwritten,
but allows you to write the buffer contents to a file with
another name.
Caution:
The file can still be overwritten with w! in the ex command mode.
-v (vi) Invokes the vi editor. A detailed description of vi is pro-
vided in vi(1).
Page 2 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
-c command
Positions the editor at a specific line of the file to be edited
or executes an ex command when ex is invoked. If you position the
editor at a line, the selected line will be displayed in the
center of the screen. By contrast, if you have an ex command exe-
cuted, the editor will be positioned at the last line of the file
after executing the command, unless the ex command you specify
(e.g. search) positions the editor itself.
command not specified:
The ex editor is positioned at the end of the file.
command specified:
command may be specified as a line number (n), a search command
(/pattern), or any other ex command (see EX COMMANDS). The speci-
fied command is executed on invocation of ex:
n n must be an integer. ex is positioned to the nth line of
the file.
/pattern
ex is positioned to the first line containing pattern. If
the pattern you specify includes metacharacters, you must
escape them to protect them from being interpreted by the
shell.
'ex-command'
"ex-command"
ex-command can be any ex command. The ex command must be
quoted (using single or double quotes) in order to prevent
it from being interpreted by the shell. If the editor is not
already positioned as a result of an ex command, ex will be
positioned to the last line of the file.
Example:
When ex is called with:
ex -c /Tuesday appointments
the file appointments is opened, and the cursor is posi-
tioned at the first line that contains the word Tuesday [see
vi(1)].
Page 3 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
-x Encryption option: ex executes an X command and prompts you for a
key. This key is used to encrypt and decrypt text using the algo-
rithm of the crypt command. ex checks whether or not the text to
be read is encrypted. The temporary buffer file is likewise
encrypted, using a transformed version of the key you enter here
[see crypt(1)].
-C Encryption option: the same as the -x option, except that ex exe-
cutes the C command. The C command is like the X command, except
that all text read in is assumed to have been encrypted [see
crypt(1)].
file Name of the file that you wish to edit. If you specify a number
of files, these files will be processed in the order in which
they are listed. The ex command n can be used to switch to the
next file.
file not specified:
ex opens an empty buffer into which you can write your text. The
contents of this buffer are not assigned a name until you write
them back (with w) to a file or assign a name explicitly using
the f command.
Caution:
If your file contains null characters, ex will discard them when
reading in the file. No null characters appear in files written
by ex.
FUNCTIONALITY OF EX
ex always works on a buffer, not on files. When you start an ex ses-
sion, a working copy of the file you are editing is read into the edi-
tor buffer. All the editing changes you make are initially performed
in this buffer and are not saved until you use the w (write) command
to copy the buffer contents back into the original file.
Once you have done this, you can quit ex using the q command.
If you wish to exit the ex editor without writing back the changes to
the original file, you must enter q!.
Null ASCII characters [see ascii(5)] are discarded in input files and
thus cannot appear in output files.
Operating modes of ex
ex offers you two file editing modes:
- the ex command mode, and
- the ex input mode.
Page 4 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
You can also switch from ex to the vi editor, which provides you with
additional operating modes (for more details see vi(1), Operating
modes of vi).
When ex is invoked, it comes up in command mode, as indicated by the
prompt : displayed on the screen. The commands a (append), i (insert),
and c (change) can be used to switch to the input mode, which enables
you to add or modify text in the buffer (see EX COMMANDS).
In input mode, all subsequent input characters, including various
non-printing characters, are written into the buffer. Commands are not
interpreted as such. You can exit from input mode by entering a period
(.) in the first column and then pressing RETURN.
Saving the editor buffer and quitting ex
ex must be in command mode to save the editor buffer or to quit the ex
editor.
Use the following command to save the contents of your editor buffer
to the file edited or that specified:
w [file]
(write) The contents of the editor buffer are saved to the file
specified.
file not specified:
The contents of the editor buffer are written back to the edited
file.
You can quit ex using one of the following options:
q (quit) Quit ex. This works only if the editor buffer has not been
modified at all or if the modified editor buffer has been saved
to a file.
q! (quit) Quit ex. Unsaved modifications made to the editor buffer
are not saved.
x Quit ex and write the modified editor buffer to the edited file.
wq [file]
(write and quit) Quit ex and write the modified editor buffer to
the file specified.
file not specified:
The contents of the editor buffer are written to the edited file.
Page 5 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
Caution:
ex does not issue a warning if you place text in named buffers
and do not save it before exiting the editor. The text is irre-
trievably discarded.
Presetting ex
The ex editor can, to some extent, be adapted to suit your require-
ments and working habits. This entails using the ex command se (set),
which allows you to set or change specific options (see EX OPTIONS).
The changes you make remain in effect for the current session. Details
on how to change default settings permanently can be found in the
vi(1) command description (see section Presetting the vi editor).
Current and alternate file
The file (or its copy) being edited by ex at any given moment is
referred to as the current file. The alternate file is the file most
recently mentioned in an editing command. If you switch to the alter-
nate file, the file you switch from becomes the new alternate file.
When specifying files, you can use the % character for the current
file and the # character for the alternate file. These characters are
replaced in file names by the names of the current file and the alter-
nate file, respectively.
For example, the command:
w %.bak
backs up the current file to a file with the same name but with
the extension .bak.
Page 6 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
Regular expressions
The interpretation of metacharacters in regular expressions depends on
whether or not the magic option has been set for the ex editor (cf. EX
OPTIONS).
When magic is set:
character
An ordinary character stands for itself. The following are meta-
characters, not ordinary characters:
__________________________________________________________________
| ^ | (caret) at the beginning of a pattern |
|______|__________________________________________________________|
| $ | (dollar sign) at the end of a pattern |
|______|__________________________________________________________|
| * | (asterisk) anywhere except at the beginning of a pattern|
|______|__________________________________________________________|
| . | (period) at any position in a pattern |
|______|__________________________________________________________|
| [ | (left square bracket) at any position in a pattern |
|______|__________________________________________________________|
| ~ | (tilde) at any position in a pattern |
|______|__________________________________________________________|
Metacharacters have special meanings and must be escaped with a
backslash \ if they are to lose their special meanings.
^ ^ at the beginning of a pattern stands for the beginning of the
line.
$ $ at the end of a pattern stands for the end of the line.
. stands for any one character.
\<
\>
\< matches the beginning of a word. The word must begin with a
letter, digit, or underscore and be preceded by the beginning of
the line or a character other than the above. \> matches the end
of a word.
[string]
Any character contained in string, where string is not a sequence
of blank characters. The following characters have special mean-
ings within string:
- a dash - between a pair of characters defines a range, e.g.
[a-z] matches a, z, and all the characters which come between
them in the ASCII collating sequence.
Page 7 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
- if a caret ^ is the first character in string, it causes the
construct to match any characters not included in string.
If these characters are escaped by a backslash, they lose their
special meanings.
* Zero, one or more occurrences of the regular expression preceding
the * character.
~ Matches the replacement string used in the last s command (sub-
stitute, see EX COMMANDS).
\(pattern\)
A regular expression pattern can be enclosed in parentheses
escaped by backslashes. This serves only to identify them for
substitution actions (see Replacement strings).
rs A sequence of two regular expressions r and s is a regular
expression in itself. rs matches all strings which consist of a
string matching r followed by a string matching s.
When nomagic is set:
If nomagic has been set, the only characters that have special mean-
ings are:
- caret ^ at the beginning of a pattern
- dollar $ at the end of a pattern, and
- backslash \.
The following characters only have a special meaning if they have been
escaped by a preceding backslash \:
- period .
- asterisk *
- left square bracket [
- tilde ~
Replacement strings
The ampersand character & (with a preceding backslash, i.e. \&, if
nomagic is set) in the replacement string stands for the text matched
by the pattern, i.e. the text to be replaced.
The tilde ~ (\~ if nomagic is set) is replaced by the replacement
string used in the previous s (substitute) command.
Page 8 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
The sequence \n, where n is an integer, is replaced by the text that
is matched by the pattern enclosed in the nth set of parentheses
\(...\).
If the replacement string includes the sequence \u or \l, the charac-
ter that immediately follows \u (upper) or \l (lower) in the replace-
ment string will be converted to uppercase (for u) or lowercase (for
l) if this character is a letter. The sequence \U or \L converts into
uppercase or lowercase all letters until the end of the replacement
string or until the sequence \E or \e is encountered.
Buffers
ex uses one unnamed and 26 named buffers, named a through z.
You can use these buffers to copy text with ya (yank), to save deleted
text with d (delete), and to subsequently retrieve this text with pu
(put).
The d, pu, and ya commands use the unnamed buffer unless you expli-
citly name a buffer. In other words, if you do not specify a buffer
for a delete operation, for example, the material you delete will be
saved in the unnamed buffer.
You can save blocks of text in up to 26 buffers. The buffers are
designated in either lowercase or uppercase letters from a-z (or A-Z).
If you use lowercase letters, the old contents of the buffer will be
overwritten by the new text, i.e. the old contents are deleted. If you
use uppercase letters, the old buffer contents are not overwritten;
the new text is appended to the old one instead.
Error and signal handling
When an error occurs during an ex session, ex sends the BEL character
[acoustic signal; see ascii(5)] to the terminal and prints an error
message.
If an interrupt signal is received, ex returns to command mode, allow-
ing you to enter a new ex command.
If the editor input is from a file, ex exits at the interrupt signal.
EX COMMANDS
Unlike most vi commands, which are interpreted and executed by vi
immediately, ex commands must be "dispatched" by pressing the RETURN
key.
Command lines which start with double quotes " are ignored. This means
that you can use lines of this kind to insert comment lines in a com-
mand script.
Page 9 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
Addressing
An address is used to specify a particular line. Some ex commands
expect one or more addresses as input. The specified line or line
range (an inclusive range of all lines from the first address to the
second) is then processed by the ex command.
For ex, there is at all times a current line. This is explicitly
addressed by a period (.). As a rule, the current line is the line
last processed by a command or the line to which the editor has been
explicitly positioned (e.g. by a search command).
Addresses must be separated from one another by a comma or a semi-
colon. Such address lists are evaluated by ex from left to right.
- When a semicolon (;) is used as a separator, the current line is
set to the value of the first address before the second address is
interpreted.
- When a comma (,) is the separator, all addresses are calculated
relative to the current line. The current line is not changed until
the command is executed.
If more addresses are given than the command requires, then all but
the last address (when a line is expected) or the last two addresses
(if a range is expected) are ignored. When a command requires two
addresses, the first line that is addressed must precede the second
one in the buffer. If you do not specify any address (null address),
ex will use the current line by default.
. Current line of the buffer.
$ Last line of the buffer.
n nth line in the buffer. The lines are numbered sequentially from
1.
'x The line marked with the letter x, where x must be a lowercase
letter (see EX COMMANDS, ma or k). 'x is the address of the
marked line. Before ex executes a movement command, the current
line is marked. You can return to it with '' (2 single quotes).
/RE/ A simple regular expression enclosed in /.../ [see
expressions(5)] addresses the first line which contains a charac-
ter string which matches the regular expression, searching for-
ward from the current line. If necessary, ex wraps around from
the end of the buffer to its start to continue the search (see EX
OPTIONS, wrapscan). If the line matching RE is only to be
printed, the second / may be omitted.
Page 10 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
RE not specified:
The previous specified pattern is used.
?RE? As RE, but searching backward.
+n
-n If an address starts with a plus or minus sign followed by a
decimal number n (optional), the line that lies n lines after (+)
or before (-) the current line will be addressed. Thus, .+3, +3
and +++ have the same effect.
adr+
adr- If an address ends with a plus or minus sign, the line that is
located one line after (+) or before (-) the line identified by
the address is referenced. A single - refers to the line before
the current line. The + or - signs at the end of an address have
a cumulative effect; the address ++ thus addresses the second
line after the current line, 3++ addresses line 5, and ++ and .+2
are identical.
% The % (percent) sign stands for the address pair 1,$, i.e. the
entire buffer.
Parameters
The following parameters are used with ex commands:
line = address
A single line address, which you can specify in any of the forms
described earlier in the Addressing section.
line not specified:
The default value (the period .) applies. The period stands for
the current line.
range = address,address
range = address;address
A pair of line addresses that defines an inclusive range of
lines. The addresses can be separated by a comma or a semicolon.
A range should not be specified together with a number n, since
the last address of the specified range will then be interpreted
as the first address of a range of n lines that begins with the
last address. In other words, you would end up addressing a range
that comes after the one intended. This has been taken into
account in the ex command syntax.
Page 11 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
range not specified:
The default value .,. applies.
.,. represents only the current line.
n A positive integer. In n you specify the number of lines to be
processed.
n not specified:
The default value is 1.
flag One or a combination of the ex commands # (see nu), p, and l.
These commands display a line in a specific format and are exe-
cuted after the preceding ex command completes.
<blank>
The blanks need not always be specified. However, in the interest
of clarity, they have not been indicated as optional here.
Any number of plus or minus characters may be combined with these
parameters.
Commands
Overview of ex commands and their abbreviations
___________________________________________________________________________
| CTRL-D | (scroll) | display n lines, where n=$scroll (see options) |
|________|_____________|___________________________________________________|
| ab | abbrev | define abbreviations |
|________|_____________|___________________________________________________|
| a | append | add text after specified line |
|________|_____________|___________________________________________________|
| ar | args | display argument list of command line |
|________|_____________|___________________________________________________|
| c | change | replace text line |
|________|_____________|___________________________________________________|
| C | encryption | encrypt text |
|________|_____________|___________________________________________________|
| co | copy | copy text range |
|________|_____________|___________________________________________________|
| d | delete | delete text range |
|________|_____________|___________________________________________________|
| e | edit | change edited file |
|________|_____________|___________________________________________________|
| f | file | display current file name |
|________|_____________|___________________________________________________|
| g | global | execute command for all lines matching /RE/ |
|________|_____________|___________________________________________________|
Page 12 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
___________________________________________________________________________
| i | insert | insert text lines |
|________|_____________|___________________________________________________|
| j | join | join two lines |
|________|_____________|___________________________________________________|
| l | list | output text with non-printing characters |
|________|_____________|___________________________________________________|
| map | --- | define macros |
|________|_____________|___________________________________________________|
| k | mark | mark lines |
|________|_____________|___________________________________________________|
| m | move | move line range |
|________|_____________|___________________________________________________|
| ma | mark | mark lines |
|________|_____________|___________________________________________________|
| n | next | edit next file |
|________|_____________|___________________________________________________|
| nu | number | number and output lines |
|________|_____________|___________________________________________________|
| # | number | number and output lines |
|________|_____________|___________________________________________________|
| pre | preserve | preserve contents of buffer |
|________|_____________|___________________________________________________|
| p | print | print range of text |
|________|_____________|___________________________________________________|
| pu | put | put lines back in buffer |
|________|_____________|___________________________________________________|
| q | quit | quit the editor |
|________|_____________|___________________________________________________|
| r | read | read copy of a file into the buffer |
|________|_____________|___________________________________________________|
| rec | recover | reconstruct file after system crash |
|________|_____________|___________________________________________________|
| rew | rewind | rewind argument list (cf. ar) |
|________|_____________|___________________________________________________|
| se | set | display and set options |
|________|_____________|___________________________________________________|
| sh | shell | call shell |
|________|_____________|___________________________________________________|
| so | source | read command from file |
|________|_____________|___________________________________________________|
| s | substitute | search and replace |
|________|_____________|___________________________________________________|
| unab | unabbrev | cancel word from abbreviation list made with ab |
|________|_____________|___________________________________________________|
| u | undo | undo effect of previous command |
|________|_____________|___________________________________________________|
| unm | unmap | remove macro definition made with map |
|________|_____________|___________________________________________________|
Page 13 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
___________________________________________________________________________
| v | --- | like g, but for all lines that do not match /RE/ |
|________|_____________|___________________________________________________|
| ve | version | output version number of the editor |
|________|_____________|___________________________________________________|
| vi | visual | switch to vi |
|________|_____________|___________________________________________________|
| w | write | write buffer contents to file |
|________|_____________|___________________________________________________|
| x | exit | quit editor after saving buffer content |
|________|_____________|___________________________________________________|
| X | encryption | encrypt text |
|________|_____________|___________________________________________________|
| ya | yank | copy lines to buffer |
|________|_____________|___________________________________________________|
| z | (window) | output specific text range |
|________|_____________|___________________________________________________|
| ! | (escape) | execute shell command |
|________|_____________|___________________________________________________|
| & s | (resubst) | repeat the last substitute command |
|________|_____________|___________________________________________________|
| < | (lshift) | shift text range to left |
|________|_____________|___________________________________________________|
| > | (rshift) | shift text range to right |
|________|_____________|___________________________________________________|
| = | (line no) | display the line number |
|________|_____________|___________________________________________________|
No command specified
If you specify only a line or a range, the command p (print) is
automatically assumed and executed. If a null line is entered,
the next line is printed (equivalent to .+1p)
<CTRL-D>
(ASCII EOT) prints the next n lines, where n is the value of the
ex option scroll.
ab word text
(abbreviate) This command is only effective in vi mode! If you
enter word in the vi input mode as a complete word (i.e. not as a
word fragment), it is replaced by the string text. If text is to
include special characters, e.g. RETURN, these characters must be
preceded by CTRL-V.
line a
(append) Causes ex to enter input mode, placing the input text
after the specified line. Use a line value of 0 to put a line at
the beginning of the buffer. The last line of new input becomes
the new current line. If there is no new input, the target line
becomes the current line.
Input is terminated by a period (.) entered in column 1.
Page 14 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
ar (arguments) Prints the argument list from the command line of the
ex call, enclosed in square brackets [...].
line c n
range c
(change) ex switches to input mode. n lines or the lines in range
are replaced by the lines you enter next.
The last input line becomes the current line. If no text lines
are entered, the specified range is deleted, i.e. c has the same
effect as the d (delete) command. Input is terminated by a period
(.) entered in column 1.
C Encryption command: the C command is like the X command, except
that all text read in with the e and r commands is assumed to
have been encrypted (see option -C).
range co line flags
(copy) Copies the lines specified by range to after line. If line
is assigned a value of 0, the range of lines (i.e. text) will be
copied to the beginning of the buffer.
line d buffer n
range d buffer
(delete) The lines in range, or n lines from the given line, are
deleted from the buffer. If a named buffer is specified, the
deleted text is saved in it. You can use the ex command pu to
retrieve the contents of this buffer if you wish. The first line
following the deleted material becomes the current line, unless
the deleted lines were at the end of the buffer. In that case,
the last line in the buffer becomes the current line.
e [+line] file
(edit) The named file is edited. If the current buffer has been
modified since the last w (write) command, ex warns you and
aborts the command. You can, however, force the execution of the
e command by appending an exclamation mark to the e: e! file. The
current line is the last line of the buffer; however, if this
command is called from vi, the current line becomes the first
line of the buffer.
+line
The specified line becomes the current line. line can be
given as:
- a line number n
- the dollar symbol $ (for end of file) - a regular expres-
sion in the form /RE or ?RE.
Page 15 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
f [name]
(file) Prints the current file name and other information, e.g.
the number of lines and the position of the current line.
name specified:
name becomes the current file name
range g/RE/cmds
(global) First marks all lines within the given range that match
the pattern specified in RE; then applies the given cmds to the
each of marked lines in turn, with each marked line becoming the
current line while it is being edited.
The commands given in cmds may be specified on separate lines,
provided newline characters are escaped with a backslash. If cmds
are omitted, all lines will be printed. The a(ppend), c(hange),
and i(nsert) commands are allowed; the terminating period at the
end of cmds may be omitted. The visual command is also permitted,
and takes input from the display terminal.
The following commands are not permitted in cmds: global and
undo.
The following edit options are not allowed in cmds: autoprint,
autoindent and report.
Example:
1,$g/^\*/s//+/
All occurrences of * in the first column ^ of line 1 and of all
lines through to the end of the file ($) are replaced by a plus
character (+) by the substitute command (s).
line i
(insert) ex enters input mode; the input text is placed before
the specified line. The last line inserted becomes the current
line, but if no text is inserted, the line before the target line
becomes the current line. Input is terminated by a period (.)
entered in column 1.
line j n flag
range j flag
(join) Joins the lines in range, or n lines from line, into one
line. The command inserts at least one blank between two previ-
ously split lines; two blanks are provided if a line ends with a
period. If a following line begins with a right parenthesis, no
blanks are inserted. Extra white space at the start of a line is
discarded.
Page 16 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
Appending an exclamation mark to the j command (j!) produces a
simpler join with no white space processing.
line l n flag
range l flag
(list) Displays the specified lines. Tab characters are replaced
by ^I, and the end of each line is marked with a trailing $. The
only useful flag is #, when the lines are to be preceded by their
line numbers. The last line printed becomes the current line.
map x commands Format 1
map! x text Format 2
Only works with vi!
Format 1: Macro definitions for vi command mode
This format of the map command is used to define macros for use
in the vi command mode. The first argument x is a single charac-
ter, or the sequence #n, where n is a digit that refers to func-
tion key n. When this character or function key is typed in vi
command mode, vi responds as if the corresponding commands were
entered. The specified commands are interpreted as a sequence of
vi commands. If special characters, white space, or newline char-
acters are to be used in the commands, they must be escaped with
CTRL-V.
Example 1:
You want to define a macro which replaces an * occurring at the
beginning of a line (column 1) by a blank <blank> throughout the
entire file. The name of this macro is to be *. Enter the follow-
ing in your .exrc file (see section Presetting ex) so that you
can call the macro when required:
:map * :1,$s/^\*/ /
Example 2:
You now want to define a macro and bind it to function key <F1>.
This macro is to search for the next line that begins with a par-
ticular regular expression RE and then automatically delete this
line.
To do this, you enter (from vi command mode):
:map CTRL-V <F1> /^rA CTRL-V RETURN dd RETURN
Page 17 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
Format 2: Macro definitions for vi input mode
This format of the map command defines macros for use in vi input
mode (cf. Format 1). Every x entered in vi input mode is replaced
by text. (In the ab command, by contrast, x is replaced only when
alone).
If x is not to be replaced by text, it must be escaped by preced-
ing it with CTRL-V.
Formats 1 and 2:
Macro definitions can be canceled with:
unmap x or
unmap! x
line ma x
line k x
(mark) Marks the specified line with the character x, which must
be a single lowercase letter. The x must be preceded by a blank
or tab. The current line position is not affected.
range m line
(move) Moves the specified lines (range) to after the target
line. The first of the moved lines becomes the current line.
n [file ...]
file not specified:
(next) The next file from the command line argument list is
edited (cf. f and ar). If the current buffer has been modified
since the last w (write) command, ex warns you and aborts the
command. You can, however, force the execution of the n command
by entering an exclamation mark after the n: n!.
file specified:
The previous argument list is replaced by the specified file(s),
and the first specified file is edited.
line nu n flag
range nu flag
line # n flag
range # flag
(number) Prints the lines, each preceded by its line number. The
only useful flag in this case is l. The last line printed becomes
the current line.
Page 18 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
pre (preserve) The current editor buffer is saved as though the sys-
tem had just crashed. The pre command is for use in emergencies,
e.g. when a w (write) does not work because the disk is full, and
the buffer contents cannot be saved in any other way.
line p n
range p
(print) Prints the specified lines, with non-printing characters
printed as control characters in the form ^x; DEL is represented
as ^?. The last line printed becomes the current line.
line pu buffer
(put) Lines deleted with d (delete) or copied to a buffer with y
(yank) are put back in after the specified line. buffer repre-
sents a buffer name from a to z.
buffer not specified:
The text in the unnamed buffer is retrieved.
q (quit) Quits the editor. If the buffer has been modified since
the last w (write) command, a warning is printed and the q com-
mand fails. You can, however, force the execution of the q com-
mand by appending an exclamation mark to the q: q!. All changes
not saved with w will then be discarded.
line r [file]
(read) Places a copy of the specified file in the buffer after
the target line. Use a value of 0 to place text at the beginning
of the buffer. If there is no current file at this point (e.g.
when ex is called without a file name), then file becomes the
current file. The last line read becomes the current line; in vi
mode, the first line read becomes the current line.
file not specified:
The current file is read.
If file is given as !unixcmd, then unixcmd is interpreted as a
Reliant UNIX command and passed to the shell. The output of the
Reliant UNIX command is then read in to the buffer.
rec file
Recovers file from the save area after an editor or system crash.
rew (rewind) The argument list (see ar) is rewound, and the first
file in the list is edited. If the buffer has been modified since
the last w (write) command, a warning is printed and the rew com-
mand is not executed. You can, however, force the execution of
the rew command by appending an exclamation mark to the rew com-
mand: rew!. All changes not saved with w are then discarded.
Page 19 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
se [parameter]
(set) The set command can be used to display or set options.
There are two types of options: those that have "Boolean" (i.e.
on or off) values and those that do not. One example of a Boolean
parameter is the number option. If this option is set, line
numbers are displayed; when nonumber is set, no line numbers are
displayed. By contrast, the report option is non-Boolean. The
value of this option (default = 5) defines the number of lines
that must be changed by a command before ex and vi issue a mes-
sage.
parameter
all The values of all options are displayed.
option?
The current value of the specified option is displayed.
option
Only for options with Boolean values: The option is set.
nooption
Only for options with Boolean values: The option is not set.
option=value
Only for options with non-Boolean values: The option is
assigned the specified value.
parameter not specified:
set displays user-defined ex options, i.e. options that deviate
from default settings.
More detailed information on ex options is provided in the corre-
sponding section below.
sh If the SHELL variable is set, the shell defined in that variable
is invoked; otherwise, the Bourne shell sh. When you exit the
shell, you will be returned to the editing session at the point
you left off.
so file
Reads and executes commands from the specified file. Such so com-
mands may be nested.
line s/RE/repl/options n flags
range s/RE/repl/options flags
(substitute) The first occurrence of a pattern that matches RE
(regular expression) in each line of the given range is replaced
by the string repl (see Regular expressions and Replacement
strings). The range is either given in range or specified as n
lines from the specified line.
Page 20 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
options
g (global) All strings that match RE in the line are substi-
tuted.
c (confirm) Before each substitution, the line is output with
the pattern to be replaced shown in the line below it,
marked by a ^ character. Entering y causes the substitution
to be made; any other input causes the command to abort. The
last line that contains a substitution becomes the current
line.
una word
(unabbreviate) word is deleted from the list of abbreviations set
up by ab.
u (undo) Reverses the changes made by the previous editing command.
g (global) and vi (visual) are considered single commands in this
case. Commands which affect the external environment, such as w
(write), e (edit), and n (next), cannot be undone.
An undo can itself be reversed with a follow-up u.
All markers for lines changed and subsequently restored are lost
with u.
unm x
unm! x
(unmap) Removes the macro definition created by map for x.
range v/RE/cmds
(vice versa) This is the same as the global command, except that
cmds are applied to all lines that do not match the pattern RE.
ve Prints the current version of the editor.
line vi [type] n
Enters vi mode at the specified line. The type is optional and
may be given as a minus sign (-) or a period (.), as in the z
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. n specifies an initial window size; the default is
the value of the ex option window. The command Q exits vi mode
and returns you to ex. For further information, see vi(1).
[range] w[!] [file] Format 1
[range] wq[!] [file] Format 2
Format 1: Write to a file
(write) The specified range is written to the named file, and the
number of lines and characters written is printed.
Page 21 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
If an alternate file is specified, and the file exists, the com-
mand will fail in order to prevent the alternate file from being
accidentally overwritten. The execution of w can, however, be
forced by appending an exclamation mark to the command: w!.
To append to the file, use the form w>>. If the file does not
exist, an error message is issued.
If !sinixcmd is specified instead of file, then sinixcmd is
interpreted as a Reliant UNIX command. The command interpreter is
invoked, and the specified range is passed as standard input to
the command.
range not specified:
The entire current file is written to file.
file not specified:
The current file is used by default. The w command cannot be exe-
cuted if there is no current file and no file is specified.
Format 2: Write to a file and quit ex
(write and quit) The command wq is equivalent to a w followed by
a q; wq! is equivalent to w! followed by q.
x (exit) Writes out the buffer if changes have been made since the
last w and then (in any case) quits.
X Encryption command: you are prompted for a key, which is used in
subsequent e, r, and w commands to decrypt and encrypt text using
the algorithm of the crypt(1) command. A null key turns off
encryption. ex verifies whether or not the text to be read (e and
r) is encrypted. The temporary buffer file is likewise encrypted,
using a transformed version of the key you enter here (see the -x
option).
line ya buffer n
range ya buffer
Copies (yanks) the specified range, or n lines from the specified
line, to the named buffer.
buffer not specified:
If no buffer is specified, the unnamed buffer is used.
Page 22 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
line z [type] n
(window) Displays n lines from the area in which line is located.
n not specified:
n defaults to the value of the window variable.
type
type is an optional parameter and can be specified as a dash or a
period; a - causes the line to be placed at the bottom of the
screen, while a . causes the line to be placed in the middle of
the display. The last line printed becomes the current line.
type not specified:
line is placed at the top of the displayed area.
Caution:
ex prints the number of logical rather than physical lines. More
than a screen full of output may result if there are lines which
are longer than the screen width.
! command
(escape) The remainder of the line after the exclamation mark is
passed to the system command interpreter for execution. A warning
is issued if the buffer has been changed since the last w (write)
command. The specified command is then executed. If the command
output has not been redirected, it is displayed on the screen,
but does not change the file. The command itself may, however,
modify the file, e.g. !cat /etc/profile >> %. A single ! is
printed when the command completes. The current line position is
not affected.
Within the text of command, the percent sign % and the hash char-
acter # are expanded as file names (see Current and alternate
files).
An exclamation mark in command is replaced with the text of the
previous ! command. Thus, !! means "repeat the preceding com-
mand". If any such expansion is done, the expanded line will be
echoed.
range ! command
(escape) In this form of the ! command, the lines specified in
range are passed to the command as standard input and replaced by
the output of the command.
Page 23 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
range not specified:
range is not replaced by the current line (.,.); the other form
of the ! command applies.
" Command lines that start with double quotes " are ignored. This
means that you can use lines of this kind to insert comment lines
in a command script.
line &options n flags
range&options flags
line soptions n flags
rangesoptions flags
(resubst) Repeats the previous s (substitute) command, as if &
were replaced by the previous s/RE/repl/. The same effect is
obtained by omitting the /RE/repl/ string in an s command.
line < n
range <
(lshift) Shifts the defined line range (or the n lines that fol-
low line) to the left by the number of spaces specified by the
shiftwidth option. White space (blanks and tabs) is lost in the
shift process; other characters are not affected. The last line
changed becomes the current line.
line > n
range >
(rshift) Shifts the defined line range (or the n lines that fol-
low line) to the right by the number of spaces specified by the
shiftwidth option. White space (blanks and tabs) is not lost, but
inserted as required.
line=
(line number) Prints the line number of the specified line. The
current line position is not affected.
line not specified:
The line number of the last line is displayed.
EX OPTIONS
ex provides a number of options with which you can govern the behavior
of both the ex and (more importantly) the vi editors (see vi(1),
Presetting the vi environment).
All options have default settings; these settings are valid at the
time ex or vi is invoked. Use the ex command se (set) if you wish to
have all options displayed:
set all RETURN
Page 24 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
The above command can also be used to change one or more options:
set showmode scroll=15 RETURN
This command shows the vi input mode in the status line and sets the
number of lines scrolled by the CTRL-D key to 15.
The command:
set RETURN
displays all options set to non-default values.
There are two types of options: those that have "Boolean" (i.e. on or
off) values and those that do not. One example of a Boolean parameter
is the showmode option. When this option is not set, it is named
noshowmode. The scroll option, by contrast, is an example of a non-
Boolean parameter.
autoindent, ai
noautoindent, noai (default)
If autoindent is set, each line in insert mode is aligned with
the beginning of the previous line; tabs and blanks are inserted
to produce this alignment. The starting indentation of a line is
determined by the line it is appended after (a), the line it is
inserted before (i), or the first line to be changed (c). Extra
indentation can be provided as usual; succeeding lines will
automatically be indented to the new alignment.
Reduced indentation is achieved by typing CTRL-D to back up over
the indentation by shiftwidth spaces. A caret ^ followed by a
CTRL-D removes all indentation temporarily for the current line;
a 0 (zero) followed by a CTRL-D removes all indentation.
autoprint, ap
noautoprint, noap (default)
Prints the current line after each command that changes buffer
text. autoprint is suppressed during global search and replace
operations (see g, s and v).
autowrite, aw
noautowrite, noaw (default)
Writes the buffer to the current file if the buffer has been
modified, and an e (edit), n (next), rew (rewind) or ! (escape)
command has been given.
beautify, bf
nobeautify, nobf (default)
Causes all control characters other than tab, newline and form
feed to be discarded from the input text.
Page 25 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
directory=dir
dir=dir
The value of dir specifies the directory which is to hold the
editor buffer. If the user does not have write permission for
this directory, the editor quits.
edcompatible, ed
noedcompatible, noed
Causes the presence of g and c suffixes on s (substitute) com-
mands to be remembered for use as toggles.
errorbells, eb
noerrorbells, noeb
Rings the terminal bell before displaying error messages in the
last line (usually in reverse video).
exrc, ex
This option has been deactivated for security reasons. It nor-
mally causes .exrc files in the current directory to be
evaluated.
flash, fl (default)
noflash, nofl
If the terminfo description contains an entry for flashing the
screen to indicate an error, this option can be used to inform
users when they have made an invalid entry.
hardtabs=number
ht=number
If the terminal has hardware tabs, this option can be used to set
the number of spaces to which the tab stops are set (to optimize
screen output).
ignorecase, ic
noignorecase, noic (default)
Treats all uppercase characters in the text as lowercase when a
search is made. Uppercase characters in regular expressions are
also mapped to lowercase, except in character class expressions.
lisp
nolisp (default)
Activates the autoindent option and modifies the vi commands left
parenthesis (, right parenthesis ), left brace {, right brace },
double left brackets [[, and double right brackets ]] suitably.
list
nolist (default)
All printed lines will be displayed with tabs shown as ^I, and
the end of line marked by a $.
Page 26 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
magic (default)
nomagic
Changes interpretation of characters in regular expressions and
substitution replacement strings (see the relevant sections).
mesg (default)
nomesg
Grants/denies other users permission to write to the terminal
(e.g. with the write command).
modelines (default)
nomodelines
The first and last five lines of a file that is read in are
interpreted as editor commands and executed if they are in the
form: ex:command:
novice
nonovice (default)
Defines the level of detail for error messages.
number, nu
nonumber, nonu (default)
Causes lines to be printed with line numbers.
optimize, opt
nooptimize, noopt (default)
Allows you to set the terminal with or without automatic carriage
returns (to optimize output).
paragraphs=string
para=string
The value of this option is a string in which each successive
pair of characters specifies the name of an nroff macro that
begins a paragraph. A macro appears in the text in the form .XX,
where the . is the first character in the line.
prompt (default)
noprompt
When prompt is set, the : prompt is displayed in command mode;
otherwise, there is no command-mode prompt.
readonly
noreadonly (default)
If readonly is set, the editor can only be used to read files,
not to make changes to the text. If noreadonly is set, you can
make changes to files.
redraw (default)
noredraw
The editor simulates an intelligent terminal on a dumb terminal.
Since this is likely to require a large amount of output to the
terminal, it is useful only at high transmission speeds.
Page 27 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
remap (default)
noremap
If remap is set, macro translation allows for macros defined in
terms of other macros; translation continues until the final pro-
duct is obtained. Only one step of translation is performed if
noremap is set.
report=n
When the number of lines changed, deleted, or copied by the last
command exceeds n, a message is issued in the status line.
scroll=n
The value n specified for scroll determines the number of lines
that the screen will scroll when a CTRL-D command is entered. It
also controls the number of lines displayed by a z command (twice
the value of scroll)
sections=string
sect=string
The value assigned to this option is a string in which each suc-
cessive pair of characters specifies the name of an nroff macro
which begins a section. A macro appears in the text in the form
.XX, where the . is the first character in the line.
shiftwidth=n
sw=n
The value n specified for sw is used for the spacing of tab stops
used by the tab key, the autoindent option, and by the < and >
(shift) commands.
showmatch, sm
noshowmatch, nosm (default)
When a right parenthesis ) or right brace } is entered in vi, the
matching left parenthesis ( or left brace { is shown, provided
the matching character is still on the screen.
showmode, smd
noshowmode, nosmd (default)
When smd is set, an indication is provided in the status line as
to whether vi is in vi input mode.
slowopen, slow
noslowopen, noslow (default)
In vi, prevents screen updates during input to improve throughput
on unintelligent terminals.
tabstop=n
ts=n
n specifies the software tab spacing to be used by the editor
when expanding tabs in the input file.
Page 28 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
taglength=number
tl=number
Defines how many characters are to be considered significant in
searches with the :tag command. A value of 0 means that all char-
acters are to be considered.
tags=files
Names of tag files, separated by blanks.
term=string
string tells vi what type of terminal is being used. (The default
is the value of the environment variable TERM.)
terse
noterse (default)
Setting terse causes shorter error messages to be issued.
timeout
notimeout
Sets/cancels a timeout period.
ttytype=string
string tells vi what type of terminal is being used. (The default
is the value of the environment variable TERM.)
warn (default)
nowarn
When warn is set, the warning No write since last change is
issued if a :! command is given before the most recent changes to
the editor buffer have been saved with w.
window=n
The number of lines in a vi text window.
wrapmargin=n
wm=n
Only effective in vi. If n>0, a newline is automatically added to
an input line at a word boundary such that lines end at least n
spaces from the right margin of the terminal screen.
The setting of automatic line breaks can be deactivated by set-
ting the value of n to 0 (default).
wrapscan, ws (default)
nowrapscan, nows
Setting wrapscan causes searches begun by the /.../ or ?...? com-
mands to wrap around from the end of a buffer to the beginning
(or vice-versa). When nows is set, the search runs through to the
end or beginning of the buffer as appropriate and then ter-
minates.
Page 29 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
writeany, wa
nowriteany, nowa (default)
When nowa is set, a check is performed before a w command to
determine whether the file exists. This is to prevent an existing
file from being accidentally overwritten. You can override the
overwrite protection with w!. Setting wa inhibits the normally
provided overwrite protection.
ERROR MESSAGES
When an error occurs, ex sends the acoustic signal BEL [see ascii(5)]
to the terminal and prints a message. If an interrupt signal is
received, ex returns to command level, allowing you to enter a new ex
command. If the editor input is from a file, ex exits at the interrupt
signal.
If ex detects an internal error, it attempts to preserve the buffer if
the most recent changes have not been saved. If you wish to access the
backed up data, you must call ex with the -r option.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
EXAMPLES
The following example demonstrates and explains a number of ex com-
mands:
$ ex figures - Call ex (file name "figures")
"figures" 4 lines, 19 characters
:set number - Output line numbers
:1,$p - Output line 1 through to last line
1 one - Original contents of "figures"
2 two
3 three
4 four
:1 c 1 - Modify line 1
1 ONE - New line 1
2 . - Quit input mode
:2,3 co 4 - Copy lines 2 to 3 after line 4
6 three
:1,$ g/two/s//TWO/ - Replace "two" by "TWO" throughout
the file
:2 a - Insert new line after line 2
3 THREE - New line 3
4 . - Quit input mode
:4 i - Insert new line before line 4
4 FOUR - New line 4
5 . - Quit input mode
Page 30 Reliant UNIX 5.44 Printed 11/98
ex(1) ex(1)
:5,$ d a - Delete line 5 and all lines to
end of file
4 FOUR
:1,$p - Output line 1 through to last line
1 ONE
2 TWO
3 THREE
4 FOUR
:wq - Save the contents of the buffer
and quit ex
"figures" 4 lines, 19 characters
ENVIRONMENT VARIABLES
TERM The type of data terminal used must be defined in the envi-
ronment variable TERM.
EXINIT Environment variable with default values for ex and vi. These
defaults always apply.
FILES
$HOME/.exrc
File containing default values for ex and vi. These defaults are
overridden if conflicting settings have been assigned to EXINIT.
SEE ALSO
ed(1), edit(1), vi(1).
Page 31 Reliant UNIX 5.44 Printed 11/98