4.3BSD/usr/contrib/apl/man/xed.1

Compare this file to the similar file:
Show the results in this format:

.ds v 7.15
.nr sa 35
.ds ex edt
.ds ed xed
.ds Ed Xed
.ds ED XED
.ds ux eXtended
'''.ds ed eed
'''.ds Ed Eed
'''.ds ED EED
'''.ds ux EE/unix
.if t .ds 0 \o'/0'
.if t .ds oq "``
.if t .ds cq "''
.if n .ds oq ""
.if n .ds cq ""
.nh
.TH \*(ED 1 "28 July 1983"
.UC 4
.SH NAME
\*(ed
\(mi \*(ux text EDitor \(mi V\*v
.SH SYNOPSIS
.B \*(ed
[
.B \(mi!@abBcdefhiklmnoOpqrstvwy
] [ name ]
.SH DESCRIPTION
.I \*(Ed
is the \*(ux text EDitor.
.PP
If a
.I name
argument is given,
.I \*(ed
simulates an
.B e
command (see below) on the named file; that is to say,
the file is read into
.IR \*(ed 's
buffer so that it can be edited.
After every \n(sa
(default)
commands have been executed,
the edit buffer will be written
on a scratch file.
When
.I \*(ed
terminates successfully,
the
.I save
file will be removed unless the
.B \(mid
flag was selected.
If a writeable file named \*(oq\c
.I edsav\c
\&\*(cq exists in the current directory,
all commands typed will be written to it.
.PP
The optional flags after the
.B \(mi
have the following functions:
.TP
.B \(mi!
Disallow use of the
.B !
command.
Mostly useful for writing programs which cannot allow
unrestricted access to shell commands.
.TP
.BI \(mi@ fn
Preset the
.I indirect
file name to
.IR fn .
Subsequent use of the
.B @
command will read commands from
.IR fn ,
until the name is changed by giving an argument to the
.B @
command.
.TP
.B \(mia
The line numbers will be printed in
.I apl
mode.
The form is
\*(oq[
.I n
]\fI\et\fP\*(cq
followed by the text.
In addition,
overstruck characters will be printed
on two lines, one above the other.
.I Apl
line numbers begin at
.I zero
instead of one.
.TP
.B \(mib
Make a
.I backup
copy of the edit file
upon entry to the editor.
The file's name will be that of the original
file with a \*(oq\c
.BI . bak\c
\&\*(cq extension.
.TP
.BI \(miB nnnn
Set the
.I line
buffer size to
.I nnnn
(decimal) bytes.
The default line buffer size is 512 bytes,
which limits the maximum length line which may be processed.
Since there are occasions where it is desired to process
longer lines,
the buffer size may be increased.
.TP
.BI \(mic nn
Set the editor's idea of the depth of the Crt screen
for the
.B :
command to
.I nn
(decimal).
Default is 21 lines.
If
.I nn
is zero, the paging will be disabled.
(See also the
.I d=nn
command.)
.TP
.B \(mid
Disables the deletion of the file created via the
.I auto-save
feature.
(The \*(oq\c
.BI . \*(ex\c
\&\*(cq file.)
.TP
.B \(mie
Each input command will be echoed on standard output.
This is useful for debugging editor command files,
since the error message will be immediately
preceded by the command that caused it.
.TP
.B \(mif
.I \*(Ed
will automatically prompt for text lines
upon being invoked.
Upon exit,
.I \*(ed
will automatically write the file.
This is useful for creating files without having to type the
.B a
command upon entry.
Note: If this flag is selected, the editor will over-write
an existing file by the same name.
See the
.B qi
command.
.TP
.B \(mih
Enable processing of a \*(oq\c
.I huge\c
\&\*(cq file, I.E. one with
up to 511 blocks, instead of the normal limit
of 255 blocks.
The use of
.B \(mih
disallows the
.B g
and
.B v
commands.
(This flag is inoperative and unnecessary on the Vax.)
.TP
.B \(mii
If an
.I interrupt
(ASCII
.BR DEL )
character is typed,
.I \*(ed
will write the current contents of the edit buffer on a file,
and exit.
The name of the dump file is that of the original file with a
.BI . int
extension.
The
.B \(mii
flag is very useful for shell files
which call the editor, since the editor will
not hang around after an interrupt,
interfering with the user's commands.
.TP
.B \(mik
Useful for slow terminals,
this flag
.I kills
verbose error messages.
Instead,
.I \*(ed
prints a query
.B ?
followed by an
.IR "error number" .
The actual error message may be obtained by typing the
.BI e nn
command (see below).
The long error messages may be turned on/off
via the
.B e+
and
.B e\(mi
commands (see below).
.TP
.BI \(mil c
The
.I eol
character is initialized to character
.IR c .
It may be changed during the edit session by the
.BI e= c
command.
.TP
.BI \(mim nn
The modification count before an automatic
save of the edit buffer is set to
.I nn
(decimal).
Default is \n(sa.
(That is, after every \n(sa commands which cause
a modification to one or more lines, the
edit buffer will be written on the edit
file name with
.BI . \*(ex
extension.)
If the count is zero, the auto-save feature is disabled.
.TP
.B \(min
The
.I no-line-numbers
flag is toggled.
This results in the omission of line number prompts
as well as line numbers on the
.B p
and
.B l
commands.
.TP
.B \(mio
The editor will not seek standard input to end-of-file
upon detecting a command error.
Normally, this results in a command file terminating immediately.
.TP
.B \(miO
If a
.I write
is attempted to a file that is write-locked,
but is owned by the user,
an attempt will be made to
.I override
the permission.
.TP
.B \(mip
Turn on prompts even if not talking to a terminal, mostly
useful for editing through pipes
(as when using
.IR protocol (1)
or
.IR script (1)).
.TP
.B \(miq
The editor will
.B NOT
ignore a
.I quit
(ASCII
.B FS
or ctrl-\c
.B \e\c
) signal.
Normally for editor debugging purposes, as a core dump
can then be made.
.br
.BR Beware ,
the edit buffer can not be recovered!
.TP
.B \(mir
.I Removes
the special meaning of the special characters:
.B $
.B &
.B \e(
.B \e)
.B [
.B .
.B *
.B ^
.B \e
.TP
.B \(mis
.I Silent
mode.
No prompts are issued,
printing of lines resulting from commands is suppressed
unless they are
.I explicitly
terminated with a
.BR p .
This mode is useful for running editor command files.
.TP
.BI \(mit c
Set the
.I tab
character to
.IR c .
This is the character which will be expanded
to the appropriate number of fill characters to get
to the next column which has a tab stop set in it.
The
.I tab
character may be set/changed using the
.BI t= c
command.
.TP
.BI \(miv c
Set the tab
.I fill
character to
.IR c .
This character is used to pad out the space between expanded
fields.
The tab
.I fill
character may be set/changed by the
.BI f= c
command.
.TP
.BI \(miw nn
Set the editor's idea of the page width to
.I nn
(decimal).
Default is 80 columns.
(See also the
.BI w= nn
command.)
.TP
.B \(miy
Set the interrupt processing to list out
one page
(see the
.B :
command)
upon receipt of an interrupt.
.TP
.B \(mi\*0123456789
A decimal number preceded by a
.B \(mi
will set a
.I tab
stop in that column.
Tab settings may be made during edit session by the
.BI t, nn
command.
.TP
.B \(mi,
A comma in the flag list is ignored to facilitate
setting multiple tab stops.
For example, tabs may be set by any of the forms
\*(oq\(mi9\ \(mi17\ \(mi25\*(cq, \*(oq\(mi9,17,25\*(cq, \*(oq\(mi9a17d25f\*(cq.
.PP
.I \*(Ed
operates on a copy of any file it is editing; changes made
in the copy have no effect on the file until a
.I w
(write)
command is given.
The copy of the text being edited resides
in a temporary file called the buffer.
There is only one buffer.
.PP
Commands to
.I \*(ed
have a simple and regular structure:
zero or more addresses followed by a one or more character
command, 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.
.PP
In general, only one command may appear on a line.
(See the
.BI e= c
command and the
.B \(mil
flag.)
Certain commands allow the input of text.
This text is placed in the appropriate place in the buffer.
While
.I \*(ed
is accepting text, it is said to be in
.IR "input mode" .
In this mode, no commands are recognized;
all input is merely collected.
Input mode is left by typing a period
.B .
alone at the
beginning of a line, or by receipt of an end-of-file
(Ctrl-D)
from the keyboard.
.PP
.I \*(Ed
supports a limited form of
.I "regular expression"
notation.
A regular expression specifies
a set of strings of characters.
A member of this set of strings is said to be
.I matched
by the regular expression.
The regular expressions allowed by
.I \*(ed
are constructed as follows:
In the following specification for regular expressions
the word
.I character
means any character but newline.
.IP 1.
Any character except a
.I special
character
matches itself.
Special characters are
the regular expression delimiter plus
.B "\e [ ."
and sometimes
.BR "^ * $" .
.IP 2.
A
.B .
matches any character.
.IP 3.
A
.B \e
followed by any character except a
.I digit
or
.B "( )"
matches that character.
.IP 4.
A nonempty string
.I s
bracketed
.B [\c
.I s\c
.B ]
(or
.B [^\c
.I s\c
.BR ] )
matches any character in (or not in)
.IR s .
In 
.IR s ,
.B \e
has no special meaning, and
.B ]
may only appear as
the first letter.
A substring 
.I a\c
\(mi\c
.IR b ,
with
.I a
and
.I b
in ascending ASCII order, stands for the inclusive
range of ASCII characters.
.IP 5.
A regular expression of form 1-4 followed by
.B *
matches a sequence of
.I zero
or more matches of the regular expression.
.IP 6.
A regular expression,
.IR x ,
of form 1-8, bracketed
.B \e(\c
.I x\c
.B \e)
matches what
.I x
matches, with side-effects described under the
.B s
command below.
.IP 7.
A
.B \e
followed by a digit 
.I n
matches a copy of the string that the
bracketed regular expression beginning with the
.IR n th
.B \e(
matched.
.IP 8.
A regular expression of form 1-8,
.IR x ,
followed by a regular expression of form 1-7,
.I y
matches a match for
.I x
followed by a match for
.IR y ,
with the
.I x
match being as long as possible while still permitting a
.I y
match.
.IP 9.
A regular expression of form 1-8 preceded by
.B ^
(or followed by
.BR $ ),
is constrained to matches that
begin at the left (or end at the right) end of a line.
.IP 10.
A regular expression of form 1-9 picks out the
longest among the leftmost matches in a line.
.IP 11.
An empty regular expression stands for a copy of the
last regular expression encountered.
.PP
Regular expressions are used in addresses to specify
lines and in one command
(see
.B s
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
.BR \e .
This also applies to the character bounding the regular
expression
(often
.BR / )
and to
.B \e
itself.
.PP
To understand addressing in
.I \*(ed
it is necessary to know that at any time there is a
.IR "current line" .
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 constructed as follows.
.IP 1.
The character
.B .
addresses the current line.
.IP 2.
The character
.B $
addresses the last line of the buffer.
.IP 3.
A decimal number
.I n
addresses the
.IR n -th
line of the buffer.
.IP 4.
.BI \(aa x
addresses the line (or lines) marked with the
mark name character
.IR x ,
which must be a lower-case letter.
An alternative to this syntax is the capital
letter alone.
Lines are marked with the
.B k
command described below.
.IP 5.
.B \(aa\c
.IB x ^
(or
.IB X ^\c
) addresses the first (lower)
line of the range marked
with the mark name character
.IR x .
(See the
.I k
command description.)
.IP 6.
.B \(aa\c
.IB x $
(or
.IB X $\c
) addresses the last (upper)
line of the range marked
with the mark name character
.IR x .
(See the
.B k
command description.)
.IP 7.
A regular expression enclosed in slashes
.B /
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.
.IP 8.
A regular expression enclosed in queries
.B ?
addresses
the first line found by searching toward the beginning of
the buffer and stopping at the first line containing
a string matching the regular expression.
If necessary the search wraps around to the end of the buffer.
.IP 9.
An address followed by a plus sign
.B +
or a minus sign
.B \(mi
followed by a decimal number
specifies that address plus
(resp. minus)
the indicated number of lines.
The plus sign may be omitted.
.IP 10.
If an address begins with
.B +
or
.B \(mi
the addition or subtraction is taken with respect to the current line;
e\.g\.
.B \(mi5
is understood to mean
.BR .\(mi5 .
(If the first address is omitted, but a second
bound is specified, then the first address will be the current line
plus one.
e.g. \*(oq\c
.B ,+10\c
\&\*(cq is equivalent to \*(oq\c
.B .+1,.+10\c
\&\*(cq.)
.IP 11.
If an address ends with
.B +
or
.BR \(mi ,
then 1 is added (resp. subtracted).
As a consequence of this rule and rule 10,
the address
.B \(mi
refers to the line before the current line.
Moreover, trailing
.B +
and
.B \(mi
characters have cumulative effect, so
.B \(mi\(mi
refers to the current
line less 2.
(There are complications of this rule,
see the
.B b
command below.)
.IP 12.
To maintain compatibility with earlier versions of the editor,
the character
.B ^
in addresses is entirely equivalent to
.BR \(mi .
.IP 13.
The character
.B =
specifies that the address bounds of the
previous command are to be used for the current command.
.IP 14.
The character pair
.B =^
addresses the lower bound
(first address) specified in the previous command.
.IP 15.
The character pair
.B =$
addresses the upper bound
(second address) specified in the previous command.
.IP 16.
The character pair
.B ..
addresses the
last value of
.B .
different from the current value of
.BR . \\|.
.PP
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.
.PP
Addresses are separated from each other typically by a comma
.BR , \\|.
They may also be separated by a semicolon
.BR ; \\|.
In this case the current line
.B .
is set to
the first address before the next address is interpreted.
The second address of any two-address sequence
must correspond to a line following
the line corresponding to the first address.
.PP
In the following list of
.I \*(ed
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.
.PP
As mentioned, it is generally illegal for more than one
command to appear on a line. However, most commands may be suffixed by
.BR p ,
.BR b ,
.B q
or
.BR l ,
in which case the current line is either
printed (as in the
.B p
command), listed with balanced pairs of parentheses, square brackets,
and brace brackets numbered (\c
.BR b ),
quoted (by
.B
"
or
.BR \(aa )
string lengths (\c
.BR q ),
or listed as in the
.B l
command.
.de PI
.br
.ne 5
.IP
.ti -.5i
..
.PI
(
.B .
)\c
.B a
.ti -.5i
.I text
.ti -.5i
.B .
.br
The
.I append
command reads the given text
and appends it after the addressed line.
.B .
is left on the last line input, if there
were any, otherwise at the addressed line.
Address \*(oq\c
.B \*0\c
\&\*(cq is legal for this command;
text is placed at the beginning of the buffer.
.PI
(
.B .
)\c
.B a
.I text
.br
If a space immediately follows the
.I append
command,
then the
.I text
immediately following the space is appended after
the addressed line.
.B .
is left at the newly created line.
This is essentially a quick method for entering one line.
.PI
(
.B .
,
.B .
)\c
.BI a/ text\c
.B /
.br
Append the text after the last character in the addressed lines.
.PI
.BI b nn
.br
The
.I browse
count is set to
.I nn
(decimal).
This count is then used for subsequent
.I "new-line"
commands as the number of lines to be printed out.
If
.I nn
is missing, the count is reset to 1.
.sp 1
In constructing addresses as described in rule 11 above,
the browse count is added to or subtracted from
the current address,
instead of a constant of 1 for each
.B +
or
.BR \(mi .
Normally this has no effect since the default is 1.
.PI
(
.B .
,
.B .
)\c
.B c
.ti -.5i
.I text
.ti -.5i
.B .
.br
The
.I change
command deletes the addressed lines, then accepts input
text which replaces these lines.
.B .
is left at the last line input; if there were none,
it is left at the first line not deleted.
.PI
(
.B .
,
.B .
)\c
.BI c/ "regular expression\c"
.BI / replacement\c
.B /
.ti -.5i
(
.B .
,
.B .
)\c
.BI c/ "regular expression\c"
.BI / replacement\c
.BI / nn
.ti -.5i
(
.B .
,
.B .
)\c
.BI c/ "regular expression\c"
.BI / replacement\c
.B /g
.br
This form of the change command is identical to the
.B s
command below.
.PI
(
.B .
,
.B .
)\c
.BI co a
.br
The
.B co
(copy) command is identical to the
.B t
(transfer)
command below.
.PI
(
.B .
,
.B .
)\c
.B d
.br
The
.I 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.
.PI
.B d
.I pathname
.br
The current directory is set to
.I pathname
by a call to
.IR chdir (2).
.PI
.BI d= nn
.br
Sets
.IR \*(ed 's
idea of what the
.I depth
of the screen is, to
.I nn
(decimal)
lines.
This is used in calculating how many lines will
fit on the screen with the
.B :
command, and may be preset with the
.B \(mic
flag
(see above).
.PI
.B e
.I filename
.ti -.5i
.B ei
.I filename
.br
The
.I edit
command causes the entire contents of the buffer to be deleted,
and then the named file to be read in.
If no
.I filename
is given, the
.I current
file is used.
.B .
is set to the last line of the buffer.
The number of lines read is printed.
.I filename
(if present) is remembered for
possible use as a default file name in a subsequent
.BR e ,
.BR r ,
or
.B w
command.
If the
.B i
is present,
.I \*(ed
will read
.I filename
immediately
(without double-checking first).
.PI
.BI e= c
.br
The
.I end-of-line
character is set to
.IR c .
Thereafter,
any occurrences of
.I c
are treated as if they were an actual newline character.
This facilitates entering several commands on the same
physical line.
.BR Caution :
the
.I eol
character is also interpreted in
.I insert
mode.
.PI
.BI e nn
.br
Displays the
.I long
error message for error number
.IR nn .
.PI
.B e+
.ti -.5i
.B e\(mi
.br
If a
.B \(mi
follows,
issue error messages in the form
.BI ? nn
where
.I nn
is the error number of the error that occurred.
This is mostly useful for slow terminals.
A
.B +
returns to long error messages.
(See the
.B \(mik
flag,
and the
.BI e nn
command above.)
.PI
(
.B .
,
.B .
)\c
.B exp
.br
Providing that a
.I "tab character"
has been set
(see the
.BI t= c
command and the
.B \(mit
flag)
as well as
.I "tab stops"
being set
(see the
.BI t, nn
command),
any instances of the
.I "tab character"
within the addressed lines which are to the left
of a column which is marked as a
.IR "tab stop" ,
will be expanded with an appropriate
number of
.IR "fill characters" .
(See the
.BI f= c
command).
.PI
.B f
.I filename
.br
The
.I filename
command prints the currently remembered file name.
If
.I filename
is given,
the currently remembered file name is changed to
.IB filename .
.PI
.BI f= c
.br
Set the
.I fill
character to
.IR c .
This is the character used to fill out a line where
.I tab
characters have been expanded.
If
.I c
is missing,
the
.I fill
character is reset to the default,
which uses as many tabs as possible,
followed by as many blanks as necessary to reach
the desired column, resulting in the fewest possible
characters to get to the desired position.
.PI
(
.B 1
,
.B $
)\c
.BI g/ "regular expression\c"
.BI / command-list
.ti -.5i
(
.B 1
,
.B $
)\c
.BI g/ "regular expression\c"
.BI /v command-list
.br
In the
.I global
command, the first step is to mark every line which matches
the given
.IR "regular expression" .
If the optional
.B v
is present after the regular expression,
each line potentially matching the regular expression will
be printed, followed by the message \*(oq\c
.B "Ok?\\ \c"
\&\*(cq.
If the response begins with
.IR n ,
the line will not
be marked, any other response will cause the line to
be marked.
Then for every marked line, the
given command list is executed with
.B .
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
.B \e\c
\&.
The
.BR a ,
.BR i ,
and
.B c
commands and associated input are permitted;
the
.B .
terminating input mode may be omitted if it would be on the
last line of the command list.
The (global) commands,
.BR g ,
and
.BR v ,
are not permitted in the command list.
If an
.I end-of-file
(Ctrl-D)
is typed in response to the prompt,
no further lines will be scanned or marked,
and all lines marked so far (if any) will have
.I command-list
applied to them.
.PI
.B h
.ti -.5i
.BI h nn
.br
Column numbers to column
.I nn
(default 71)
are printed out.
Any columns which have
.I tab
stops set will print out with
.B \(mi
character in the appropriate position.
.PI
.BR he [lp]
.br
List syntax of all
.I \*(ed
commands available.
(Merely displays the contents of the file
.B /etc/\*(ed.doc\c
\&.)
.PI
(
.B .
)\c
.B i
.ti -.5i
.I text
.ti -.5i
.B .
.br
This command inserts the given text before the addressed line.
.B .
is left at the last line input;
if there were none,
at the addressed line.
This command differs from the
.B a
command only in the placement of the text.
.PI
(
.B .
)\c
.B i
.I text
.br
This form of the
.I insert
command inserts one line before the addressed line,
consisting of the
.I text
following the space.
(See the
.B a
command.)
.PI
(
.B .
,
.B .
)\c
.BI i/ text\c
.B /
.br
Insert the text before the first character in the addressed lines.
.PI
(
.B .\(mi1
,
.B .
)\c
.B j
.ti -.5i
(
.B .\(mi1
,
.B .
)\c
.BI j/ text\c
.B /
.br
Join the addressed lines together to form one resulting line.
This effectively removes the new-line from the
ends of all but the last line.
(Useful for rejoining lines that
were split incorrectly by the
.I s
command.)
.sp 1
If a delimiter
(and perhaps some
.IR text )
is present,
then the
.I text
will be inserted between the text of the joined lines.
.PI
.B k
.ti -.5i
(
.B .
,
.B .
)\c
.BI k x
.br
The mark command marks the addressed line(s) with name
.IR x ,
which must be a letter.
Either of the address forms
.BI \(aa x
or
.I X
(capital letter)
then address this/these line(s).
If no character is specified after the command,
all currently marked lines are listed.
.PI
(
.B .
,
.B .
)\c
.B l
.br
The
.I list
command prints the addressed lines in an unambiguous way:
non-graphic characters are printed as
.IR ^X ,
and long lines are folded.
.I Tab
characters show as
\o'->'
and
.I backspace
characters are displayed as
\o'-<'.
An
.B l
command may follow most others on the same line.
.PI
(
.B .+1
,
.BI .+ nn
)\c
.B la
.br
One
.I page
of text is listed as in the
.B l
command above.
The text is guaranteed not to scroll off the screen.
.PI
(
.B 1
,
.B $
)\c
.B ll
.br
The entire contents of the edit buffer are listed as if \*(oq\c
.B 1,$l\c
\&\*(cq had been typed.
.PI
.B m
.br
The characters
.B ^
.B $
.B .
.B *
.B [
.B &
.B \e(
.B \e)
and
.B \e
lose or regain their
special meaning in patterns as well as in the substitute command.
Each invocation of
.B m
toggles the \*(oq\c
.I magic\c
\&\*(cq characters on/off.
.PI
(
.B .
,
.B .
)\c
.BI m a
.ti -.5i
(
.B .
,
.B .
)\c
.BI mo a
.br
The
.I move
command repositions the addressed
lines after the line addressed by
.IR a .
The last of the moved lines becomes the current line.
.PI
.B n
.br
Line numbering is toggled on or off.
.PI
.B n+
.ti -.5i
.B n\(mi
.br
Line numbering for the
.B |
(and other variants)
command is turned on for a
.BR + ,
off for a
.BR \(mi .
.PI
(
.B .
,
.B .
)\c
.B p
.br
The
.I print
command prints the addressed lines.
.B .
is left at the last line printed.
The
.B p
command may be placed on the same line after most commands.
.PI
(
.B .+1
,
.BI .+ nn
)\c
.B pa
.br
One
.I page
of text is printed out.
The text is guaranteed not to scroll off the screen.
(See the
.B :
command below.)
.PI
(
.B 1
,
.B $
)\c
.B pp
.br
The entire contents of the edit buffer are listed as if \*(oq\c
.B 1,$p\c
\&\*(cq had been typed.
.PI
.B q
.ti -.5i
.B qi
.br
The
.I quit
command causes
.I \*(ed
to exit.
No automatic write of a file is done.
If the edit file has been modified and the entire contents
of the buffer have not been written to a file,
a query will be issued to insure that the user
has not forgotten to write his file.
If the
.B i
is present, the editor will quit immediately
(without double-checking first).
Moreover,
if the
.B \(mif
flag was selected,
the file will
.I not
be (over)written.
.PI
(
.B $
)\c
.B r
.I filename
.br
The
.I 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
.I e
and
.I f
commands).
The remembered file name is not changed unless
.I filename
is the very first file name mentioned.
Address \*(oq\c
.B \*0\c
\&\*(cq is legal for
.I r
and causes the file to be read at the beginning of the buffer.
If the read is successful, the number of lines read is typed.
.B .
is left at the last line read from the file.
.PI
.B s
.br
The
.I stop
command without any parameters performs an automatic write
(\c
.BR w )
if the file has been modified and then exits the editor.
.PI
(
.B .
,
.B .
)\c
.BI s/ "regular expression\c"
.BI / replacement\c
.B /
.ti -.5i
(
.B .
,
.B .
)\c
.BI s/ "regular expression\c"
.BI / replacement\c
.BI / nn
.ti -.5i
(
.B .
,
.B .
)\c
.BI s/ "regular expression\c"
.BI / replacement\c
.B /g
.br
The
.I substitute
command searches each addressed
line for an occurrence of the specified regular expression.
On each line in which a match is found,
one of the folowing actions are taken for each of the three
forms of the command:
.IP 1. +.5i
The first occurrence of the specified expression
is replaced by the replacement text.
.IP 2. +0i
The
.IR nn -th
(where
.I nn
is a decimal number)
occurrence of the specified expression
is replaced by the replacement text.
.IP 3. +0i
All occurrences of the specified expression
are replaced.
.in -.5i
.sp 1
It is an error for the substitution to fail on all addressed lines.
Any character other than
.I newline
may be used instead of
.B /
to delimit the regular expression
and the replacement.
.B .
is left at the last line substituted.
.sp 1
An ampersand
.B &
appearing in the replacement
is replaced by the string matching the regular expression.
As a more general feature, the characters
.B \e\c
.I n\c
,
where
.I n
is a digit,
are replaced by the text matched by the
.IR n -th
regular subexpression enclosed between
.B \e(
and
.B \e)\c
\&.
When nested, parenthesized subexpressions are present,
.I n
is determined by counting occurrences of
.B \e(
starting from the left.
.sp 1
Lines may be split by substituting
.I newline
characters into them.
The newline in the
.I replacement
must be escaped by preceding it with a
.B \e\c
\&.
.TP -.5i
.ti -.5i
.BI sa nn
.br
The
.I save-count
command changes the default
(\n(sa) count of text-changing
commands which may be executed before
an automatic buffer save will be done.
(\c
.I nn
is a decimal number.)
The save file name is the current filename with a
.BI . \*(ex
extension.
A count of zero (\*0) will disable the auto-save feature.
.PI
.B t
.br
All tab stops currently in effect, as set by the
.BI t, nn
command,
are listed.
.PI
(
.B .
,
.B .
)\c
.BI t a
.br
A copy of the addressed lines is
.I transferred
after address
.I a
(which may be \*0).
.B .
is left at the last line of the copy.
.PI
.BI t= c
.br
Set
.I tab
character to
.IR c .
All occurrences of this character entered by the
.B a
or
.B i
commands will be expanded to the appropriate number of
.I fill
characters to get to the next column with a
.IR "tab stop" .
Any occurrences of the
.I tab
character after the last tab column will be untouched.
.PI
.BI t, nn\c
.RI , nn\c
,...
.br
Set
.I "tab stops"
in specified (decimal) columns.
Numbers preceded by a
.B \(mi
will clear the tab
setting at that position.
The number zero clears
.I all
tab settings.
.PI
.B u
.br
The
.I undo
command will restore the last modified line
to its original condition.
This is different from the
.B x
(\c
.IR undelete )
command, which recovers blocks of
.I deleted
lines, whereas
.B u
will restore only
.I one
line, when modified by a
.I substitution
or
.I tab
expansion.
.I Undo
will
.I not
recover from a
.I join
command, nor
from any deletion, which is processed by the
.I undelete
command.
.PI
(
.B 1
,
.B $
)\c
.BI v/ "regular expression\c"
.BI / command-list
.ti -.5i
(
.B 1
,
.B $
)\c
.BI v/ "regular expression\c"
.BI /v command-list
.br
This command is the same as the
.I global
command except that the command list is executed
with
.B .
initially set to every line
.B except
those matching the regular expression.
.PI
(
.B 1
,
.B $
)\c
.B w
.I filename
.ti -.5i
(
.B 1
,
.B $
)\c
.BI w> filename
.ti -.5i
(
.B 1
,
.B $
)\c
.B wi
.I filename
.br
The
.I write
command writes the addressed lines onto
the given file.
If the file does not exist,
it is created
(see
.IR umask (2)).
The remembered file name is not changed unless
.I filename
is the very first file name mentioned.
If no file name is given,
the remembered file name, if any, is used
(see
.B e
and
.B f
commands).
.B .
is unchanged.
If the
.B >
is present, the addressed lines
will be appended onto the end of the file.
If the
.B wi
form is used,
and the file is write-locked,
then
.I \*(ed
will attempt to over-ride the file permission, if possible.
.PI
.BI w= nn
.br
Sets
.IR \*(ed 's
idea of how wide the screen is to
.I nn
columns.
This is used in calculating how many lines will
fit on the screen with a
.B :
command, and may be preset with the
.B \(miw
flag
(see above).
.PI
(
.B .
)\c
.B x
.br
.I Undelete
is used to recover the most recently deleted
(or replaced)
block of lines.
.B .
is left at the last recovered line.
.IP
.nf
Example:
	25,34d		delete the lines
	*		see the damage
	24x		recovers the lost lines
.fi
.PI
(
.B .
)\c
.B y+
.ti -.5i
.B y
.ti -.5i
.B y\(mi
.br
This command changes the processing of an interrupt
received from the terminal.
If the
.B \(mi
is present, normal processing takes place.
That is, the message
\*(oqINTERRUPT!\*(cq
will be displayed on the terminal and
.I \*(ed
will prompt for another command.
If the
.B +
is present, the addressed line is set as
the initial address for the
.B :
command, which will automatically be
invoked upon each interrupt.
Lastly, if no character follows,
then upon each interrupt, one
.I page
will be displayed from
.B .
onward, which is useful for paging through
sections of text.
.PI
.B @
.I filename
.ti -.5i
.B @p
.I filename
.br
.I \*(Ed
opens the specified file,
and reads command lines from it.
The commands are echoed to the terminal
(if the
.B p
is present)
as each character is processed.
This allows monitoring the command file as
it is running, so that erroneous command line(s)
will appear before their respective
error messages.
If no filename is given,
the last
.IR indirect ed
filename,
if any,
will be used.
.PI
.BI ! UNIX-command
.br
The remainder of the line after the
.B !
is sent to the
.I shell
(see
.BR SH (1))
to be interpreted as a
.I UNIX
command.
.B .
is unchanged.
.PI
(
.B .
)\c
.BI | UNIX-command
.br
The addressed lines are
.I piped
as the standard input
to the command(s) following the
.B |
symbol.
The
.I UNIX
command is passed to the
.I shell
(as in
.B !
above)
to be processed.
Line numbers will not precede the lines of text sent to
the command(s) unless explicitly enabled via the
.B n+
command (see above).
.PI
.B |+
.ti -.5i
.B |\(mi
.br
Turn on (or off, respectively) strict checking of the exit status of
.I UNIX
commands executed via the
.B |\\||
command.
If checking is enabled, no processing will be done on the text
returned by a command which has a non-zero exit status
(thereby implying an error occurred).
This reduces the chance of erroneous command processing
causing loss of lines.
Lines deleted by the
.B |\\||
command may be recovered with
.B x
(undelete).
.PI
(
.B .
)\c
.BI |\\|| UNIX-command
.br
This variant of the
.I pipe
command
(commonly referred to as the \*(oq\c
.I double-pipe\c
\&\*(cq command)
performs similarly to the
.B |
command above, but replaces the lines sent to the command(s)
with those received from the command(s) on the standard output
of the command(s).
If the error status from the command(s) is not that of a
.IR "normal exit" ,
no change will be made in the text.
Similarly,
(by default)
if the exit status of the command(s) is non-zero
(possibly indicating an error)
no changes will be made.
This is due to the existence of many older programs which
do not terminate with a meaningful exit status.
The strict exit status checking may be disabled via the
.B |\(mi
command below.
An optional
.I "line number"
(\c
.B not
address)
may immediately follow the
.B |\\||
which will specify the line after which the returned
lines are to be placed.
.PI
.BI |< UNIX-command
.br
Lines generated by the
.I UNIX
command(s) are inserted after
.BR . .
An optional
.I "line number"
(\c
.B not
address)
may immediately follow the
.B <
which will specify the line after which the returned
lines are to be placed.
.PI
(
.B .
)\c
.BI |> UNIX-command
.br
The only difference between this command and the
.B |\\||
command above is this variant
.I inserts
the generated text
.I after
the lines sent, instead of
.I replacing
the original lines.
An optional
.I "line number"
(\c
.B not
address)
may immediately follow the
.B >
which will specify the line after which the returned
lines are to be placed.
.PI
(
.B .+1
,
.BI .+ nn
)\c
.B :
.ti -.5i
(
.BI .- nn
,
.B .
)\c
.B :-
.ti -.5i
(
.BI .- nn
,
.BI .+ nn
)\c
.B *
.br
One
.I page
of text is printed out.
The text is guaranteed not to scroll off the screen.
The first form (just the
.B :
alone) will start at the addressed line,
the line following
.B .
is the default,
and print one screenful, or
.I page
of text.
.B .
is set to the last line displayed.
The second form,
.BR :- ,
displays one screenful, leaving
.B .
as the last line displayed, and remaining as the current line.
The last form,
.BR * ,
displays one screenful, with
.B .
centered in the
.IR page .
.PI
(
.B .+1
,
.BI .+ nn
)\c
.I (newline)
.br
An address alone on a line causes the addressed line to be printed.
A blank line alone is equivalent to \*(oq\c
.BI .+1,.+ nn\c
.B p\c
\&\*(cq;
it is useful for stepping through text.
The
.I nn
is the count specified with the
.B b
command
(default 1).
.PP
If an interrupt signal (ASCII
.BR DEL )
is received,
.I \*(ed
prints
\*(oqINTERRUPT!\*(cq
and returns to its command level.
(See also the
.I y
command for alternate interrupt processing.)
.SH "Some size limitations"
.br
512 characters per line,
(see the
.B \(miB
flag above)
.br
256 characters per global command list,
.br
64 characters per file name,
.br
128K characters in the temporary file
(PDP-11 version only)
.br
(256K characters with
.B \(mih
flag)
.br
(No limit on the Vax version)
.br
The limit on the number of lines depends on the amount of core:
.ti +.5i
each line takes 1 word.
.br
(The current absolute maximum on the PDP-11's is 24,062 lines.)
.SH FILES
.TP
/tmp/e?????
temporary; ????? is process number (in decimal).
.TP
/tmp/ep?????
temporary for
.B |\\||
stuff.
.TP
*.hup
if
.I hangup
signal is received.
.TP
*.bak
if
.B \(mib
flag is specified.
.TP
*.int
if
.B \(mii
flag is specified and an
.I interrupt
is received.
.TP
*.\*(ex
auto-save (every \n(sa commands).
.TP
*.trm
if
.I termination
signal is received.
.TP
/etc/\*(ed.doc
for the
.BR he lp
command.
.SH DIAGNOSTICS
Each command has self-explanatory
error messages.
.SH "SEE ALSO"
ed(1), edit(1), eed(1), ex(1), umask(2), vi(1)
.br
A Tutorial Introduction to the
.B ED
Text Editor \(mi B. W. Kernighan
.SH BUGS
A
.B \e
followed by a
.IR newline ,
useful for splitting lines
with the substitute command, may not be passed through
the global command.

If line(s) are deleted which include the endpoints of
a range marked with the
.B k
command,
that mark-name character will
not work correctly.