4.4BSD/usr/src/Foreign/man/ed.0
ED(1) BSD Reference Manual ED(1)
NNAAMMEE
eedd - text editor
SSYYNNOOPPSSIISS
eedd [--] [_f_i_l_e]
DDEESSCCRRIIPPTTIIOONN
EEdd once was the standard text editor in the early days of UNIX. While its
life as a line editor is dated, eedd still resides on systems produced by a
variety of vendors for good reason. Because of its small size and sim-
plicity, eedd,, is found on the root partition (_/_b_i_n_/_e_d) for emergency edit-
ing when normal system reboots fail or single user tasks are performed
and _/_u_s_r is not mounted. EEdd is also useful for script editing tasks, and
although there is nothing which can be done by eedd that cannot be per-
formed by sed(1), ex(1) or _G_n_u _E_m_a_c_s, eedd remains the simplest and easi-
est to use.
If a _f_i_l_e argument is given, eedd simulates an ee command (see below) on the
named file; that is to say, the file is read into eedd's buffer so that it
can be edited.
Available options:
-- Suppresses the printing of explanatory output and should be used
when the standard input is an editor script.
EEdd operates on a copy of any file it is editing; changes made in the copy
have no effect on the file until a ww (write) command is given. The copy
of the text being edited resides in a temporary file called the _b_u_f_f_e_r.
Commands to eedd have a simple and regular structure: zero or more
_a_d_d_r_e_s_s_e_s followed by a single character ccoommmmaanndd, possibly 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 al-
low the addition of text to the buffer. While eedd is accepting text, it
is said to be in _i_n_p_u_t _m_o_d_e. 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.
EEdd supports a limited form of _r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n notation. A regular ex-
pression specifies a set of strings of characters. A member of this set
of strings is said to be _m_a_t_c_h_e_d by the regular expression. In the fol-
lowing specification for regular expressions the word `character' means
any character but newline.
1. Any character except a special character matches itself. Special
characters are the regular expression delimiter plus `\[.' and some-
times `^*$'.
2. A ``.'' matches any character.
3. A `\' followed by any character except a digit or ( matches that
character.
4. A nonempty string _s bracketed [_s] (or [_^_s]) matches any character in
(or not in) _s_. In _s_, `\' has no special meaning, and may only appear
as the first letter. A substring _a_-_b, with _a and _b in ascending
ASCII order, stands for the inclusive range of ASCII characters.
5. A regular expression of form 1-4 followed by `*' matches a sequence
of 0 or more matches of the regular expression.
6. A regular expression, _x, of form 1-8, bracketed \( _x\) matches what
_x matches.
7. A \ followed by a digit _n matches a copy of the string that the
bracketed regular expression beginning with the _nth \( matched.
8. A regular expression of form 1-8, _x, followed by a regular expres-
sion of form 1-7, _y matches a match for _x followed by a match for _y,
with the _x match being as long as possible while still permitting a
_y match.
9. 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.
10. A regular expression of form 1-9 picks out the longest among the
leftmost matches in a line.
11. An empty regular expression stands for a copy of the last regular
expression encountered.
Regular expressions are used in addresses to specify lines and in one
command (see _s below) to specify a portion of a line which is to be re-
placed. If it is desired to use one of the regular expression metachar-
acters as an ordinary character, that character may be preceded by `\'.
This also applies to the character bounding the regular expression (often
`/') and to `\' itself.
To understand addressing in eedd it is necessary to know that at any time
there is a _c_u_r_r_e_n_t _l_i_n_e_. 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 the command. Addresses are con-
structed as follows.
1. The character `_.' addresses the current line.
2. The character `_$' addresses the last line of the buffer.
3. A decimal number _n addresses the _nth line of the buffer.
4. `'_x' addresses the line marked with the name _x, which must be a low-
er-case letter. Lines are marked with the _k command described be-
low.
5. 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 buffer.
6. 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 expres-
sion. If necessary the search wraps around to the end of the
buffer.
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.
8. 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 `.-5'.
9. If an address ends with `+' or `-' then 1 is added (resp. subtract-
ed). As a consequence of this rule and rule 8, the address `-'
refers to the line before the current line. Moreover, trailing `+'
and `-' characters have cumulative effect, so `--' refers to the
current line less 2.
10. To maintain compatibility with earlier versions of the editor, the
character `^' in addresses is equivalent to `-'
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 insuffi-
cient are given. If more addresses are given than such a command re-
quires, 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 back-
ward searches (`/', `?') The second address of any two-address sequence
must correspond to a line following the line corresponding to the first
address. The special form `%' is an abbreviation for the address pair
`1,$'.
In the following list of eedd 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, most commands may be suffixed by `p' or by `l', in
which case 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 be line numbered. These suffixes may be
combined in any order.
(_.)aa
<text>
..
The append 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.
(_.,_.)cc
<text>
..
The change command deletes the addressed lines, then accepts input
text which replaces these lines. `_.' is left at the last line in-
put; if there were none, it is left at the line preceding the
deleted lines.
(_.,_.)dd
<text>
..
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.
ee _f_i_l_e_n_a_m_e
The edit 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.
_f_i_l_e_n_a_m_e is remembered for possible use as a default file name in a
subsequent rr or ww command. If _f_i_l_e_n_a_m_e is missing, the remembered
name is used.
EE _f_i_l_e_n_a_m_e
This command is the same as ee, except that no diagnostic results
when no ww has been given since the last buffer alteration.
ff _f_i_l_e_n_a_m_e
The filename command prints the currently remembered file name. If
_f_i_l_e_n_a_m_e is given, the currently remembered file name is changed to
_f_i_l_e_n_a_m_e.
(_1,_$)gg_/_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n_/ccoommmmaanndd lliisstt
In the global 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 In the global 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 `\\' AA, ii, and cc commands and associated in-
put are permitted; the `_.' terminating input mode may be omitted if
it would be on the last line of the command list. The commands gg
and vv are not permitted in the command list.
(_.)ii
<text>
..
This command inserts the given text before the addressed line. `_.'
is left at the last line input, or, if there were none, at the line
before the addressed line. This command differs from the aa command
only in the placement of the text.
(_.,_._+_1)jj
This command joins the addressed lines into a single line; interme-
diate newlines simply disappear. `_.' is left at the resulting
line.
(_.)kk_x
The mark command marks the addressed line with name _x, which must
be a lower-case letter. The address form _'_x then addresses this
line.
(_.,_.)ll
The list command prints the addressed lines in an unambiguous way:
non-graphic characters are printed in two-digit octal, and long
lines are folded. The _l command may be placed on the same line af-
ter any non-i/o command.
(_.,_.)mm_a
The move command repositions the addressed lines after the line ad-
dressed by `_a'. The last of the moved lines becomes the current
line.
(_.,_.)pp
The print command prints the addressed lines. `_.' is left at the
last line printed. The pp command may be placed on the same line
after any non-i/o command.
(_.,_.)PP
This command is a synonym for pp.
qq The quit command causes eedd to exit. No automatic write of a file
is done.
QQ This command is the same as qq, except that no diagnostic results
when no ww has been given since the last buffer alteration.
(_$,_.)rr _f_i_l_e_n_a_m_e
The read 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 ee and ff commands). The file name is remembered if there was
no remembered file name already. Address `0' is legal for rr 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.
(_1,_$)gg_/_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n_/rreeppllaacceemmeenntt lliisstt or,
(_1,_$)gg_/_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n_/rreeppllaacceemmeenntt lliisstt//gg
The substitute command searches each addressed line for an occur-
rence 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 gg 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 expres-
sion and the replacement. `_.' is left at the last line substitut-
ed. 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 `\\' The
characters `\\_n' where _n is a digit, are replaced by the text
matched by the regular subexpression enclosed between _n`' and `\\))'
When nested, parenthesized subexpressions are present, _n is deter-
mined by counting occurrences of `\\((' starting from the left.
Lines may be split by substituting new-line characters into them.
The new-line in the replacement string must be escaped by preceding
it by `\\' One or two trailing delimiters may be omitted, implying
the pp suffix. The special form ss followed by _n_o delimiters repeats
the most recent substitute command on the addressed lines. The ss
may be followed by the letters rr (use the most recent regular ex-
pression for the left hand side, instead of the most recent left
hand side of a substitute command), pp (complement the setting of
the pp suffix from the previous substitution), or gg (complement the
setting of the gg suffix). These letters may be combined in any or-
der.
(_.,_.)tt_a
This command acts just like the mm command, except that a copy of
the addressed lines is placed after address _a (which may be 0).
`_.' is left on the last line of the copy.
(_.,_.)uu
The undo command restores the buffer to it's state before the most
recent buffer modifying command. The current line is also re-
stored. Buffer modifying commands are aa, cc, dd, gg, ii, kk, mm, rr, ss,
tt, and vv. For purposes of undo, gg and vv are considered to be a sin-
gle buffer modifying command. Undo is its own inverse. When eedd
runs out of memory (at about 8000 lines on any 16 bit mini-computer
such as the PDP-11) This full undo is not possible, and uu can only
undo the effect of the most recent substitute on the current line.
This restricted undo also applies to editor scripts when eedd is in-
voked with the -- option.
(_1,_$)vv_/_r_e_g_u_l_a_r _e_x_p_r_e_s_s_i_o_n_/ccoommmmaanndd lliisstt
This command is the same as the global command gg except that the
command list is executed gg with `_.' initially set to every line
_e_x_c_e_p_t those matching the regular expression.
(_1,_$)ww _f_i_l_e_n_a_m_e
The write command writes the addressed lines onto the given file.
If the file does not exist, it is created. The file name is remem-
bered if there was no remembered file name already. If no file
name is given, the remembered file name, if any, is used (see ee and
ff commands). `_.' is unchanged. If the command is successful, the
number of characters written is printed.
(_1,_$)WW _f_i_l_e_n_a_m_e
This command is the same as ww, except that the addressed lines are
appended to the file.
(_1,_$)wwqq _f_i_l_e_n_a_m_e
This command is the same as ww except that afterwards a qq command is
done, exiting the editor after the file is written.
(_._+_1)zz or,
(_._+_1)zz_n
This command scrolls through the buffer starting at the addressed
line. 22 (or _n, if given) lines are printed. The last line print-
ed becomes the current line. The value _n is sticky, in that it be-
comes the default for future zz commands.
(_$)== The line number of the addressed line is typed. `_.' is unchanged
by this command.
_!<shell command>
The remainder of the line after the `!!' is sent to sh(1) to be in-
terpreted as a command. `_.' is unchanged.
(_._+_1,_._+_1)<newline>
An address alone on a line causes the addressed line to be printed.
A blank line alone is equivalent to _._+_1 it is useful for stepping
through text. If two addresses are present with no intervening
semicolon, eedd 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, eedd prints `?interrupted' and
returns to its command level.
Some size limitations: 512 characters per line, 256 characters per global
command list, 64 characters per file name, and, on mini computers, 128K
characters in the temporary file. The limit on the number of lines de-
pends on the amount of core: each line takes 2 words.
When reading a file, eedd discards ASCII NUL characters and all characters
after the last newline. It refuses to read files containing non- ASCII
characters.
FFIILLEESS
/tmp/e*
edhup work is saved here if terminal hangs up
SSEEEE AALLSSOO
ex(1), sed(1), crypt(1)
B. W. Kernighan, _A _T_u_t_o_r_i_a_l _I_n_t_r_o_d_u_c_t_i_o_n _t_o _t_h_e _E_D _T_e_x_t _E_d_i_t_o_r
B. W. Kernighan, _A_d_v_a_n_c_e_d _e_d_i_t_i_n_g _o_n _U_N_I_X
HHIISSTTOORRYY
The eedd command appeared in
DDIIAAGGNNOOSSTTIICCSS
`name' for inaccessible file; `?self-explanatory message' for other er-
rors.
To protect against throwing away valuable work, a qq or ee command is con-
sidered to be in error, unless a ww has occurred since the last buffer
change. A second qq or ee will be obeyed regardless.
BBUUGGSS
The ll command mishandles DEL.
The uunnddoo command causes marks to be lost on affected lines.
The special treatment of hangups only works on UNIX.
AT&T 7th Edition August 19, 1993 7