Research V3 development
[unix-history] / man / man1 / ed.1
.pa 1
.he 'ED (I)'1/15/73'ED (I)'
.tr |
.ti 0
NAME
.br
ed -- editor
.sp
.ti 0
SYNOPSIS
.br
ed\b\b__ [ name ]
.sp
.ti 0
DESCRIPTION
.br
.in -8
ed\b\b__
is the standard text editor.
.sp
If the optional argument is given, ed\b\b__
simulates an e\b_ command on the named file; that is to say,
the file is read into ed\b\b__'s buffer so that it can be edited.
.sp
ed\b\b__ operates on a copy of any file it is editing; changes made
in the copy have no effect on the file until a write
(w\b_) command is given.
The copy of the text being edited resides
in a temporary file called the buffer\b\b\b\b\b\b______. There is only
one buffer.
.sp
Commands to ed\b\b__ have a simple and regular structure: zero or
more addresses\b\b\b\b\b\b\b\b\b_________ followed by a single character command\b\b\b\b\b\b\b_______, possibly
followed by parameters to the command.
These addresses specify one or more lines in the buffer.
Every command which requires addresses has default addresses,
so that the addresses can often be omitted.
.sp
In general, only one command may appear on a line.
Certain commands allow the input of text.
This text is placed in the appropriate place in the buffer.
While ed\b\b__ is accepting text, it is said
to be in input\b\b\b\b\b_____ mode\b\b\b\b____. In this mode, no commands are recognized;
all input is merely collected.
Input mode is left by typing a period (.) alone at the
beginning of a line.
.sp
ed\b\b__ supports a limited form of regular\b\b\b\b\b\b\b_______ expression\b\b\b\b\b\b\b\b\b\b__________ notation.
A regular expression is an expression which specifies
a set of strings of characters.
A member of this set of strings is said to be matched\b\b\b\b\b\b\b_______
by the regular expression.
The regular expressions allowed by ed\b\b__ are constructed as follows:
.sp
.in +6
.ti -3
1. An ordinary character (not one of those discussed below)
is a regular expression and matches that character.
.sp
.ti -3
2. A circumflex (^) at the beginning of a regular expression
matches the null character at the beginning of a line.
.sp
.ti -3
3. A currency symbol ($) at the end of a regular expression
matches the null character at the end of a line.
.sp
.ti -3
4. A period (.) matches any character but a new-line character.
.ti -3
5. A regular expression followed by an asterisk (*)
matches any number of adjacent occurrences (including zero)
of the regular expression it follows.
.ti -3
6. A string of characters enclosed in square brackets
([]) matches any character in the string but no others.
If, however, the first character of the string is a circumflex
(^) the regular expression matches any character but new-line
and the characters in the string.
.ti -3
7. The concatenation of regular expressions is a regular
expression which matches the concatenation of the strings
matched by the components of the regular expression.
.ti -3
8. The null regular expression standing alone
is equivalent to the last regular expression encountered.
.in -6
Regular expressions are used in addresses to specify
lines and in one command (s\b_, see below)
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 "\\".
This also applies to the character bounding the regular
expression (often "/") and to "\\" itself.
.sp
Addresses are constructed as follows.
To understand addressing in ed\b\b__
it is necessary to know that at any time there is a current\b\b\b\b\b\b\b_______
line\b\b\b\b____. Generally speaking, the current line is
the last line affected by a command; however,
the exact effect on the current line
by each command is discussed under the description of
the command.
.in +6
.ti -3
1. The character "." addresses the current line.
.ti-3
2.|The character "^" addresses the line immediately before the current line.
.sp
.ti -3
3. The character "$" addresses the last line of the buffer.
.ti -3
4. A decimal number n\b_ addresses the n\b_th line of the buffer.
.ti -3
6. A regular expression enclosed in slashes "/" addresses
the first line found by searching toward the end of the
buffer and stopping at the first line containing a
string matching the regular expression.
If necessary the search wraps around to the beginning of the
buffer.
.ti -3
5. A regular expression enclosed in queries "?" addresses
the first line found by searching toward the beginning of
the buffer and stopping at the first line found containing
a string matching the regular expression. If necessary
the search wraps around to the end of the buffer.
.ti -3
7. 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.
.ti-3
8.|"'x" addresses the line associated (marked) with the
mark name character "x"
which must be a printable character.
Lines may be marked with the "k" command described below.
.sp
.in -6
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 "." 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.
In the following list of ed\b\b__ 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
the default.
As mentioned, it is generally illegal for more than one
command to appear on a line.
However, any command may be suffixed by "p" (for "print").
In that case, the current line is printed after the command
is complete.
.ne 6
.in +6
.ti -3
(.)a
.ti -3
<text>
.ti -3
.li
\1f.
.br
The a\b_ppend command reads the given text
and appends it after the addressed line. "." is left
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.
.ti -3
(.,.)c
.ti -3
<text>
.ti -3
\1f.
.br
The c\b_hange
command deletes the addressed lines, then accepts input
text which replaces these lines.
"." is left at the last line input; if there were none,
it is left at the first line not changed.
.ti -3
(.,.)d
.br
The d\b_elete 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.
.ti -3
e filename
.br
The e\b_dit
command causes the entire contents of the buffer to be deleted,
and then the named file to be read in.
"." 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
in a subsequent r\b_ or w\b_ command.
.sp
.ti-3
f filename
.br
The f\b_ilename command prints the currently remembered file name.
If "filename" is given,
the currently remembered file name is changed to "filename".
.ti -3
(1,$)g/regular expression/command list
.br
In the g\b_lobal
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 "." 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 "\\".
a\b_, i\b_, and c\b_ commands and associated input are permitted;
the "." terminating input mode may be omitted if it would be on the
last line of the command list.
The (global) commands, g\b_ and v\b_, are not permitted in the command list.
.ti -3
(.)i
.ti -3
<text>
.ti -3
\1f.
.br
This command i\b_nserts the given text before the addressed line.
"." is left at the last line input; if there were none,
at the addressed line.
This command differs from the a\b_ command only in the placement of the
text.
.ti-3
(.)kx
.br
The mark\b_ command associates or marks the addressed line with
the single character mark name "x".
The ten most recent mark names are remembered.
The current mark names may be printed with the n\b_ command.
.ti -3
(.,.)mA
.br
The m\b_ove command will reposition the addressed lines after the line
addressed by "A".
The line originally after the last line moved becomes the current line;
if the lines moved were originally at the end,
the new last line becomes the current line.
.ti-3
n
.br
The markn\b_ames command will print the current mark names.
.ti -3
(.,.)p
.br
The p\b_rint command prints the addressed lines. "."
is left at the last line printed.
The p\b_ command may\b\b\b___ be placed on the same line after any command.
.ti -3
q\b_
.br
The q\b_uit command causes ed\b\b__ to exit. No automatic write
of a file is done.
.ti -3
($)r filename
.br
The r\b_ead command
reads in the given file after the addressed line.
If no file name is given,
the remembered file name, if any, is used (see e\b_ and f\b_ commands).
The remembered file name is not changed unless
"filename" is the very first file name
mentioned.
Address "0" is legal for r\b_ and causes the
file to be read at the beginning of the buffer.
If the read is successful, the number of characters
read is typed.
"." is left at the last line read in from the file.
.ti -3
(.,.)s/regular expression/replacement/ or,
.ti -3
(.,.)s/regular expression/replacement/g
.br
The s\b_ubstitute 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 character other than space or new-line
may be used instead of "/" to delimit the regular expression
and the replacement.
"." is left at the last line substituted.
The ampersand "&" appearing in the replacement
is replaced by the regular expression that was matched.
The special meaning of "&" in this context may be
suppressed by preceding it by "\\".
.ti -3
(1,$)v/regular expression/command list
.br
This command is the same as the g\b_lobal command
except that the command list is executed
with "." initially set to every line except\b\b\b\b\b\b______ those
matching the regular expression
.ti -3
(1,$)w filename
.br
The w\b_rite command writes the addressed lines onto
the given file.
If the file does not exist,
it is created mode 17 (readable and writeable by everyone).
The remembered file name is not\b\b\b___ changed unless
"filename" is the very first file name mentioned.
If no file name is given,
the remembered file name, if any, is used (see e\b_ and f\b_ commands).
"." is unchanged.
If the command is successful, the number of characters written is
typed.
.ti -3
($)=
.br
The line number of the addressed line is typed.
"." is unchanged by this command.
.ti -3
!UNIX command
.br
The remainder of the line after the "!" is sent
to UNIX to be interpreted as a command.
"." is unchanged.
.ti -3
(.+1)<newline>
.br
An address alone on a line causes that line to be printed.
A blank line alone is equivalent to ".+1p"; it is useful
for stepping through text.
.in -6
If an interrupt signal (ASCII DEL) is sent,
ed\b\b__ will print a "?" and return to its command level.
If invoked with the command name '-', (see init\b\b\b\b____)
ed\b\b__ will sign on with the message "Editing system"
and print "*" as the command level prompt character.
.sp
Ed\b\b__ has size limitations on the maximum number of lines that can be edited,
and on the maximum number of characters in a line,
in a global's command list,
and in a remembered file name.
These limitations vary with the physical core size of the PDP11 computer
on which ed\b\b__ is being used.
The range of limiting sizes
for the above mentioned items is;
1300|-|4000 lines per file,
256|-|512 characters per line,
63|-|256 characters per global command list,
and
64 characters per file name.
.sp
.ti 0
.in +8
FILES
.br
/tmp/etm? temporary
.br
/etc/msh to implement the "!" command.
.sp
.ti 0
SEE ALSO --
.sp
.ti 0
DIAGNOSTICS "?" for any error
.sp
.ti 0
BUGS --