.ds LF Computing Services, U.C. Berkeley
Ex/Edit Command Summary (Version 2.0)
are text editors, used for creating
and modifying files of text on the \*U
with features designed to
In terms of command syntax and effect
the editors are essentially identical,
and this command summary applies to both.
The summary is meant as a quick reference
for users already acquainted
Fuller explanations of the editors are available
(a self-teaching introduction) and the
(the comprehensive reference source for
both \fIedit\fP and \fIex\fP).
Both of these writeups are available in the
Computing Services Library.
In the examples included with the
summary, commands and text entered by
the user are printed in \fBboldface\fR to
distinguish them from responses printed
In order to perform its tasks
the editor sets aside a temporary
separate from the user's permanent
Before starting to work on an existing
file the editor makes a copy of it in the
buffer, leaving the original untouched.
All editing changes are made to the
buffer copy, which must then
be written back to the permanent
file in order to update the
at the end of the editing session.
Editing: Command and Text Input Modes
During an editing session there are
two usual modes of operation:
\fIcommand\fP mode and \fItext input\fP
(This disregards, for the moment,
In command mode, the editor issues a
to show that it is ready to
accept and execute a command.
In text input mode, on the other hand, there is
no prompt and the editor merely accepts text to
Text input mode is initiated by the commands
\fIappend\fP, \fIinsert\fP, and \fIchange\fP,
and is terminated by typing a period as the
first and only character on a line.
Line Numbers and Command Syntax
The editor keeps track of lines of text
in the buffer by numbering them consecutively
starting with 1 and renumbering
as lines are added or deleted.
At any given time the editor is positioned
at one of these lines; this position is
called the \fIcurrent line\fP.
Generally, commands that change the
contents of the buffer print the
new current line at the end of their
Most commands can be preceded by one or two
line-number addresses which indicate the lines
If one number is given the command operates on
that line only; if two, on an inclusive range
Commands that can take line-number prefixes also
assume default prefixes if none are given.
The default assumed by each command is designed
to make it convenient to use in many instances
without any line-number prefix.
For the most part, a command used without a
prefix operates on the current line,
though exceptions to this rule should be noted.
by itself, for instance, causes
one line, the current line, to be
The summary shows the number of line addresses
prefixed to each command as well as
the defaults assumed if they are omitted.
means that up to 2 line-numbers may be given,
and that if none is given the
command operates on the current line.
(In the address prefix notation, ``.'' stands
for the current line and ``$'' stands for
the last line of the buffer.)
If no such notation appears, no
line-number prefix may be used.
Some commands take trailing
the more important instances of this
are mentioned in the summary.
Besides command and text input modes,
provide on some CRT terminals other modes of editing,
In these modes the cursor can
be moved to individual words
The commands then given are very different
from the standard editor commands; most do not appear on the screen when
An Introduction to Display Editing with Vi
provides a full discussion.
Some characters take on special meanings
when used in context searches
and in patterns given to the \fIsubstitute\fP command.
For \fIedit\fR, these are ``^'' and ``$'',
meaning the beginning and end of a line,
has the following additional special characters:
To use one of the special characters as its
simple graphic representation
rather than with its special meaning,
precede it by a backslash (\\).
The backslash always has a special meaning.
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
Name Abbr Description Examples
adding lines to the buffer after
the line specified. Appending continues
until ``.'' is typed alone at the
beginning of a new line, followed by
a carriage return. \fI0a\fR places
lines at the beginning of the buffer.
Deletes indicated line(s) and
initiates text input mode to
replace them with new text which follows.
New text is terminated the same way
\fR(.,.)\fBcopy \fIaddr co T{
Places a copy of the specified lines
after the line indicated by \fIaddr\fR.
The example places a copy of lines 8 through
12, inclusive, after line 25.
\fRLast line copied is printed
Removes lines from the buffer
and prints the current line after the deletion.
\fRNew current line is printed
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
\fRClears the editor buffer and then
copies into it the named \fIfile\fR,
which becomes the current file.
This is a way of shifting to a different
without leaving the editor.
The editor issues a warning
message if this command is used before
made to the file already in the buffer;
using the form \fBe!\fR overrides this protective mechanism.
No write since last change
"ch10" 3 lines, 62 characters
\fRIf followed by a \fIname\fR, renames
the current file to \fIname\fR.
If used without \fIname\fR, prints
the name of the current file.
\fR"ch9" [Modified] 3 lines ...
\fR"ch9" [Modified] 3 lines ...
(1,$)\fBglobal g \fBglobal/\fIpattern\fB/\fIcommands T{
\fR(1,$)\fBglobal! g!\fR or \fBv T{
Searches the entire buffer (unless a smaller
range is specified by line-number prefixes) and
executes \fIcommands\fR on every line with
an expression matching \fIpattern\fR.
The second form, abbreviated
either \fBg!\fR or \fBv\fR,
executes \fIcommands\fR on lines that \fIdo
not\fR contain the expression \fIpattern\fR.
Inserts new lines of text immediately before the speciffied line.
only in that text is placed before, rather than after, the indicated lne.
In other words, \fB1i\fR has the same effect as \fB0a\fR.
be added prior to line 1.
Join lines together, adjusting white space (spaces
Resulting line is printed
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
Name Abbr Description Examples
\fRPrints lines in a more
unambiguous way than the \fIprint\fR
command does. The end of a line,
for example, is marked with a ``$'',
and tabs printed as ``^I''.
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
\fR(.,.)\fBmove \fIaddr\fB m T{
\fRMoves the specified lines
to a position after the line
New current line is printed
Prints each line preceded
by its buffer line number.
\0\0\fR10\0 This is line 10
Too involved to discuss here,
but if you enter open mode
the \s-2ESC\s0 key followed by
get back into normal editor
\fIEdit\fP is designed to
prevent accidental use of
Saves a copy of the current buffer contents as though the system had
just crashed. This is for use in an emergency when a
command has failed and you don't know how else to save your work.\(dg
\fR(.,.)\fBprint p Prints the text of line(s). T{
The second and third lnes
\(dg Seek assistance from a consultant as soon as possible
after saving a file with the
command, because the file is saved on system storage space for only one week.
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
\fREnds the editing session.
warning if you have changed the buffer
since last writing its contents
to the file. In this event you
must either type \fBw\fR to write,
or type \fBq!\fR to exit from
the editor without saving your changes.
\fRNo write since last change
\fR(.)\fBread \fIfile\fP r T{
\fRPlaces a copy of \fIfile\fR in the
buffer after the specified line.
Address 0 is permissible and causes
the copy of \fIfile\fR to be placed
at the beginning of the buffer.
The \fIread\fP command does not
erase any text already in the buffer.
If no line number is specified,
\fIfile\fR is placed after the
\fR"newfile" 5 lines, 86 characters
\fBrecover \fIfile\fP rec T{
Retrieves a copy of the editor buffer
after a system crash, editor crash,
phone line disconnection, or
\fR(.,.)\fBsubstitute s T{
\fBsubstitute/\fIpattern\fB/\fIreplacement\fB/
substitute/\fIpattern\fB/\fIreplacement\fB/gc
\fRReplaces the first ocurrence of \fIpattern\fR
Including a \fBg\fR after the command
changes all occurrences of \fIpattern\fP
The \fBc\fR option allows the user to
confirm each substitution before it is
made; see the manual for details.
\fRLine 3 contains a misstake
\fRLine 3 contains a mistake
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
Name Abbr Description Examples
\fRReverses the changes made in
the buffer by the last buffer-editing
Note that this example contains
a notification about the number of
new line number 1 is printed
\fR15 more lines in file ...
old line number 1 is printed
\fR(1,$)\fBwrite \fIfile\fR w T{
\fRCopies data from the buffer onto
a permanent file. If no \fIfile\fR
is named, the current filename
The file is automatically created
if it does not yet exist.
A response containing the number of
lines and characters in the file
has been completed successfully.
The editor's built-in protections
against overwriting existing files
will in some circumstances
The form \fBw!\fR forces the
an existing file is to be overwritten.
\fR"file7" 64 lines, 1122 characters
\fR"file8" File exists ...
\fR"file8" 64 lines, 1122 characters
\fR(1,$)\fBwrite! \fIfile\fP w! \^ \^
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
\fR(.)\fBz \fIcount\fP z T{
\fRPrints a screen full of text starting
or, if \fIcount\fR is specified,
prints that number of lines.
Variants of the \fIz\fR command
are described in the manual.
Executes the remainder of the line
after \fB!\fR as a \*U command.
The buffer is unchanged by this, and
control is returned to the editor when
the execution of \fIcommand\fR is complete.
\fRFri Jun 9 12:15:11 PDT 1978
Prints the next \fIscroll\fR of text,
normally half of a screen. See the
manual for details of the \fIscroll\fR
An address alone followed by a carriage
return causes the line to be printed.
A carriage return by itself prints the
line following the current line.
the line after the current line
ltw(1.0i) lt2w(0.40i)fB ltw(3.0i) ltw(1.8i).
\fRSearches for the next line in which
\fIpattern\fR occurs and prints it.
\fRThis pattern next occurs here.
Repeats the most recent search.
\fRThis pattern also occurs here.
Searches in the reverse direction
Repeats the most recent search,
moving in the reverse direction