7. Command descriptions
The following form is a prototype for all
ex
commands:
-
address command ! parameters count flags
All parts are optional; the degenerate case is the empty command which prints
the next line in the file. For sanity with use from within
visual
mode,
ex
ignores a ``:'' preceding any command.
In the following command descriptions, the
default addresses are shown in parentheses,
which are
not,
however,
part of the command.
abbreviate word rhs abbr: ab
-
Add the named abbreviation to the current list.
When in input mode in visual, if
word
is typed as a complete word, it will be changed to
rhs.
( . ) append abbr: a
text
.
-
Reads the input text and places it after the specified line.
After the command, `.'
addresses the last line input or the
specified line if no lines were input.
If address `0' is given,
text is placed at the beginning of the buffer.
a!
text
.
-
The variant flag to
append
toggles the setting for the
autoindent
option during the input of
text.
args
-
The members of the argument list are printed, with the current argument
delimited by `[' and `]'.
( . , . ) change count abbr: c
text
.
-
Replaces the specified lines with the input text.
The current line becomes the last line input;
if no lines were input it is left as for a
delete.
c!
text
.
-
The variant toggles
autoindent
during the
change.
( . , . )copy addr flags abbr: co
-
A
copy
of the specified lines is placed after
addr,
which may be `0'.
The current line
`.'
addresses the last line of the copy.
The command
t
is a synonym for
copy.
( . , . )delete buffer count flags abbr: d
-
Removes the specified lines from the buffer.
The line after the last line deleted becomes the current line;
if the lines deleted were originally at the end,
the new last line becomes the current line.
If a named
buffer
is specified by giving a letter,
then the specified lines are saved in that buffer,
or appended to it if an upper case letter is used.
edit file abbr: e
ex file
-
Used to begin an editing session on a new file.
The editor
first checks to see if the buffer has been modified since the last
write
command was issued.
If it has been,
a warning is issued and the
command is aborted.
The
command otherwise deletes the entire contents of the editor buffer,
makes the named file the current file and prints the new filename.
After insuring that this file is sensible**
the editor reads the file into its buffer.
-
If the read of the file completes without error,
the number of lines and characters read is typed.
If there were any non-ASCII characters
in the file they are stripped of their non-ASCII
high bits,
and any null characters in the file are discarded.
If none of these errors occurred, the file is considered
edited.
If the last line of the input file is missing the trailing
newline character, it will be supplied and a complaint will be issued.
This command leaves the current line `.' at the last line read.***
e! file
-
The variant form suppresses the complaint about modifications having
been made and not written from the editor buffer, thus
discarding all changes which have been made before editing the new file.
e +n file
-
Causes the editor to begin at line
n
rather than at the last line;
n may also be an editor command containing no spaces, e.g.: ``+/pat''.
file abbr: f
-
Prints the current file name,
whether it has been `[Modified]' since the last
write
command,
whether it is
read only,
the current line,
the number of lines in the buffer,
and the percentage of the way through the buffer of the current line.*
file file
-
The current file name is changed to
file
which is considered
`[Not edited]'.
( 1 , $ ) global /pat/ cmds abbr: g
-
First marks each line among those specified which matches
the given regular expression.
Then the given command list is executed with `.' initially
set to each marked line.
-
The command list consists of the remaining commands on the current
input line and may continue to multiple lines by ending all but the
last such line with a `\'.
If
cmds
(and possibly the trailing / delimiter) is omitted, each line matching
pat
is printed.
Append,
insert,
and
change
commands and associated input are permitted;
the `.' terminating input may be omitted if it would be on the
last line of the command list.
Open
and
visual
commands are permitted in the command list and take input from the terminal.
-
The
global
command itself may not appear in
cmds.
The
undo
command is also not permitted there,
as
undo
instead can be used to reverse the entire
global
command.
The options
autoprint
and
autoindent
are inhibited during a
global,
(and possibly the trailing / delimiter) and the value of the
report
option is temporarily infinite,
in deference to a report for the entire global.
Finally, the context mark `''' is set to the value of
`.' before the global command begins and is not changed during a global
command,
except perhaps by an
open
or
visual
within the
global.
g! /pat/ cmds abbr: v
-
The variant form of global runs cmds at each line not matching
pat.
( . )insert abbr: i
text
.
-
Places the given text before the specified line.
The current line is left at the last line input;
if there were none input it is left at the line before the addressed line.
This command differs from
append
only in the placement of text.
i!
text
.
-
The variant toggles
autoindent
during the
insert.
( . , .+1 ) join count flags abbr: j
-
Places the text from a specified range of lines
together on one line.
White space is adjusted at each junction to provide at least
one blank character, two if there was a `.' at the end of the line,
or none if the first following character is a `)'.
If there is already white space at the end of the line,
then the white space at the start of the next line will be discarded.
j!
-
The variant causes a simpler
join
with no white space processing; the characters in the lines are simply
concatenated.
( . ) k x
-
The
k
command is a synonym for
mark.
It does not require a blank or tab before the following letter.
( . , . ) list count flags
-
Prints the specified lines in a more unambiguous way:
tabs are printed as `^I'
and the end of each line is marked with a trailing `$'.
The current line is left at the last line printed.
map lhs rhs
-
The
map
command is used to define macros for use in
visual
mode.
Lhs
should be a single character, or the sequence ``#n'', for n a digit,
referring to function key n. When this character or function key
is typed in
visual
mode, it will be as though the corresponding rhs had been typed.
On terminals without function keys, you can type ``#n''.
See section 6.9 of the ``Introduction to Display Editing with Vi''
for more details.
( . ) mark x
-
Gives the specified line mark
x,
a single lower case letter.
The
x
must be preceded by a blank or a tab.
The addressing form `'x' then addresses this line.
The current line is not affected by this command.
( . , . ) move addr abbr: m
-
The
move
command repositions the specified lines to be after
addr.
The first of the moved lines becomes the current line.
next abbr: n
-
The next file from the command line argument list is edited.
n!
-
The variant suppresses warnings about the modifications to the buffer not
having been written out, discarding (irretrievably) any changes which may
have been made.
n filelist
n +command filelist
-
The specified
filelist
is expanded and the resulting list replaces the
current argument list;
the first file in the new list is then edited.
If
command
is given (it must contain no spaces), then it is executed after editing the first such file.
( . , . ) number count flags abbr: # or nu
-
Prints each specified line preceded by its buffer line
number.
The current line is left at the last line printed.
( . ) open flags abbr: o
( . ) open /pat/ flags
-
Enters intraline editing open mode at each addressed line.
If
pat
is given,
then the cursor will be placed initially at the beginning of the
string matched by the pattern.
To exit this mode use Q.
See
An Introduction to Display Editing with Vi
for more details.
preserve
-
The current editor buffer is saved as though the system had just crashed.
This command is for use only in emergencies when a
write
command has resulted in an error and you don't know how to save your work.
After a
preserve
you should seek help.
( . , . )print count abbr: p or P
-
Prints the specified lines
with non-printing characters printed as control characters `^x';
delete (octal 177) is represented as `^?'.
The current line is left at the last line printed.
( . )put buffer abbr: pu
-
Puts back
previously
deleted
or
yanked
lines.
Normally used with
delete
to effect movement of lines,
or with
yank
to effect duplication of lines.
If no
buffer
is specified, then the last
deleted
or
yanked
text is restored.*
By using a named buffer, text may be restored that was saved there at any
previous time.
quit abbr: q
-
Causes
ex
to terminate.
No automatic write of the editor buffer to a file is performed.
However,
ex
issues a warning message if the file has changed
since the last
write
command was issued, and does not
quit.**
Normally, you will wish to save your changes, and you
should give a write command;
if you wish to discard them, use the q! command variant.
q!
-
Quits from the editor, discarding changes to the buffer without complaint.
( . ) read file abbr: r
-
Places a copy of the text of the given file in the
editing buffer after the specified line.
If no
file
is given the current file name is used.
The current file name is not changed unless there is none in which
case
file
becomes the current name.
The sensibility restrictions for the
edit
command apply here also.
If the file buffer is empty and there is no current name then
ex
treats this as an
edit
command.
-
Address `0' is legal for this command and causes the file to be read at
the beginning of the buffer.
Statistics are given as for the
edit
command when the
read
successfully terminates.
After a
read
the current line is the last line read.***
( . ) read !command
-
Reads the output of the command
command
into the buffer after the specified line.
This is not a variant form of the command, rather a read
specifying a
command
rather than a
filename;
a blank or tab before the ! is mandatory.
recover file
-
Recovers
file
from the system save area.
Used after a accidental hangup of the phone**
or a system crash** or
preserve
command.
Except when you use
preserve
you will be notified by mail when a file is saved.
rewind abbr: rew
-
The argument list is rewound, and the first file in the list is edited.
rew!
-
Rewinds the argument list discarding any changes made to the current buffer.
set parameter
-
With no arguments, prints those options whose values have been
changed from their defaults;
with parameter
all
it prints all of the option values.
-
Giving an option name followed by a `?'
causes the current value of that option to be printed.
The `?' is unnecessary unless the option is Boolean valued.
Boolean options are given values either by the form
`set option' to turn them on or
`set nooption' to turn them off;
string and numeric options are assigned via the form
`set option=value'.
-
More than one parameter may be given to
set;
they are interpreted left-to-right.
shell abbr: sh
-
A new shell is created.
When it terminates, editing resumes.
source file abbr: so
-
Reads and executes commands from the specified file.
Source
commands may be nested.
( . , . ) substitute /pat/repl/ options count flags abbr: s
-
On each specified line, the first instance of pattern
pat
is replaced by replacement pattern
repl.
If the
global
indicator option character `g'
appears, then all instances are substituted;
if the
confirm
indication character `c' appears,
then before each substitution the line to be substituted
is typed with the string to be substituted marked
with `\(ua' characters.
By typing an `y' one can cause the substitution to be performed,
any other input causes no change to take place.
After a
substitute
the current line is the last line substituted.
-
Lines may be split by substituting
new-line characters into them.
The newline in
repl
must be escaped by preceding it with a `\'.
Other metacharacters available in
pat
and
repl
are described below.
stop
-
Suspends the editor, returning control to the top level shell.
If
autowrite
is set and there are unsaved changes,
a write is done first unless the form
stop!
is used.
This commands is only available where supported by the teletype driver
and operating system.
( . , . ) substitute options count flags abbr: s
-
If
pat
and
repl
are omitted, then the last substitution is repeated.
This is a synonym for the
&
command.
( . , . ) t addr flags
-
The
t
command is a synonym for
copy.
ta tag
-
The focus of editing switches to the location of
tag,
switching to a different line in the current file where it is defined,
or if necessary to another file.***
-
The tags file is normally created by a program such as
ctags,
and consists of a number of lines with three fields separated by blanks
or tabs. The first field gives the name of the tag,
the second the name of the file where the tag resides, and the third
gives an addressing form which can be used by the editor to find the tag;
this field is usually a contextual scan using `/pat/' to be immune
to minor changes in the file. Such scans are always performed as if
nomagic
was set.
The tag names in the tags file must be sorted alphabetically.
unabbreviate word abbr: una
-
Delete
word
from the list of abbreviations.
undo abbr: u
-
Reverses the changes made in the buffer by the last
buffer editing command.
Note that
global
commands are considered a single command for the purpose of
undo
(as are
open
and
visual.)
Also, the commands
write
and
edit
which interact with the
file system cannot be undone.
Undo
is its own inverse.
-
Undo
always marks the previous value of the current line `.'
as `'''.
After an
undo
the current line is the first line restored
or the line before the first line deleted if no lines were restored.
For commands with more global effect
such as
global
and
visual
the current line regains it's pre-command value after an
undo.
unmap lhs
-
The macro expansion associated by
map
for
lhs
is removed.
( 1 , $ ) v /pat/ cmds
-
A synonym for the
global
command variant g!, running the specified cmds on each
line which does not match pat.
version abbr: ve
-
Prints the current version number of the editor
as well as the date the editor was last changed.
( . ) visual type count flags abbr: vi
-
Enters visual mode at the specified line.
Type
is optional and may be `-' , `\(ua' or `.'
as in the
z
command to specify the placement of the specified line on the screen.
By default, if
type
is omitted, the specified line is placed as the first on the screen.
A
count
specifies an initial window size; the default is the value of the option
window.
See the document
An Introduction to Display Editing with Vi
for more details.
To exit this mode, type Q.
visual file
visual +n file
-
From visual mode,
this command is the same as edit.
( 1 , $ ) write file abbr: w
-
Writes changes made back to file, printing the number of lines and
characters written.
Normally file is omitted and the text goes back where it came from.
If a file is specified, then text will be written to that file.*
If the file does not exist it is created.
The current file name is changed only if there is no current file
name; the current line is never changed.
-
If an error occurs while writing the current and
edited
file, the editor
considers that there has been ``No write since last change''
even if the buffer had not previously been modified.
( 1 , $ ) write>> file abbr: w>>
-
Writes the buffer contents at the end of
an existing file.
-
w! name
-
Overrides the checking of the normal write command,
and will write to any file which the system permits.
( 1 , $ ) w !command
-
Writes the specified lines into
command.
Note the difference between w! which overrides checks and
w ! which writes to a command.
wq name
-
Like a write and then a quit command.
wq! name
-
The variant overrides checking on the sensibility of the
write
command, as w! does.
xit name
-
If any changes have been made and not written, writes the buffer out.
Then, in any case, quits.
( . , . )yank buffer count abbr: ya
-
Places the specified lines in the named
buffer,
for later retrieval via
put.
If no buffer name is specified, the lines go to a more volatile place;
see the put command description.
( .+1 ) z count
-
Print the next count lines, default window.
( . ) z type count
-
Prints a window of text with the specified line at the top.
If type is `-' the line is placed at the bottom; a `.' causes
the line to be placed in the center.*
A count gives the number of lines to be displayed rather than
double the number specified by the scroll option.
On a CRT the screen is cleared before display begins unless a
count which is less than the screen size is given.
The current line is left at the last line printed.
! command
-
The remainder of the line after the `!' character is sent to a shell
to be executed.
Within the text of
command
the characters
`%' and `#' are expanded as in filenames and the character
`!' is replaced with the text of the previous command.
Thus, in particular,
`!!' repeats the last such shell escape.
If any such expansion is performed, the expanded line will be echoed.
The current line is unchanged by this command.
-
If there has been ``[No write]'' of the buffer contents since the last
change to the editing buffer, then a diagnostic will be printed
before the command is executed as a warning.
A single `!' is printed when the command completes.
( addr , addr ) ! command
-
Takes the specified address range and supplies it as
standard input to
command;
the resulting output then replaces the input lines.
( $ ) =
-
Prints the line number of the
addressed line.
The current line is unchanged.
( . , . ) > count flags
( . , . ) < count flags
-
Perform intelligent shifting on the specified lines;
< shifts left and > shift right.
The quantity of shift is determined by the
shiftwidth
option and the repetition of the specification character.
Only white space (blanks and tabs) is shifted;
no non-white characters are discarded in a left-shift.
The current line becomes the last line which changed due to the
shifting.
^D
-
An end-of-file from a terminal input scrolls through the file.
The
scroll
option specifies the size of the scroll, normally a half screen of text.
( .+1 , .+1 )
( .+1 , .+1 ) |
-
An address alone causes the addressed lines to be printed.
A blank line prints the next line in the file.
( . , . ) & options count flags
-
Repeats the previous
substitute
command.
( . , . ) ~ options count flags
-
Replaces the previous regular expression with the previous
replacement pattern from a substitution.