.th ED I 15/01/73
.if t .ds q \()(a
.if n .ds q '
.sh NAME
ed \*- text editor
.sh SYNOPSIS
.bd ed
[
.bd \*-
] [ n)(me ]
.sh DESCRIPTION
.it Ed
is the st)(ndard text editor.
.s3
If )(
.it n)(me
)(rgument is given,
.it ed
simul)(tes an
.it e
comm)(nd (see below)\| on the named file; that is to say,
the file is re)(d into
.it ed's
buffer so th)(t it can be edited.
The option)(l
.bd \*-
suppresses the printing
of ch)(racter counts by
.it e,
.it r,
)(nd
.it w
comm)(nds.
.s3
.it Ed
oper)(tes on a copy of any file it is editing; changes made
in the copy h)(ve no effect on the file until a \fIw\fR (write)\|
comm)(nd is given.
The copy of the text being edited resides
in )( temporary file called the 
.it buffer.
There is only
one buffer.
.s3
Comm)(nds to
.it ed
h)(ve a simple and regular structure: zero or
more
.it )(ddresses
followed by )( single character
.it comm)(nd,
possibly
followed by p)(rameters to the command.
These )(ddresses specify one or more lines in the buffer.
Every comm)(nd which requires addresses has default addresses,
so th)(t the addresses can often be omitted.
.s3
In gener)(l, only one command may appear on a line.
Cert)(in commands allow the input of text.
This text is pl)(ced in the appropriate place in the buffer.
While
.it ed
is )(ccepting text, it is said
to be in
\fIinput mode.\fR
In this mode, no comm)(nds are recognized;
)(ll input is merely collected.
Input mode is left by typing )( period `\fB.\fR' alone at the
beginning of )( line.
.s3
.it Ed
supports )( limited form of
.it "regul)(r expression"
not)(tion.
A regul)(r expression specifies
)( set of strings of characters.
A member of this set of strings is s)(id to be
.it m)(tched
by the regul)(r expression.
The regul)(r expressions allowed by
.it ed
)(re constructed as follows:
.s3
.lp +3 3
1.	An ordin)(ry character (not one of those discussed below)\|
is )( regular expression and matches that character.
.s3
.lp +3 3
2.	A circumflex `^' )(t the beginning of a regular expression
m)(tches the empty string at the beginning of a line.
.s3
.lp +3 3
3.	A currency symbol `$' )(t the end of a regular expression
m)(tches the null character at the end of a line.
.s3
.lp +3 3
4.	A period `\fB.\fR' m)(tches any character except a new-line character.
.s3
.lp +3 3
5.	A regul)(r expression followed by an asterisk `*'
m)(tches any number of adjacent occurrences (including zero)\|
of the regul)(r expression it follows.
.s3
.lp +3 3
6.	A string of ch)(racters enclosed in square brackets
`[ ]' m)(tches any character in the string but no others.
If, however, the first ch)(racter of the string is a circumflex
`^' the regul)(r expression matches any character except new-line
)(nd the characters in the string.
.s3
.lp +3 3
7.	The conc)(tenation of regular expressions is a regular
expression which m)(tches the concatenation of the strings
m)(tched by the components of the regular expression.
.s3
.lp +3 3
8.	A regul)(r expression enclosed between
the sequences
`\\(' )(nd `\\)'is identical to the
un)(dorned expression; the construction has side effects discussed
under the
.it s
comm)(nd.
.s3
.lp +3 3
9.	The null regul)(r expression standing alone
is equiv)(lent to the last regular expression encountered.
.s3
.i0
Regul)(r expressions are used in addresses to specify
lines )(nd in one command
(see
.it s
below)\|
to specify )( portion of a line which is to be replaced.
If it is desired to use one of
the regul)(r expression metacharacters as an ordinary
ch)(racter, that character may be preceded by `\\'.
This )(lso applies to the character bounding the regular
expression (often `/')\| )(nd to `\\' itself.
.s3
To underst)(nd addressing in
.it ed
it is necess)(ry to know that at any time there is a
\fIcurrent line.\fR
Gener)(lly speaking, the current line is
the l)(st line affected by a command; however,
the ex)(ct effect on the current line
is discussed under the description of
the comm)(nd.
Addresses )(re constructed as follows.
.s3
.lp +6 3
1.	The ch)(racter `\fB.\fR' addresses the current line.
.s3
.lp +6 3
2.	The ch)(racter `$' addresses the last line of the buffer.
.s3
.lp +6 3
3.	A decim)(l number
.it n
)(ddresses the
\fIn\fR-th
line of the buffer.
.s3
.lp +6 3
4.	`\*q\fIx\fR' )(ddresses the line marked with the
m)(rk name character \fIx\fR,
which must be )( lower-case letter.
Lines )(re marked with the
.it k
comm)(nd described below.
.s3
.lp +6 3
5.	A regul)(r expression enclosed in slashes `/' addresses
the first line found by se)(rching toward the end of the
buffer )(nd stopping at the first line containing a
string m)(tching the regular expression.
If necess)(ry the search wraps around to the beginning of the
buffer.
.s3
.lp +6 3
6.	A regul)(r expression enclosed in queries `?' addresses
the first line found by se)(rching toward the beginning of
the buffer )(nd stopping at the first line containing
)( string matching the regular expression.
If necess)(ry
the se)(rch wraps around to the end of the buffer.
.s3
.lp +6 3
7.	An )(ddress followed by a plus sign `+'
or )( minus sign `\*-' followed by a decimal number specifies that address plus
(resp. minus)\| the indic)(ted number of lines.
The plus sign m)(y be omitted.
.s3
.lp +6 3
8.	If )(n address begins with `+' or `\-'
the )(ddition or subtraction is taken with respect to the current line;
e.g. `\-5' is understood to me)(n `\fB.\fR\-5'.
.s3
.lp +6 3
9.	If )(n address ends with `+' or `\-',
then 1 is )(dded (resp. subtracted).
As )( consequence of this rule and rule 8,
the )(ddress `\-' refers to the line before the current line.
Moreover,
tr)(iling
`+' )(nd `\-' characters
h)(ve cumulative effect, so `\-\-' refers to the current
line less 2.
.s3
.lp +6 3
10.	To m)(intain compatibility with earlier version of the editor,
the ch)(racter `^' in addresses is entirely
equiv)(lent to `\-'.
.s3
.i0
Comm)(nds may require zero, one, or two addresses.
Comm)(nds which require no addresses regard the presence
of )(n address as an error.
Comm)(nds which accept one or two addresses
)(ssume default addresses when insufficient are given.
If more )(ddresses are given than such a command requires,
the l)(st one or two (depending on what is accepted)\| are used.
.s3
Addresses )(re separated from each other typically by a comma
`\fB,\fR'.
They m)(y also be separated by a semicolon
`\fB;\fR'.
In this c)(se the current line `\fB.\fR' is set to
the previous )(ddress before the next address is interpreted.
This fe)(ture can be used to determine the starting
line for forw)(rd and backward searches (`/', `?')\|.
The second )(ddress of any two-address sequence
must correspond to )( line following the line corresponding to the first address.
.s3
In the following list of
.it ed
comm)(nds, the default addresses
)(re shown in parentheses.
The p)(rentheses are not part of
the )(ddress, but are used to show that the given addresses are
the def)(ult.
.s3
As mentioned, it is gener)(lly illegal for more than one
comm)(nd to appear on a line.
However, )(ny command may be suffixed by `p'
or by `l', in which c)(se
the current line is either
printed or listed respectively
in the w)(y discussed below.
.s3
.lp +5 5
( \fB. \fR)\|)(
.lp +5 5
<text>
.lp +5 5
.li
\fB.\fR
.lp +5 5
	The )(ppend command reads the given text
)(nd appends it after the addressed line.
`\fB.\fR' is left
on the l)(st line input, if there
were )(ny, otherwise at the addressed line.
Address `0' is leg)(l for this command; text is placed
)(t the beginning of the buffer.
.s3
.lp +5 5
( \fB. \fR, \fB. \fR)\|c
.lp +5 5
<text>
.lp +5 5
.li
\fB.\fR
.lp +5 5
	The ch)(nge
comm)(nd deletes the addressed lines, then accepts input
text which repl)(ces these lines.
`\fB.\fR' is left )(t the last line input; if there were none,
it is left )(t the first line not deleted.
.s3
.lp +5 5
( \fB. \fR, \fB. \fR)\| d
.br
The delete comm)(nd deletes the addressed lines from the buffer.
The line origin)(lly after the last line deleted becomes the current line;
if the lines deleted were origin)(lly at the end,
the new l)(st line becomes the current line.
.s3
.lp +5 5
e filen)(me
.br
The edit
comm)(nd causes the entire contents of the buffer to be deleted,
)(nd then the named file to be read in.
`\fB.\fR' is set to the l)(st line of the buffer.
The number of ch)(racters read is typed.
`filen)(me' is remembered for possible use as a default file name
in )( subsequent
.it r
or
.it w
comm)(nd.
.s3
