libg++.a and libiberty.a should be installed 444, not 555.
[unix-history] / usr / src / contrib / ed / ed.1
CommitLineData
445c7738
KB
1.\" Copyright (c) 1992 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Rodney Ruddock of the University of Guelph.
6.\"
7.\" %sccs.include.redist.roff%
8.\"
05ee7127 9.\" @(#)ed.1 5.9 (Berkeley) %G%
445c7738
KB
10.\"
11.TH ED 1 ""
12.SH NAME
13ed \- line oriented text editor
14.SH SYNOPSIS
15.B ed
16[
17.B \-p
18.I prompt-string
19] [
20.B \-s
21] [
22.B \-v
23] [
24.I filename
25]
26.SH DESCRIPTION
27.I Ed
e692f66f 28is a standard text editor.
445c7738
KB
29.PP
30\fIEd\fR is a powerful line oriented editor. Although ex(1)/vi(1) have gained
31popularity, \fIed\fR still maintains advantages over them. Most notable points
32are the
33.I W
34command (see below) (which is not part of ex(1)/vi(1)\|), the
e692f66f
KB
35smaller executable size (you can often be editing before the others finish
36loading), and the better response when editing from slow terminals or across
445c7738
KB
37low baud data lines. \fIEd\fR continues to be used by many system utilities.
38.SH OPTIONS
39.PP
40When a filename is present \fIed\fR starts by simulating an
41.I e
42command (see below)
43If no filename is present \fIed\fR
44starts with an empty buffer.
45The option
46.B \-p
47allows for the setting of a prompt string in
48.IR ed .
49The option
50.B \-s
51suppresses the printing
52of explanatory output
53(from the commands
54.IR e ,
55.IR E ,
56.IR r ,
57.IR w ,
58.I W
59and
60.IR wq ;
61see below) and should be used with a script.
62The
63.B \-v
64option will display a message of which mode (BSD or POSIX)
65.I ed
66as been set locally. This is useful for determining the described
67behavior below.
68.PP
69.I Ed
70performs all changes to a copy of the file which is contained in a \fBbuffer\fR.
71For the changes to have an effect one of the write commands (
72.IR w ,
73.IR W ,
74.IR wq ,
75or
76.IR Wq )
77must be issued.
78.PP
79The contents of the
80.B buffer
81can changed by issuing commands that are lead
82by zero, one, or two addresses. All commands are alphabetically listed below
83with their parameter structures if applicable; trailing structures not
84described with commands are regarded as erroneous. Commands that
85accept zero addresses regard the presence of any address as an error.
86.PP
87.I Ed
88works in two modes: command, and input. The two modes are exclusive of
89each other. While in command mode
90.I ed
91accepts commands that display, modify, or give information about the
92.BR buffer .
93While in input mode
94.I ed
95accepts lines of text to be added to the
96.BR buffer .
97.PP
98Addressing in \fIed\fR specifies one or more lines contained in the
99.BR buffer .
100For commands that expect at least one address, and none are given, default
101addresses will be used.
102Using addresses in
103.I ed
104involves understanding that during the execution of most
105.I ed
106commands that a
107.I "current line"
108(
109.BR current )
110exists.
111.B Current
112(as a rule of thumb) is the location in the
113.B buffer
114that the last command issued affected; some
115commands do not affect
116.BR current .
117Each command description (below) describes
118its affects on
119.B current
120as the affect will vary depending under which compile option (BSD or POSIX)
121.I ed
122was compiled under.
123Addresses can be divided into three cases: one
124address (\fBsingle address\fR), two addresses (an \fBaddress pair\fR),
125and special address forms.
126
127For the first two cases
128an address is formed with the use of:
129.TP
1301.
131A positive decimal integer (e.g. 123) indicating a line number in the buffer.
132Line number 1 is the first line in the buffer.
133.TP
1342.
135The `.' character indicating the current line (\fBcurrent\fR).
136.TP
1373.
138The `$' character which indicates the last line in the buffer.
139.TP
1404.
141A regular expression (RE) enclosed with `/'s as delimiters (i.e. /RE/).
142This causes a forward search to the first occurrence of the specified RE. The
143address will then become this line.
144The character sequence \e/ escapes the forwardslash from being a
145delimiter.
146The search will wrap from the bottom of
147the buffer to the top of the buffer if need be.
148.I Ed
149RE's are, outside of this document, now refered to as
150.IR "basic regular expressions" .
151Basic regular expressions (BRE's), traditionally described in \fIed(1)\fR are
05ee7127 152now fully described in regex(7). BRE's are, for the most part, the same as
445c7738
KB
153the old RE's - the name has changed and the expressions extended to meet
154POSIX 1003.2 specifications. (See the search command for more details.)
155.TP
1565.
157A RE enclosed with `?'s as delimiters (i.e. ?RE?).
158This will cause a backward search to the first occurrence of the
159specified BRE. The address will then become this line.
160The character sequence \e? escapes the questionmark from being a
161delimiter.
162The search will wrap
163from the top of the buffer to the
164bottom of the buffer if need be. (See the search command for more details.)
165.TP
1666.
167A line previously marked by the `k' command (see below). \fB`x\fR addresses
168the line marked by the single lower-case letter `\fBx\fR' (from the
169portable character set in the range a-z).
170.TP
1717.
172An address of the form 1-6 followed by a `+' followed by an integer number,
173.BR n ,
174specifies the line to be addressed is
175.B n
176lines after the address of the form
1771-6.
178If the address starts with a `+' then by default the addressed line is taken
179with respect to
180.B current
181(equivalent to `.'\|; form 2).
182If no integer number is given then 1 is added to the address.
183Hence, if
184more than one `+' is given in a sequence, with no integer number following,
1851 is added to the address for each `+'. Therefore, +++ is eqivalent to +3,
186but +++1 is equivalent to +1.
187.TP
1888.
189An address of the form 1-6 followed by a `\-' followed by an integer number,
190.BR n ,
191specifies the line to be addressed is
192.B n
193lines before the address of the form
1941-6.
195If the address starts with a `\-' then by default the
196addressed line is taken
197with respect to
198.B current
199(`.'\|; form 1).
200If no integer number is given then 1 is subtracted from the address.
201Hence, if
202more than one `\-' is given in a sequence, with no integer number following,
2031 is subtracted from the address for each `\-'. Therefore, \-\-\-
204is eqivalent to \-3,
205but \-\-\-1 is equivalent to \-1.
206For backward compatibility `^' is the equivalent to `\-'.
207.TP
2089.
209A `,' (comma) may be used to separate two addresses of the form 1-8 to
210create an \fBaddress pair\fR.
211The first address must occur no later in
212the buffer than the second address to be legal.
213.TP
21410.
215A `;' (semicolon) may be used to separate two addresses of the form 1-8 to
216create an \fBaddress pair\fR.
217With this form the second address is evaluated with respect to
218and after the first address has been evaluated. This is useful when
219addresses of the forms 2-8 are used.
220The first address must occur no later in
221the buffer than the second address to be legal.
222.TP
223NOTE:
224Addresses of the forms 7 and 8 cannot be followed by addresses
225of forms 2-6; it is an error.
226.PP
227The following are special address forms that cannot be combined
228with any of the address forms listed above.
229A `,' by itself represents the address pair `1,$'.
230Likewise `%' by itself represents the address pair `1,$'.
231A `;' by itself represents the address pair `.,$'.
232.PP
233The \fIed\fR commands listed below default to the addresses prefixing the
234commands. Commands without default addresses accept zero addresses.
235The parentheses with the default addresses are not part of
236the address; they are used to show that the addresses are
237default.
238.PP
239Generally only one command appears on a line at a time.
240However, many of the commands may be suffixed by `l', `n',
241or `p', in which case
242the current line is printed
243in the manner discussed below.
244These suffixes may be combined in any order.
245.TP 5
246.RB (\|.\|)\|a
247.br
248.ns
249.TP 5
250<text>
251.br
252.ns
253.TP 5
254.B .
255.br
256Append text after the addressed line. A `.' in the first column
257followed immediately by a <newline> places
258.I ed
259back in command mode - the `.' is not included in the text. Line 0
260is legal for this command; text will be placed at the top of the buffer.
261.B Current
262is the last line appended (or the addressed line if no text given).
263.TP 5
264.RB (\|.\|,\|.\|)\|c
265.br
266.ns
267.TP 5
268<text>
269.br
270.ns
271.TP 5
272.B .
273.br
274Change text on the addressed line(s). The addressed lines are deleted
275before
276.I
277ed
278is placed in input mode. A `.' in the first column
279followed immediately by a <newline> places
280.I ed
281back in command mode - the `.' is not included in the text.
282.B Current
283is the new last line appended (or if no text is given the line after
284the addressed line deleted).
285.TP 5
286.RB (\|.\|,\|.\|)\|d
287Delete the addressed line(s) from the buffer. Deleted lines may be
288recovered with the undo command (\fIu\fR; see below).
289.B
290Current
291is the line after the last addressed line deleted.
292.TP 5
293e [filename]
294Edit the new file `filename'. The
295.B buffer
296is cleared and the new file is placed in the
297.BR buffer .
298If the
299.B buffer
300has been modified since the last write command
301.I ed
302will issue a warning (`?'); a second issuing of
303the command will be obeyed regardless.
304The number of characters read is printed (unless -s is specified
305at startup). If `filename' is missing, the remembered
306name is used.
307If `filename' is lead by ! then it shall be interpreted as a shell
2d5f5b81
KB
308command to be executed, from which the standard output will be
309placed into the buffer; `filename' will be non-remembered.
445c7738
KB
310Undo will not restore the
311.B buffer
312to its state before the edit command.
313.B Current
314is the last line in the
315.B buffer
316(`$').
317.TP 5
318E [filename]
319.I E
320works the same as
321.I e
322except if the buffer has been modified no warning is issued.
323.TP 5
324f [filename]
325Print the
326.BR "remembered filename" .
327If `filename' is specified the
328.B "remembered filename"
329will be set to `filename'.
330If `filename' is lead by ! then it shall be interpreted as a shell
2d5f5b81
KB
331command to be executed, from which the standard output will be used as
332the new remembered filename.
445c7738
KB
333.B Current
334is unchanged.
335.TP 5
336(1,$)\|g/regular expression/command list
337The global command first marks all lines matching
338the regular expression.
339For each matching line, the
340command list is executed. At the start of each command list execution,
341\fBcurrent\fR is set to equal that line; \fBcurrent\fR may change
342as each command in the command list is executed for that line.
343The first command of the command list begins on the same line as
344the global command.
345Generally, in the command list one command occupies a line. Thus to
346have multiple commands in the command list it is necessary to escape the
347<newline> at the end of each line so that the global command does not
348interpret it as an indication that the command list entry has ended.
71fc9f52 349The <newline> is escaped by proceeding it with a backslash (`\e').
445c7738 350Similarly with the commands that set \fIed\fR into input mode the <newlines>
e692f66f
KB
351of the entered text need to be escaped. If the `.' used to end input mode
352is the last line of the command list the <newline> following the `.' need
353not be escaped, or the `.' may be omitted entirely.
445c7738
KB
354Commands in the command list can affect any line in the buffer.
355For the behaviour of each \fIed\fR command within a command list refer to the
71fc9f52 356information on the individual command, particularly \fIs\fR and \fI!\fR.
445c7738
KB
357The commands
358.IR g ,
359.IR G ,
360.IR v ,
361.IR V ,
362and \fI!\fR
363are permitted in the command list, but should be used with caution.
364The command list defaults to
365.I p
366if left empty (i.e. g/RE/p).
367For the regular expression the delimiters can be any characters except
368for <space> and <newline>; delimiters within a regular expression can
369be escaped with a backslash preceeding it.
370.TP 5
371(1,$)\|G/regular expression/
372.br
373The interactive global command works similar to \fIg\fR. The first step
374is to mark every line which matches the given regular expression.
375For every line matched it will print this line, set \fBcurrent\fR
376to this line, and accept one command (not including \fIa\fR, \fIc\fR, \fIi\fR, \fIg\fR, \fIG\fR, \fIv\fR, and \fIV\fR)
377for execution.
378The command can affect any line in the buffer. `%' by itself executes
379the last non-null command.
380A return by itself will act as a null command. \fBCurrent\fR
381will be set to the last line affected by the last successful command
382input. If no match or an input command error occurs \fBcurrent\fR
383will be set to the last line searched by \fIG\fR. \fIG\fR can be prematurely
384ended by `ctrl-C' (SIGINT).
71fc9f52
KB
385For the behaviour of each \fIed\fR command within a command list refer to the
386information on the individual command, particularly \fIs\fR and \fI!\fR.
445c7738
KB
387
388.TP 5
389h
390.br
391The help command displays a message explaining the most recent command
392error (indicated by `?'). \fBCurrent\fR is unchanged.
393.TP 5
394H
395.br
396This toggles on or off the automatic display of messages explaining
397the most recent command error in place of `?'. \fBCurrent\fR is
398unchanged.
399.TP 5
400.RB (\|.\|)\|i
401.TP 5
402<text>
403.br
404.TP 5
405.B .
406.br
407The insert command places
408.I ed
409in input mode with the text being placed before the
410addressed line. Line 0 is invalid for this command.
411A `.' in the first column
412followed immediately by a return places
413.I ed
414back in command mode - the `.' is not included in the text.
415.B Current
416is the last line inserted. If no text is inserted then
417.B current
418is the addressed when
419.I ed
420is compiled for POSIX; compiled for BSD,
421.B current
422is the addressed line -1.
423.TP 5
424.RB (\|.\|,\|.+1)\|j
425The join command joins the addressed lines together to make one
426line. If no addresses are specified
427.B current
428and
429.BR current +1
430lines are joined.
431If one address only is given then
432no join is performed.
433.B Current
434becomes that line if
435.I ed
436has been compiled under the BSD option; if compiled under the POSIX
437option
438.B current
439is unchanged.
440.TP 5
441( \fB. \fR)\|k\fBx\fR
442The mark command marks the addressed line with label
443.BR x ,
444where
445.B x
446is a lowercase letter from the portable character set (a-z).
447The address form \fB`x\fR will refer to
448this line (address form 6 above).
449.B Current
450is unchanged.
451.TP 5
452.RB (\|.\|,\|.\|)\|l
453The list command
454prints the addressed lines in an unambiguous way:
455non-graphic characters are
456printed in three-digit octal preceded by a \e
457unless they are one of the following in which case they will be printed
458as indicated in the brackets:
459backslash (`\e\\'),
460horizontal tab (\et), form feed (\ef).
461return (\er), vertical tab (\ev), and backspace (\eb).
462Long lines will be broken base on the type of terminal currently in
463use.
464.B Current
465is set to the last line printed.
466The
467.I l
468command may be placed on the same line after any
469command except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR).
470.TP 5
471.RB (\|.\|,\|.\|)\|m\fBa\fR
472The move command moves the addressed lines in the buffer
473to after the address
474.BR a .
05ee7127 475Line 0 is valid as the address \fBa\fR for this command.
445c7738
KB
476.B Current
477is the location in the
478.B buffer
479of the last line moved.
480.TP 5
481.RB (\|.\|,\|.\|)\|n
482The number command prints the addressed lines preceding the text with the line number.
483The
484.I n
485command
486may
487be placed on the same line after any command
488except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR).
489.B Current
490is the last line printed.
491.TP 5
492.RB (\|.\|,\|.\|)\|p
493The print command prints the addressed lines.
494The
495.I p
496command
497may
498be placed on the same line after any command
499except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR).
500.B Current
501is the last line printed.
502.TP
503.RB (\|.\|,\|.\|)\|P
504This command is a synonym for
505.I p
506if
507.I ed
508has been compiled under the BSD option. If
509.I ed
510has been compiled under the POSIX option then the prompt is toggled on or off.
511.B Current
512is unchanged when compiled under the POSIX option.
513The default prompt is "*" if not specified with the \-p option at startup.
514The prompt is initially off unless the \-p option is specified.
515.TP 5
516q
517The quit command causes
518.I ed
71fc9f52 519to exit. If the entire
445c7738 520.B buffer
71fc9f52 521(1,$) has not been written since the last modification
445c7738
KB
522.I ed
523will
524issue a warning once (`?'); a second issuing of the command will be obeyed
525regardless.
526.TP 5
527Q
528.I Q
529works the same as
530.I q
531except if the buffer has been modified no warning is issued.
532.TP 5
533($)\|r [filename]
534The read command reads in the file `filename' after the
535addressed line. If no `filename' is specified then the
536.B "remembered filename"
537is used. Address 0 is valid for this command.
538If read is successful then the number of characters
539read is printed (unless the -s option is specified).
540If `filename' is lead by ! then it shall be interpreted as a shell
2d5f5b81
KB
541command to be executed, from which the standard output will be
542placed in the buffer; `filename' will be non-remembered.
445c7738
KB
543.B Current
544is the last line read.
545.TP 5
546(\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/\fBreplacement\fR/\fBflags\fR
547.br
548The substitute command searches for the regular expression in the
549addressed lines.
550On each line in which a match is found,
551matched strings are replaced by the \fBreplacement\fR as specified
552by the \fBflags\fR (see below).
553If no \fBflags\fR appear, by default only the first occurrence
554of the matched string in each line is replaced.
555It is an error if no matches to the RE occur.
556.IP
557The delimiters may be any character except <space> or <newline>.
558The delimiter lead by a \e will escape it to be a literal
559in the RE or
560.BR replacement .
561.IP
562An ampersand, `&', appearing in the replacement
563will equal the string matching the RE.
564The `&'s special meaning is supressable by leading
565it with a `\e'.
566When `%' is the only replacement character in
567.B replacement
568the most recent
569replacement is used.
570The `%'s special meaning is supressable by leading
571it with a `\e'.
572.IP
573The characters `\fB\en\fR' (where \fBn\fR is a digit 1-9) is
574replaced by the text matching the RE subexpression
575.B n
576(known as backreferencing).
577.I S
578may be used to break lines by including a <newline> in
579.B replacement
580preceeded by a backslash (`\e') to escape it.
581.B Replacement
582can continue on the next line and can include another escaped <newline>.
583.IP
584The following extention should not be included in portable scripts.
71fc9f52
KB
585When spliting lines using \fIs\fR within the global commands (\fIg\fR,
586\fIG\fR, \fIv\fR, or \fIV\fR) the <newline> in the replacement string
445c7738 587must be escaped by preceding it with `\e\e\e' (three adjacent `\e'\|s \-
71fc9f52
KB
588the first `\e' escapes the second `\e' so that it is passed to \fIs\fR
589to escape the <newline> passed by the global command; the third `\e'
590is to escape the <newline> so that the global command list continues).
591[N.B. Other \fIed\fR's do not allow line
2d5f5b81 592splitting within the global commands].
445c7738
KB
593.IP
594The \fBflags\fR may be any combination of:
595.RS
596.IP \fIcount\fR
597in each addressed line replace the \fIcount\fR\-th matching occurrence.
598.IP g
599in each addressed line replace all matching occurrences. When \fIcount\fR and
600g are specified together inclusively replace in each addressed line
601all matches from the \fIcount\fR\-th match to the end of line.
602.IP l
603write the line after replacement in the manner specified by the \fIl\fR
604command.
605.IP n
606write the line after replacement in the manner specified by the \fIn\fR
607command.
608.IP p
609write the line after replacement in the manner specified by the \fIp\fR
610command.
611.RE
612.IP
613The following special form
614should not be included in portable scripts.
615This form is maintained for backward compatibility and
616is extended to dovetail into the above forms of
617.BR s .
618.I S
619followed by
620.I no
621delimiters
622repeats the most recent substitute command
623on the addressed lines.
624.I S
625may be suffixed with the letters
626.BR r " (use the most recent RE rather than the last RE used with \fIs\fR),"
627.B p
628(complement the setting of the
629any print command (l, n, p)
630suffix from the previous substitution),
631.B g
632(complement the setting of the
633.I g
634suffix) or
635.B N
636(negate the previous \fIcount\fR flag).
637These modifying letters may be combined in any order
638(N.B. multiple use of the modifying letters may cause them
639to be interpreted as delimiters).
640.IP
641.B Current
642is set to the last line search (BSD) or where the last replacement
643occurred (POSIX).
644.TP 5
645.RB (\|.\|,\|.\|)\|t\|\fBa\fR
646The transcribe command copies the addressed lines in
647the
648.B buffer
649to after the address
650.BR a .
05ee7127 651Address 0 is valid as the address \fBa\fR for this command.
445c7738
KB
652.B Current
653is the last line transcribed.
654.TP 5
655.RB (\|.\|,\|.\|)\|u
656The undo command nullifies the most recent
657.B buffer
658modifying command.
659Buffer modifying commands undo works on are
660.IR a ,
661.IR c ,
662.IR d ,
663.IR g ,
664.IR G ,
665.IR i ,
666.IR j ,
667.IR m ,
668.IR r ,
669.IR s ,
670.IR t ,
671.IR u ,
672.IR v ,
673and
674.I V.
675Marks set by the \fIk\fR command will also be restored.
676All commands (including nested \fIg\fR, \fIG\fR, \fIv\fR, and
677\fIV\fR commands within the \fIg\fR or \fIv\fR)
678that undo works on are treated as a single buffer modification.
679\fBCurrent\fR is set to the line it addressed before the last
680buffer modification.
681.TP 5
682(1, $)\|v/regular expression/command list
683The global non-matching command performs as the
684.I g
685command does except that the command list is executed for every line
686that does not match the RE.
687.TP 5
688(1, $)\|V/regular expression/
689The interactive global non-matching command is the same as the
690.I G
691except that one command will be accepted as input
692with \fBcurrent\fR initially set to every line
693that does not match the RE.
694.TP 5
695(1, $)\|w [filename]
696.br
697The write command writes the addressed lines to the file `filename'.
698If no `filename' is specified then the
699.B "remembered filename"
700is used. If no addresses are specified the whole
701.B buffer
702is written.
703If the command is successful, the number of characters written is
704printed (unless the -s option is specified).
705If `filename' is lead by ! then it shall be interpreted as a shell
2d5f5b81
KB
706command to be executed which will accept on its standard input
707the section of the buffer specified for writting.
445c7738
KB
708\fBCurrent\fR is unchanged.
709.TP
710(1, $)\|W [filename]
711.I W
712works as the
713.I w
714command does except the addressed contents of the
715.B buffer
716are appended to `filename' (or the
71fc9f52 717.B "remembered filename"
2d5f5b81
KB
718if `filename' is not specified). If `filename' is lead by ! then
719.I W
720will act exactly as the
721.I w
722command.
445c7738
KB
723\fBCurrent\fR is unchanged.
724.TP 5
725(1, $)\|wq [filename]
726.I wq
727works as the
728.I w
729command does with the addition that
730.I ed
731exits immediately after the write is complete.
732\fBCurrent\fR is unchanged.
733.TP 5
734(1,$)\|Wq [filename]
735.I Wq
736works as the
737.I W
738command does with the addition that
739.I ed
71fc9f52 740exits immediately after the appended write is complete.
445c7738
KB
741\fBCurrent\fR is unchanged.
742.TP 5
743.RB (\|.\|+1)\|z\ \ \ \ or,
744.br
745.TP 5
746.RB (\|.\|+1)\|z\fBn\fR
747Scroll through the
748.BR buffer .
749Starting from the addressed line (or
750.BR current +1)
751print the next 22 (by default or
752.BR n )
753lines. The
754.B n
755is a sticky value; it becomes the default number of lines printed
756for successive scrolls.
757.B Current
758is the last line printed.
759.TP 5
760($)\|=
761Print the number of lines in the
762.BR buffer .
763If an address is provided (in the forms 1-8 above) then the line number
764for that line will be printed.
765\fBCurrent\fR is unchanged.
766.TP 5
767!<shell command>
768The command after the
769.I !
770is executed by \fIsh(1)\fR and the results are printed. A `!' is
771printed in the first column when execution has completed (unless the -s
772option has been specified).
71fc9f52
KB
773A `!' immediately after \fI!\fR repeats the last shell command.
774An unescaped `%' represents the remembered filename.
775Commands to \fIsh(1)\fR can have several lines by escaping the <newline>
776with a `\e' immediately before it. The line continuation character
777for \fIsh(1)\fR, `\e', can be included on a line provided that it
778is escaped by a `\e' immediately before so that \fIed\fR passes it
779literally to \fIsh(1)\fR: `\e\e'. It is implicit that for the command
780line that the \fIsh(1)\fR line continuation character is on that the
781<newline> will be escaped (e.g. `\e\e\e<newline>').
782This behavior can be used within global command lists. However, an
783additional `\e' must be added so that the \fI!\fR command continuor is
784passed to \fI!\fR - it must occur immediately before the global
785command's continuor. Therefore,
786the \fI!\fR command continuation sequence in a global command list
787will appear as `\e\e\e' (explanation as with \fIsfR). The line continuation
788character for \fIsh(1)\fR needs no additional escaping (since it it
789not dependant on <newline> being adjacent) - hence, the
790sequence in a global command list with a line continuation will appear
791as `\e\e\e\e\e<newline>'.
792
445c7738
KB
793\fBCurrent\fR is unchanged.
794.TP 5
795/regular expression/\|\|\|\|\|or,
796.br
797.TP 5
798?regular expression?
799.br
800The search command searches forward, `/', (or backward, `?') through the
801.B buffer
802attempting to find
803a line that matches the RE. The search will wrap to the top (or bottom)
804of the
805.B buffer
806if necessary. Search returns the line number that the match occurs on -
807combined with the null command (see below) this causes the line to be printed.
808.B Current
809is the matching line.
810.TP 5
811.RB (\|.+1,\|.+1)\|<newline>
812.br
813The null command is equivalent to asking for the line
814.BR current +1
815to be printed according to the
816.I p
817command. This is a useful command to quickly print the next couple of
818lines. If more than a couple of lines are needed the
819.I z
820command (see above) is much better to use.
821\fBCurrent\fR is the last line printed.
822
823.SH OTHER
824.PP
825If an interrupt signal (SIGINT)\| is sent,
826.I ed
827prints `?'
828and returns to command mode.
829.PP
830BSD command pairs (pp, ll, etc.) are permitted. Additionally any single
831print command may follow any of the non-I/O commands (I/O commands:
832e, E, f, r, w, W, wq, and !). This will cause the current line to be
833printed in the specified manner after the command has completed.
834.PP
835Previous limitations on the number of characters per line and per command
836list have been lifted; there is now no maximum.
837File name and path length is restricted to the maximum length that
838the current file system supports.
839The
840.I undo
841command now restores marks to affected lines.
842The temporary buffer method will vary dependent on the method selected at
843compile. Two methods work with a temporary file (stdio and db), while the
844third uses memory.
845The limit on the number of lines depends on the amount of memory.
846.SH FILES
2d5f5b81
KB
847/tmp/_bsd44_ed*
848.br
445c7738
KB
849.XP
850ed.hup: the buffer is written to this file in the current
2d5f5b81
KB
851directory if possible and in the HOME directory is not
852(if the signal SIGHUP (hangup) is received).
445c7738
KB
853.SH "SEE ALSO"
854B. W. Kernighan,
855.I
856A Tutorial Introduction to the ED Text Editor
857.br
858B. W. Kernighan,
859.I
860Advanced editing on UNIX
861.br
05ee7127 862ex(1), learn(1), regex(3), regex(7), sed(1), vi(1), POSIX 1003.2 (4.20)
445c7738
KB
863.SH "AUTHOR"
864Rodney Ruddock
865.SH DIAGNOSTICS
866`?name' for a file that is either inaccessible, does not exist, or is
867a directory. `?'
868for all other errors unless the help messages have been toggled on (with
869the H command) in which case a descriptive message will be printed.
870.PP
2d5f5b81
KB
871EOF is treated as a newline during input so that characters after the last <newline>
872are included into the \fBbuffer\fR; the message "<newline> added at
873end of line" is printed.
445c7738
KB
874.PP
875.I Ed
2d5f5b81
KB
876Returns an exit status of 0 on successful completion. A value >0 is returned
877to indicate an \fIed\fR error: 1 for a command line error, 2 for HUP
878signal received, 4 for an \fIed\fR command error; these error values
879will be or'd together when appropriate.
445c7738
KB
880.SH NOTES
881.PP
882Regular expressions are now described on regex(7).
883.I Ed
884follows basic regular expressions (BRE's) as described on regex(7).
885BRE's, for the most part, are the same as previous
886.I ed
2d5f5b81 887RE's. The changes to the RE's are extensions for internationalization
445c7738
KB
888under POSIX 1003.2. Old scripts with RE's should work without
889modification.
890.PP
05ee7127
KB
891Regular expression logic is very tight. If you believe a command with a
892regular expression in it has performed erroneously then a close reading
893of regex(7) is likely required.
894.PP
895Address `0' is legal only for those commands which explicitly state that
896it may be used; its use is illegal for all other commands.
897.PP
445c7738
KB
898The special form of substitute has been maintained for backward
899compatability and should not be used in scripts if they are to
900portable.
901.PP
902Help messages may appear ambiguous to beginners - particularly when BRE's
903form part of the command.
904.PP
905For backward compatability, when more addresses are provided
906than required by a command the one or two addresses closest to the
907command are used (depending on how may addresses the command accepts).
908Portable scripts should not rely on this feature.
909.PP
910For backward compatibility the option `-' is
911equivalent to the `-s' option at the startup of
912.IR ed .