is the standard text editor.
command (see below)\| on the named file; that is to say,
buffer so that it can be edited.
all lower case text in the buffer
is converted to upper case.
command is simulated first to handle an encrypted file.
when the standard input is
operates on a copy of any file it is editing; changes made
in the copy have no effect on the file until a
The copy of the text being edited resides
in a temporary file called the
have a simple and regular structure: zero or
followed by a single character
followed by parameters to the command.
These addresses specify one or more lines in the buffer.
Missing addresses are supplied by default.
In general, only one command may appear on a line.
Certain commands allow the
addition of text to the buffer.
is accepting text, it is said
In this mode, no commands are recognized;
all input is merely collected.
Input mode is left by typing a period `\fB.\fR' alone at the
supports a limited form of
A regular expression specifies
a set of strings of characters.
A member of this set of strings is said to be
by the regular expression.
In the following specification for regular expressions
the word `character' means any character but newline.
Any character except a special character
the regular expression delimiter plus
A \e followed by any character except a digit or (\|) matches that character.
matches any character in (or not in)
\e has no special meaning, and ] may only appear as
in ascending ASCII order, stands for the inclusive
range of ASCII characters.
A regular expression of form 1-4 followed by * matches a sequence of
0 or more matches of the regular expression.
matches a copy of the string that the
bracketed regular expression beginning with the
A regular expression of form 1-8,
followed by a regular expression of form 1-7,
match being as long as possible while still permitting a
A regular expression of form 1-8 preceded by ^
(or followed by $), is constrained to matches that
begin at the left (or end at the right) end of a line.
A regular expression of form 1-9 picks out the
longest among the leftmost matches in a line.
An empty regular expression stands for a copy of the
last regular expression encountered.
Regular expressions are used in addresses to specify
to specify a portion of a line which is to be replaced.
If it is desired to use one of
the regular expression metacharacters as an ordinary
character, that character may be preceded by `\e'.
This also applies to the character bounding the regular
expression (often `/')\| and to `\e' itself.
To understand addressing in
it is necessary to know that at any time there is a
Generally speaking, the current line is
the last line affected by a command; however,
the exact effect on the current line
is discussed under the description of
Addresses are constructed as follows.
The character `\fB.\fR' addresses the current line.
The character `$' addresses the last line of the buffer.
`\(fm\fIx\fR' addresses the line marked with the name
which must be a lower-case letter.
Lines are marked with the
A regular expression enclosed in slashes `/' addresses
the line found by searching forward from the current line
and stopping at the first line containing a
string that matches the regular expression.
If necessary the search wraps around to the beginning of the
A regular expression enclosed in queries `?' addresses
the line found by searching backward from the current line
and stopping at the first line containing
a string that matches the regular expression.
the search wraps around to the end of the buffer.
An address followed by a plus sign `+'
or a minus sign `\-' followed by a decimal number specifies that address plus
(resp. minus)\| the indicated number of lines.
The plus sign may be omitted.
If an address begins with `+' or `\-'
the addition or subtraction is taken with respect to the current line;
e.g. `\-5' is understood to mean `\fB.\fR\-5'.
If an address ends with `+' or `\-',
then 1 is added (resp. subtracted).
As a consequence of this rule and rule 8,
the address `\-' refers to the line before the current line.
have cumulative effect, so `\-\-' refers to the current
To maintain compatibility with earlier versions of the editor,
the character `^' in addresses is
Commands may require zero, one, or two addresses.
Commands which require no addresses regard the presence
of an address as an error.
Commands which accept one or two addresses
assume default addresses when insufficient are given.
If more addresses are given than such a command requires,
the last one or two (depending on what is accepted)\| are used.
Addresses are separated from each other typically by a comma
They may also be separated by a semicolon
In this case the current line `\fB.\fR' is set to
the previous address before the next address is interpreted.
This feature can be used to determine the starting
line for forward and backward searches (`/', `?')\|.
The second address of any two-address sequence
must correspond to a line following the line corresponding to the first address.
is an abbreviation for the address pair `1,$'.
commands, the default addresses
are shown in parentheses.
The parentheses are not part of
the address, but are used to show that the given addresses are
As mentioned, it is generally illegal for more than one
command to appear on a line.
However, most commands may be suffixed by `p'
the current line is either
printed or listed respectively
in the way discussed below.
Commands may also be suffixed by `n',
meaning the output of the command is to
These suffixes may be combined in any order.
The append command reads the given text
and appends it after the addressed line.
on the last line input, if there
were any, otherwise at the addressed line.
Address `0' is legal for this command; text is placed
at the beginning of the buffer.
command deletes the addressed lines, then accepts input
text which replaces these lines.
`\fB.\fR' is left at the last line input; if there were none,
it is left at the line preceding the deleted lines.
The delete command deletes the addressed lines from the buffer.
The line originally 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.
command causes the entire contents of the buffer to be deleted,
and then the named file to be read in.
`\fB.\fR' is set to the last line of the buffer.
The number of characters read is typed.
`filename' is remembered for possible use as a default file name
If `filename' is missing, the remembered name is used.
This command is the same as
except that no diagnostic results when no
has been given since the last buffer alteration.
The filename command prints the currently remembered file name.
the currently remembered file name is changed to `filename'.
(1,$)\|g/regular expression/command list
command, the first step is to mark every line which matches
the given regular expression.
Then for every such line, the
given command list is executed with `\fB.\fR' initially set to that line.
A single command or the first of multiple commands
appears on the same line with the global command.
All lines of a multi-line list except the last line must be ended with `\e'.
commands and associated input are permitted;
the `\fB.\fR' terminating input mode may be omitted if it would be on the
last line of the command list.
are not permitted in the command list.
This command inserts the given text before the addressed line.
`\fB.\fR' is left at the last line input, or, if there were none,
at the line before the addressed line.
This command differs from the
command only in the placement of the
This command joins the addressed lines into a single line;
intermediate newlines simply disappear.
`\fB.\fR' is left at the resulting line.
The mark command marks the addressed line with
which must be a lower-case letter.
The address form `\(fm\fIx\fR' then addresses this line.
prints the addressed lines in an unambiguous way:
non-graphic characters are
printed in two-digit octal,
and long lines are folded.
command may be placed on the same line after any non-i/o
.RB (\| .\| ,\ .\| )\|m\fIa
The move command repositions the addressed lines after the line
The last of the moved lines becomes the current line.
The number command prints the addressed lines
with line numbers and a tab at the left.
The print command prints the addressed lines.
is left at the last line printed.
be placed on the same line after any non-i/o command.
This command is a synonym for
This command is the same as
except that no diagnostic results when no
has been given since the last buffer alteration.
reads in the given file after the addressed line.
If no file name is given,
the remembered file name, if any, is used
The file name is remembered if there was no
remembered file name already.
file to be read at the beginning of the buffer.
If the read is successful, the number of characters
`\fB.\fR' is left at the last line read in from the file.
(\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/ or,
(\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/g
The substitute command searches each addressed
line for an occurrence of the specified regular expression.
On each line in which a match is found,
all matched strings are replaced by the replacement specified,
if the global replacement indicator `g' appears after the command.
If the global indicator does not appear, only the first occurrence
of the matched string is replaced.
It is an error for the substitution to fail on all addressed lines.
Any punctuation character
may be used instead of `/' to delimit the regular expression
`\fB.\fR' is left at the last line substituted.
An ampersand `&' appearing in the replacement
is replaced by the string matching the regular expression.
The special meaning of `&' in this context may be
suppressed by preceding it by `\e'.
are replaced by the text matched by the
enclosed between `\e(' and `\e)'.
nested, parenthesized subexpressions
is determined by counting occurrences of `\e(' starting from the left.
Lines may be split by substituting new-line characters into them.
must be escaped by preceding it by `\e'.
One or two trailing delimiters may be omitted,
The special form `s' followed by
repeats the most recent substitute command
The `s' may be followed by the letters
(use the most recent regular expression for the
left hand side, instead of the most recent
left hand side of a substitute command),
(complement the setting of the
suffix from the previous substitution), or
(complement the setting of the
These letters may be combined in any order.
.RB (\| .\| ,\ .\| )\|t\|\fIa
This command acts just like the
command, except that a copy of the addressed lines is placed
`\fB.\fR' is left on the last line of the copy.
The undo command restores the buffer to it's state
before the most recent buffer modifying command.
The current line is also restored.
Buffer modifying commands are
.I a, c, d, g, i, k, m, r, s, t,
are considered to be a single buffer modifying command.
(at about 8000 lines on any 16 bit mini-computer
This full undo is not possible, and
can only undo the effect of the most recent
substitute on the current line.
This restricted undo also applies to editor scripts
(1, $)\|v/regular expression/command list
This command is the same as the global command
except that the command list is executed
with `\fB.\fR' initially set to every line
matching the regular expression.
The write command writes the addressed lines onto
If the file does not exist,
The file name is remembered if there was no
remembered file name already.
If no file name is given,
the remembered file name, if any, is used
If the command is successful, the number of characters written is
This command is the same as
except that the addressed lines are appended to the file.
This command is the same as
after the file is written.
A key string is demanded from the standard input.
commands will encrypt and decrypt the text
with this key by the algorithm of
An explicitly empty key turns off encryption.
This command scrolls through the buffer starting at the addressed line.
The last line printed becomes the current line.
is sticky, in that it becomes the default for
The line number of the addressed line is typed.
`\fB.\fR' is unchanged by this command.
The remainder of the line after the `!' is sent
to be interpreted as a command.
.RB (\| . +1,\| . +1)\|<newline>
An address alone on a line causes the addressed line to be printed.
A blank line alone is equivalent to `.+1p'; it is useful
for stepping through text.
If two addresses are present with no
prints the range of lines.
If they are separated by a semicolon,
the second line is printed.
If an interrupt signal (ASCII DEL)\| is sent,
and returns to its command level.
256 characters per global command list,
64 characters per file name,
128K characters in the temporary file.
The limit on the number of lines depends on the amount of core:
discards ASCII NUL characters
and all characters after the last newline.
It refuses to read files containing non-ASCII characters.
edhup: work is saved here if terminal hangs up
A Tutorial Introduction to the ED Text Editor
.I Advanced editing on UNIX
`?name' for inaccessible file;
`?self-explanitory message'
To protect against throwing away valuable work,
command is considered to be in error, unless a
has occurred since the last buffer change.
will be obeyed regardless.
command causes marks to be lost on affected lines.
special treatment of hangups