123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814 |
- .ad l
- .TH ED 1
- .CT 1 editor
- .ds . (\|\f5.\fP\|)
- .ds .. (\|\f5.,.\fP\|)
- .ds 1$ (\|\f51,$\fP\|)
- .SH NAME
- ed, e \- text editor
- .SH SYNOPSIS
- .B ed
- [
- .B -
- ]
- [
- .B -o
- ]
- [
- .I file
- ]
- .SH DESCRIPTION
- .I Ed
- is the standard text editor;
- .I e
- is another name for it.
- .PP
- If a
- .I file
- argument is given,
- .I ed
- simulates an
- .B e
- command (see below) on that file:
- it is read into
- .I ed's
- buffer so that it can be edited.
- The options are
- .TP
- .B -
- Suppress the printing
- of character counts by
- .BR e ,
- .BR r ,
- and
- .B w
- commands and of the confirming
- .B !
- by
- .B !
- commands.
- .TP
- .B -o
- (for output piping)
- Place on the standard error file all output except writing by
- .B w
- commands.
- If no
- .I file
- is given, make
- .I /dev/stdout
- the remembered file; see the
- .B e
- command below.
- .I Ed
- starts in append mode (simulating an
- .B a
- command).
- .PP
- .I Ed
- operates on a `buffer', a copy of the file it is editing;
- changes made
- in the buffer have no effect on the file until a
- .B w
- (write)
- command is given.
- The copy of the text being edited resides
- in a temporary file called the
- .IR buffer .
- .PP
- Commands to
- .I ed
- have a simple and regular structure: zero or
- more
- .I addresses
- followed by a single character
- .I command,
- possibly
- followed by parameters to the command.
- These addresses specify one or more lines in the buffer.
- Missing addresses are supplied by default.
- .PP
- In general, only one command may appear on a line.
- Certain commands allow the
- addition of text to the buffer.
- While
- .I ed
- is accepting text, it is said
- to be in
- .I "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.
- .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.
- In the following specification for regular expressions
- the word `character' means any character but newline.
- .IP 1.
- Any character except a 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 digit,
- .BR ( ,
- or
- .B )
- matches that character.
- .IP 4.
- A nonempty string
- .I s
- bracketed
- .BI [ \|s\| ]
- (or
- .BI [^ s\| ])
- matches any character in (or not in)
- .I s.
- In
- .I s,
- .B \e
- has no special meaning, and
- .B ]
- may only appear as
- the first letter.
- A substring
- .IB a - b ,
- with
- .I a
- and
- .I b
- in ascending
- .SM Unicode
- order, stands for the inclusive
- range of
- .SM Unicode
- characters.
- .IP 5.
- A regular expression of form 1-4 followed by
- .B *
- matches a sequence of
- 0 or more matches of the regular expression.
- .IP 6.
- A regular expression,
- .I x,
- of form 1-8, bracketed
- .BI \e( \|x\| \e)
- matches what
- .I x
- matches.
- .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,
- .I x,
- followed by a regular expression of form 1-7,
- .I y
- matches a match for
- .I x
- followed by a match for
- .I 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, or a null string, preceded by
- .B ^
- (and/or followed by
- .BR $ ),
- is constrained to matches that
- begin at the left (and/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
- .I 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 `\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
- .I "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.
- .TP
- 1.
- The character
- .BR . ,
- customarily called `dot',
- addresses the current line.
- .TP
- 2.
- The character
- .B $
- addresses the last line of the buffer.
- .TP
- 3.
- A decimal number
- .I n
- addresses the
- .IR n -th
- line of the buffer.
- .TP
- 4.
- .BI \'x
- addresses the line marked with the name
- .IR x ,
- which must be a lower-case letter.
- Lines are marked with the
- .B k
- command described below.
- .TP
- 5.
- A regular expression enclosed in slashes
- .B /
- 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.
- .TP
- 6.
- A regular expression enclosed in queries
- .B ?
- 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.
- If necessary
- the search wraps around to the end of the buffer.
- .TP
- 7.
- An address followed by a plus sign
- .B +
- or a minus sign
- .B -
- followed by a decimal number specifies that address plus
- (resp. minus) the indicated number of lines.
- The plus sign may be omitted.
- .TP
- 8.
- An address followed by
- .B +
- (or
- .BR - )
- followed by a
- regular expression enclosed in slashes specifies the first
- matching line following (or preceding) that address.
- The search wraps around if necessary.
- The
- .B +
- may be omitted, so
- .B 0/x/
- addresses the
- .I first
- line in the buffer with an
- .BR x .
- Enclosing the regular expression in
- .B ?
- reverses the search direction.
- .TP
- 9.
- If an address begins with
- .B +
- or
- .B -
- the addition or subtraction is taken with respect to the current line;
- e.g.\&
- .B -5
- is understood to mean
- .BR .-5 .
- .TP
- 10.
- If an address ends with
- .B +
- or
- .BR - ,
- then 1 is added (resp. subtracted).
- As a consequence of this rule and rule 9,
- the address
- .B -
- refers to the line before the current line.
- Moreover,
- trailing
- .B +
- and
- .B -
- characters
- have cumulative effect, so
- .B --
- refers to the current
- line less 2.
- .TP
- 11.
- To maintain compatibility with earlier versions of the editor,
- the character
- .B ^
- in addresses is
- equivalent to
- .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
- is set to
- the previous address before the next address is interpreted.
- If no address precedes a comma or semicolon, line 1 is assumed;
- if no address follows, the last line of the buffer is assumed.
- 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.
- `Dot' means the current line.
- .TP
- .RB \*. \|a
- .br
- .ns
- .TP
- <text>
- .br
- .ns
- .TP
- .B .
- Read the given text
- and append it after the addressed line.
- Dot is left
- on the last line input, if there
- were any, otherwise at the addressed line.
- Address
- .B 0
- is legal for this command; text is placed
- at the beginning of the buffer.
- .TP
- .RB \*(.. \|b [ +- ][\fIpagesize\fP][ pln\fR]
- Browse.
- Print a `page', normally 20 lines.
- The optional
- .B +
- (default) or
- .B -
- specifies whether the next or previous
- page is to be printed.
- The optional
- .I pagesize
- is the number of lines in a page.
- The optional
- .BR p ,
- .BR n ,
- or
- .B l
- causes printing in the specified format, initially
- .BR p .
- Pagesize and format are remembered between
- .B b
- commands.
- Dot is left at the last line displayed.
- .TP
- .RB \*(.. \|c
- .br
- .ns
- .TP
- <text>
- .br
- .ns
- .TP
- .B .
- .br
- Change.
- Delete the addressed lines, then accept input
- text to replace these lines.
- Dot is left at the last line input; if there were none,
- it is left at the line preceding the deleted lines.
- .TP
- .RB \*(.. \|d
- Delete the addressed lines from the buffer.
- Dot is set to the line following the last line deleted, or to
- the last line of the buffer if the deleted lines had no successor.
- .TP
- .BI e " filename"
- Edit.
- Delete the entire contents of the buffer;
- then read the named file into the buffer.
- Dot is set to the last line of the buffer.
- The number of characters read is typed.
- The file name is remembered for possible use in later
- .BR e ,
- .BR r ,
- or
- .B w
- commands.
- If
- .I filename
- is missing, the remembered name is used.
- .TP
- .BI E " filename"
- Unconditional
- .BR e ;
- see `DIAGNOSTICS' below.
- .TP
- .BI f " filename"
- Print the currently remembered file name.
- If
- .I filename
- is given,
- the currently remembered file name is first changed to
- .I filename.
- .TP
- .RB \*(1$ \|g/\fIregular\ expression\fP/\fIcommand\ list\fP
- .PD 0
- .TP
- .RB \*(1$ \|g/\fIregular\ expression\fP/
- .TP
- .RB \*(1$ \|g/\fIregular\ expression\fP
- .PD
- Global.
- First mark every line which matches
- the given
- .I regular expression.
- Then for every such line, execute the
- .I command list
- with dot 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 end with
- .BR \e .
- The
- .RB \&` \&. \&'
- terminating input mode for an
- .BR a ,
- .BR i ,
- .B c
- command may be omitted if it would be on the
- last line of the command list.
- The commands
- .B g
- and
- .B v
- are not permitted in the command list.
- Any character other than space or newline may
- be used instead of
- .B /
- to delimit the regular expression.
- The second and third forms mean
- .BI g/ regular\ expression /p .
- .TP
- .RB (\| .\| ) \|i
- .PD 0
- .TP
- <text>
- .TP
- .B .
- Insert the given text before the addressed line.
- Dot is left at the last line input, or, if there were none,
- at the line before the addressed line.
- This command differs from the
- .I a
- command only in the placement of the
- text.
- .PD
- .TP
- .RB (\| .,.+1 \|) \|j
- Join the addressed lines into a single line;
- intermediate newlines are deleted.
- Dot is left at the resulting line.
- .TP
- .RB \*. \|k\fIx\fP
- Mark the addressed line with name
- .I x,
- which must be a lower-case letter.
- The address form
- .BI \' x
- then addresses this line.
- .ne 2.5
- .TP
- .RB \*(.. \|l
- List.
- Print the addressed lines in an unambiguous way:
- a tab is printed as
- .BR \et ,
- a backspace as
- .BR \eb ,
- backslashes as
- .BR \e\e ,
- and printable ASCII characters are printed as themselves.
- All other (Uncicode) characters are printed as a
- backslash and three octal digits for each byte of their UTF-8
- representation.
- Long lines are folded,
- with the second and subsequent sub-lines indented one tab stop.
- If the last character in the line is a blank,
- it is followed by
- .BR \en .
- An
- .B l
- may be appended, like
- .BR p ,
- to any non-I/O command.
- .TP
- .RB \*(.. \|m\fIa
- Move.
- Reposition the addressed lines after the line
- addressed by
- .IR a .
- Dot is left at the last moved line.
- .TP
- .RB \*(.. \|n
- Number.
- Perform
- .BR p ,
- prefixing each line with its line number and a tab.
- An
- .B n
- may be appended, like
- .BR p ,
- to any non-I/O command.
- .TP
- .RB \*(.. \|p
- Print the addressed lines.
- Dot is left at the last line printed.
- A
- .B p
- appended to any non-I/O command causes the then current line
- to be printed after the command is executed.
- .TP
- .RB \*(.. \|P
- This command is a synonym for
- .BR p .
- .TP
- .B q
- Quit the editor.
- No automatic write
- of a file is done.
- .TP
- .B Q
- Quit unconditionally; see `DIAGNOSTICS' below.
- .TP
- .RB ( $ )\|r\ \fIfilename\fP
- Read in the given file after the addressed line.
- If no
- .I filename
- is given, the remembered file name is used.
- The file name is remembered if there were no
- remembered file name already.
- If the read is successful, the number of characters
- read is typed.
- Dot is left at the last line read in from the file.
- .TP
- .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/
- .PD 0
- .TP
- .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g
- .TP
- .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP
- .PD
- Substitute.
- Search each addressed
- line for an occurrence of the specified regular expression.
- On each line in which
- .I n
- matches are found
- .RI ( n
- defaults to 1 if missing),
- the
- .IR n th
- matched string is replaced by the replacement specified.
- If the global replacement indicator
- .B g
- appears after the command,
- all subsequent matches on the line are also replaced.
- It is an error for the substitution to fail on all addressed lines.
- Any character other than space or newline
- may be used instead of
- .B /
- to delimit the regular expression
- and the replacement.
- Dot is left at the last line substituted.
- The third form means
- .BI s n / regular\ expression / replacement\fP/p\fR.
- The second
- .B /
- may be omitted if the replacement is
- empty.
- .IP
- An ampersand
- .B &
- appearing in the replacement
- is replaced by the string matching the regular expression.
- The characters
- .BI \e n,
- where
- .I n
- is a digit,
- are replaced by the text matched by the
- .IR n -th
- regular subexpression
- enclosed between
- .B \e(
- and
- .BR \e) .
- When
- nested, parenthesized subexpressions
- are present,
- .I n
- is determined by counting occurrences of
- .BR \e (
- starting from the left.
- .IP
- A literal
- .BR & ,
- .BR / ,
- .B \e
- or newline may be included in a replacement
- by prefixing it with
- .BR \e .
- .TP
- .RB \*(.. \|t\|\fIa
- Transfer.
- Copy the addressed lines
- after the line addressed by
- .I a.
- Dot is left at the last line of the copy.
- .TP
- .RB \*(.. \|u
- Undo.
- Restore the preceding contents
- of the current line, which must be the last line
- in which a substitution was made.
- .TP
- .RB \*(1$ \|v/\fIregular\ expression\fP/\fIcommand\ list\fP
- .PD 0
- .TP
- .RB \*(1$ \|v/\fIregular\ expression\fP/
- .TP
- .RB \*(1$ \|v/\fIregular\ expression\fP
- .PD
- This command is the same as the global command
- .B g
- except that the command list is executed with
- dot initially set to every line
- .I except
- those
- matching the regular expression.
- .TP
- .RB \*(1$ \|w " \fIfilename\fP"
- Write the addressed lines onto
- the given file.
- If the file does not exist,
- it is created with mode 666 (readable and writable by everyone).
- If no
- .I filename
- is given, the remembered file name, if any, is used.
- The file name is remembered if there were no
- remembered file name already.
- Dot is unchanged.
- If the write is successful, the number of characters written is
- printed.
- .TP
- .RB \*(1$ \|W " \fIfilename\fP"
- Perform
- .BR w ,
- but append to, instead of overwriting, any existing file contents.
- .TP
- .RB ( $ ) \|=
- Print the line number of the addressed line.
- Dot is unchanged.
- .TP
- .BI ! shell\ command
- Send the remainder of the line after the
- .B !
- to
- .IR sh (1)
- to be interpreted as a command.
- Dot is unchanged.
- .TP
- .RB (\| .+1 )\|<newline>
- An address without a command is taken as a
- .B p
- command.
- A terminal
- .B /
- may be omitted from the address.
- A blank line alone is equivalent to
- .BR .+1p ;
- it is useful
- for stepping through text.
- .PP
- If an interrupt signal
- .SM (ASCII DEL)
- is sent,
- .I ed
- prints a
- .B ?
- and returns to its command level.
- .PP
- When reading a file,
- .I ed
- discards
- .SM ASCII NUL
- characters. If there are any characters
- after the last newline,
- .I ed
- supplies a final newline and prints the
- message
- .I ?N appended
- on the terminal.
- It refuses to read files not conforming to the
- .SM UTF-8
- standard.
- .SH FILES
- .B /tmp/e*
- .br
- .B ed.hup
- \ \ work is saved here if terminal hangs up
- .SH "SEE ALSO"
- .IR qed (1),
- .IR sed (1),
- .IR vi (1)
- .SH DIAGNOSTICS
- .BI ? name
- for inaccessible file;
- .B ?TMP
- for temporary file overflow;
- .B ?N appended
- when a final newline has been appended;
- .B ?
- for errors in commands or other overflows.
- .PP
- To protect against throwing away valuable work,
- a
- .B q
- or
- .B e
- command is considered to be in error if the buffer has
- been modified since the last
- .BR w ,
- .BR q ,
- or
- .B e
- command.
|