BSD 4_3_Reno release
[unix-history] / usr / src / foreign / src / ed / ed.1
CommitLineData
dd9e2e8d
CL
1.\" Copyright (c) 1990 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
fd315f2c 4.\"
1c15e888 5.\" @(#)ed.1 6.5.1.1 (Berkeley) 10/21/90
b5dc1377 6.\"
1c15e888 7.Dd October 21, 1990
b5dc1377
CL
8.Dt ED 1
9.Os ATT 7th
fd315f2c
KM
10.if t .ds q \(aa
11.if n .ds q '
b5dc1377
CL
12.Sh NAME
13.Nm ed
14.Nd text editor
15.Sh SYNOPSIS
16.Nm ed
17.Op Fl
b5dc1377
CL
18.Op Ar file
19.Sh DESCRIPTION
20.Nm Ed
fd315f2c 21is the standard text editor.
b5dc1377 22.Pp
fd315f2c 23If a
b5dc1377 24.Ar file
fd315f2c 25argument is given,
b5dc1377 26.Nm ed
fd315f2c 27simulates an
b5dc1377
CL
28.Ic e
29command (see below) on the named file; that is to say,
fd315f2c 30the file is read into
b5dc1377 31.Nm ed 's
fd315f2c 32buffer so that it can be edited.
5325ced3 33.Tw Ds
b5dc1377
CL
34.Tp Fl
35Suppresses the printing
fd315f2c
KM
36of explanatory output
37and should be used
38when the standard input is
39an editor script.
b5dc1377
CL
40.Tp
41.Pp
42.Nm Ed
fd315f2c
KM
43operates on a copy of any file it is editing; changes made
44in the copy have no effect on the file until a
b5dc1377
CL
45.Ic w
46(write) command is given.
fd315f2c 47The copy of the text being edited resides
b5dc1377
CL
48in a temporary file called the
49.Ar buffer .
50.Pp
fd315f2c 51Commands to
b5dc1377 52.Nm ed
fd315f2c
KM
53have a simple and regular structure: zero or
54more
b5dc1377 55.Ar addresses
fd315f2c 56followed by a single character
b5dc1377 57.Ar command ,
fd315f2c
KM
58possibly
59followed by parameters to the command.
60These addresses specify one or more lines in the buffer.
61Missing addresses are supplied by default.
b5dc1377 62.Pp
fd315f2c 63In general, only one command may appear on a line.
b5dc1377 64Certain commands allow the
fd315f2c
KM
65addition of text to the buffer.
66While
b5dc1377 67.Nm ed
fd315f2c
KM
68is accepting text, it is said
69to be in
b5dc1377 70.Ar input mode .
fd315f2c
KM
71In this mode, no commands are recognized;
72all input is merely collected.
b5dc1377
CL
73Input mode is left by typing a period
74.Sq Ic \&.
75alone at the
fd315f2c 76beginning of a line.
b5dc1377
CL
77.Pp
78.Nm Ed
fd315f2c 79supports a limited form of
b5dc1377 80.Ar regular expression
fd315f2c
KM
81notation.
82A regular expression specifies
83a set of strings of characters.
84A member of this set of strings is said to be
b5dc1377 85.Ar matched
fd315f2c
KM
86by the regular expression.
87In the following specification for regular expressions
88the word `character' means any character but newline.
b5dc1377
CL
89.Tw Ds
90.Tp 1.
fd315f2c
KM
91Any character except a special character
92matches itself.
93Special characters are
94the regular expression delimiter plus
5325ced3 95.Sq Cm \e\[.
b5dc1377 96and sometimes
5325ced3 97.Sq Cm ^*$ .
b5dc1377 98.Tp 2.
fd315f2c 99A
5325ced3 100.Sq Cm \&.
fd315f2c 101matches any character.
b5dc1377
CL
102.Tp 3.
103A
104.Sq Li \e
105followed by any character except a digit or
106.Li (\)
107matches that character.
108.Tp 4.
fd315f2c 109A nonempty string
b5dc1377
CL
110.Op Ar s
111or
5325ced3 112.Oo
b5dc1377 113.Cx \&(
5325ced3 114.Op Cm \&^ Ar s
b5dc1377
CL
115.Cx \&)
116.Cx
5325ced3 117.Oo
fd315f2c 118matches any character in (or not in)
b5dc1377
CL
119.Ar s .
120In
121.Ar s ,
122.Sq Li \e
123has no special meaning, and
124may only appear as
fd315f2c 125the first letter.
b5dc1377
CL
126A substring
127.Ar a\-b ,
fd315f2c 128with
b5dc1377 129.Ar a
fd315f2c 130and
b5dc1377 131.Ar b
fd315f2c
KM
132in ascending ASCII order, stands for the inclusive
133range of ASCII characters.
b5dc1377
CL
134.Tp 5.
135A regular expression of form 1\-4 followed by * matches a sequence of
fd315f2c 1360 or more matches of the regular expression.
b5dc1377 137.Tp 6.
fd315f2c 138A regular expression,
b5dc1377
CL
139.Ar x ,
140of form 1\-8, bracketed
141.Cx Li \e(
142.Ar x
143.Li \e)
144.Cx
fd315f2c 145matches what
b5dc1377 146.Ar x
fd315f2c 147matches.
b5dc1377
CL
148.Tp 7.
149A \e followed by a digit
150.Ar n
fd315f2c
KM
151matches a copy of the string that the
152bracketed regular expression beginning with the
b5dc1377
CL
153.Cx Ar n
154.Cx \'th
155.Cx
156.Li \e(
157matched.
158.Tp 8.
159A regular expression of form 1\-8,
160.Ar x ,
161followed by a regular expression of form 1\-7,
162.Ar y
fd315f2c 163matches a match for
b5dc1377 164.Ar x
fd315f2c 165followed by a match for
b5dc1377 166.Ar y ,
fd315f2c 167with the
b5dc1377 168.Ar x
fd315f2c 169match being as long as possible while still permitting a
b5dc1377 170.Ar y
fd315f2c 171match.
b5dc1377
CL
172.Tp 9.
173A regular expression of form 1\-8 preceded by
174.Sq Li ^
175(or followed by
176.Sq Li $ ) ,
177is constrained to matches that
fd315f2c 178begin at the left (or end at the right) end of a line.
b5dc1377
CL
179.Tp 10.
180A regular expression of form 1\-9 picks out the
fd315f2c 181longest among the leftmost matches in a line.
b5dc1377 182.Tp 11.
fd315f2c
KM
183An empty regular expression stands for a copy of the
184last regular expression encountered.
b5dc1377
CL
185.Tp
186.Pp
fd315f2c
KM
187Regular expressions are used in addresses to specify
188lines and in one command
189(see
b5dc1377
CL
190.Ar s
191below)
fd315f2c
KM
192to specify a portion of a line which is to be replaced.
193If it is desired to use one of
194the regular expression metacharacters as an ordinary
b5dc1377
CL
195character, that character may be preceded by
196.Sq Li \e .
fd315f2c 197This also applies to the character bounding the regular
b5dc1377
CL
198expression (often
199.Sq Li \&/ )
200and to
201.Sq Li \e
202itself.
203.Pp
fd315f2c 204To understand addressing in
b5dc1377 205.Nm ed
fd315f2c 206it is necessary to know that at any time there is a
b5dc1377 207.Ar current line.
fd315f2c
KM
208Generally speaking, the current line is
209the last line affected by a command; however,
210the exact effect on the current line
211is discussed under the description of
212the command.
213Addresses are constructed as follows.
b5dc1377
CL
214.Tw Ds
215.Tp 1.
216The character
217.Sq Ic \&.
218addresses the current line.
219.Tp 2.
220The character
221.Cx `
222.Ic $
223.Cx \'
224.Cx
225addresses the last line of the buffer.
226.Tp 3.
fd315f2c 227A decimal number
b5dc1377 228.Ar n
fd315f2c 229addresses the
b5dc1377
CL
230.Cx Ar n
231.Cx \'th
232.Cx
fd315f2c 233line of the buffer.
b5dc1377
CL
234.Tp 4.
235.Cx `\(fm
236.Ar x
237.Cx \'
238.Cx
239addresses the line marked with the name
240.Ar x ,
fd315f2c
KM
241which must be a lower-case letter.
242Lines are marked with the
b5dc1377 243.Ar k
fd315f2c 244command described below.
b5dc1377
CL
245.Tp 5.
246A regular expression enclosed in slashes
247.Cx `
248.Li /
249.Cx \'
250.Cx
251addresses
fd315f2c
KM
252the line found by searching forward from the current line
253and stopping at the first line containing a
254string that matches the regular expression.
255If necessary the search wraps around to the beginning of the
256buffer.
b5dc1377
CL
257.Tp 6.
258A regular expression enclosed in queries
259.Cx `
260.Li ?
261.Cx \'
262.Cx
263addresses
fd315f2c
KM
264the line found by searching backward from the current line
265and stopping at the first line containing
266a string that matches the regular expression.
267If necessary
268the search wraps around to the end of the buffer.
b5dc1377
CL
269.Tp 7.
270An address followed by a plus sign
271.Cx `
272.Li +
273.Cx \'
274.Cx
275or a minus sign
276.Cx `
277.Li \-
278.Cx \'
279.Cx
280followed by a decimal number specifies that address plus
281(resp. minus) the indicated number of lines.
fd315f2c 282The plus sign may be omitted.
b5dc1377
CL
283.Tp 8.
284If an address begins with
285.Cx `
286.Li +
287.Cx \'
288.Cx
289or
290.Cx `
291.Li \-
292.Cx \'
293.Cx
fd315f2c 294the addition or subtraction is taken with respect to the current line;
b5dc1377
CL
295e.g.
296.Cx `
297.Li \-5
298.Cx \'
299.Cx
300is understood to mean
301.Cx `
302.Li .\-5
303.Cx \'
304.Cx
305.Nm .
306.Tp 9.
307If an address ends with
308.Cx `
309.Li +
310.Cx \'
311.Cx
312.Cx `
313.Li \-
314.Cx \',
315.Cx
fd315f2c
KM
316then 1 is added (resp. subtracted).
317As a consequence of this rule and rule 8,
b5dc1377
CL
318the address
319.Cx `
320.Li \-
321.Cx \'
322.Cx
323refers to the line before the current line.
fd315f2c
KM
324Moreover,
325trailing
b5dc1377
CL
326.Cx `
327.Li +
328.Cx \'
329.Cx
330and
331.Cx `
332.Li \-
333.Cx \'
334.Cx
335characters
336have cumulative effect, so
337.Cx `
338.Li \-\-
339.Cx \'
340.Cx
341refers to the current
fd315f2c 342line less 2.
b5dc1377 343.Tp 10.
fd315f2c 344To maintain compatibility with earlier versions of the editor,
b5dc1377
CL
345the character
346.Cx `
347.Li ^
348.Cx \'
349.Cx
350in addresses is
351equivalent to
352.Cx `
353.Li \-
354.Cx \'.
355.Cx
356.Tp
357.Pp
fd315f2c
KM
358Commands may require zero, one, or two addresses.
359Commands which require no addresses regard the presence
360of an address as an error.
361Commands which accept one or two addresses
362assume default addresses when insufficient are given.
363If more addresses are given than such a command requires,
b5dc1377
CL
364the last one or two (depending on what is accepted) are used.
365.Pp
fd315f2c 366Addresses are separated from each other typically by a comma
b5dc1377
CL
367.Cx `
368.Li ,
369.Cx \'
370.Cx
fd315f2c 371They may also be separated by a semicolon
b5dc1377
CL
372.Cx `
373.Li ;
374.Cx \'
375.Cx
376In this case the current line
377.Cx `
378.Li .
379.Cx \'
380.Cx
381.Nm .
382is set to
fd315f2c
KM
383the previous address before the next address is interpreted.
384This feature can be used to determine the starting
b5dc1377
CL
385line for forward and backward searches
386.Cx \&(`
387.Li /
388.Cx \'
389.Cx
390.Cx `
391.Li ?
392.Cx \').
393.Cx
fd315f2c
KM
394The second address of any two-address sequence
395must correspond to a line following the line corresponding to the first address.
b5dc1377
CL
396The special form
397.Cx `
398.Li \&%
399.Cx \'
400.Cx
401is an abbreviation for the address pair
402.Cx `
403.Li 1,$
404.Cx \'.
405.Cx
406.Pp
fd315f2c 407In the following list of
b5dc1377 408.Nm ed
fd315f2c
KM
409commands, the default addresses
410are shown in parentheses.
411The parentheses are not part of
412the address, but are used to show that the given addresses are
413the default.
b5dc1377 414.Pp
fd315f2c
KM
415As mentioned, it is generally illegal for more than one
416command to appear on a line.
417However, most commands may be suffixed by `p'
418or by `l', in which case
419the current line is either
420printed or listed respectively
421in the way discussed below.
422Commands may also be suffixed by `n',
423meaning the output of the command is to
424be line numbered.
425These suffixes may be combined in any order.
b5dc1377
CL
426.Tw Ds
427.Tp Cx \&(
428.Ic .
429.Cx \&)
430.Ic a
431.Cx
432.Tp <text>
433.Tp Ic \&.
fd315f2c
KM
434The append command reads the given text
435and appends it after the addressed line.
b5dc1377
CL
436.Sq Ic \&.
437is left
fd315f2c
KM
438on the last line input, if there
439were any, otherwise at the addressed line.
440Address `0' is legal for this command; text is placed
441at the beginning of the buffer.
b5dc1377
CL
442.Tp Cx \&(
443.Ic \&.
444.Cx \&,
445.Ic \&.
446.Cx \&)
447.Ic \&c
448.Cx
449.Tp <text>
450.Tp Ic \&.
fd315f2c
KM
451The change
452command deletes the addressed lines, then accepts input
453text which replaces these lines.
b5dc1377
CL
454.Sq Ic \&.
455is left at the last line input; if there were none,
fd315f2c 456it is left at the line preceding the deleted lines.
b5dc1377
CL
457.Tp Cx \&(
458.Ic \&.
459.Cx \&,
460.Ic \&.
461.Cx \&)
462.Ic \&d
463.Cx
fd315f2c
KM
464The delete command deletes the addressed lines from the buffer.
465The line originally after the last line deleted becomes the current line;
466if the lines deleted were originally at the end,
467the new last line becomes the current line.
b5dc1377
CL
468.Tp Cx Ic \&e
469.Cx \&\ \&
470.Ar filename
471.Cx
fd315f2c
KM
472The edit
473command causes the entire contents of the buffer to be deleted,
474and then the named file to be read in.
b5dc1377
CL
475.Sq Ic \&.
476is set to the last line of the buffer.
fd315f2c 477The number of characters read is typed.
b5dc1377
CL
478.Ar filename
479is remembered for possible use as a default file name
fd315f2c 480in a subsequent
b5dc1377 481.Ic r
fd315f2c 482or
b5dc1377 483.Ic w
fd315f2c 484command.
b5dc1377
CL
485If
486.Ar filename
487is missing, the remembered name is used.
488.Tp Cx Ic E
489.Cx \&\ \&
490.Ar filename
491.Cx
fd315f2c 492This command is the same as
b5dc1377 493.Ic e ,
fd315f2c 494except that no diagnostic results when no
b5dc1377 495.Ic w
fd315f2c 496has been given since the last buffer alteration.
b5dc1377
CL
497.Tp Cx Ic f
498.Cx \&\ \&
499.Ar filename
500.Cx
fd315f2c 501The filename command prints the currently remembered file name.
b5dc1377
CL
502If
503.Ar filename
504is given,
505the currently remembered file name is changed to
506.Ar filename .
507.Tp Cx \&(
508.Ic \&1
509.Cx \&,
510.Ic \&$
511.Cx \&)
512.Ic \&g
513.Ar/regular expression/command list
514.Cx
fd315f2c
KM
515In the global
516command, the first step is to mark every line which matches
517the given regular expression.
518Then for every such line, the
b5dc1377
CL
519given command list is executed with
520.Cx `
521.Ic \&.
522.Cx \'
523.Cx
524initially set to that line.
fd315f2c
KM
525A single command or the first of multiple commands
526appears on the same line with the global command.
b5dc1377
CL
527All lines of a multi-line list except the last line must be ended with
528.Cx `
529.Ic \&\e
530.Cx \'.
531.Cx
532.Ic A ,
533.Ic i,
fd315f2c 534and
b5dc1377 535.Ic c
fd315f2c 536commands and associated input are permitted;
b5dc1377
CL
537the
538.Cx `
539.Ic \&.
540.Cx \'
541.Cx
542terminating input mode may be omitted if it would be on the
fd315f2c
KM
543last line of the command list.
544The commands
b5dc1377 545.Ic g
fd315f2c 546and
b5dc1377 547.Ic v
fd315f2c 548are not permitted in the command list.
b5dc1377
CL
549.Tp Cx \&(
550.Ic .
551.Cx \&)
552.Ic i
553.Cx
554.Tp <text>
555.Tp Ic \&.
fd315f2c 556This command inserts the given text before the addressed line.
b5dc1377
CL
557.Cx `
558.Ic \&.
559.Cx \'
560.Cx
561is left at the last line input, or, if there were none,
fd315f2c
KM
562at the line before the addressed line.
563This command differs from the
b5dc1377 564.Ic a
fd315f2c
KM
565command only in the placement of the
566text.
b5dc1377
CL
567.Tp Cx \&(
568.Ic \&.
569.Cx \&,
570.Ic \&.+1
571.Cx \&)
572.Ic \&j
573.Cx
fd315f2c
KM
574This command joins the addressed lines into a single line;
575intermediate newlines simply disappear.
b5dc1377
CL
576.Cx `
577.Ic \&.
578.Cx \'
579.Cx
580is left at the resulting line.
581.Tp Cx \&(
582.Ic .
583.Cx \&)
584.Ic k
585.Ar x
586.Cx
fd315f2c
KM
587The mark command marks the addressed line with
588name
b5dc1377 589.Ar x ,
fd315f2c 590which must be a lower-case letter.
b5dc1377
CL
591The address form
592.Cx `\(fm
593.Ar x
594.Cx \'
595.Cx
596then addresses this line.
597.Tp Cx \&(
598.Ic \&.
599.Cx \&,
600.Ic \&.
601.Cx \&)
602.Ic \&l
603.Cx
fd315f2c
KM
604The list command
605prints the addressed lines in an unambiguous way:
606non-graphic characters are
607printed in two-digit octal,
608and long lines are folded.
609The
b5dc1377 610.Ar l
fd315f2c
KM
611command may be placed on the same line after any non-i/o
612command.
b5dc1377
CL
613.Tp Cx \&(
614.Ic \&.
615.Cx \&,
616.Ic \&.
617.Cx \&)
618.Ic \&m
619.Ar a
620.Cx
fd315f2c
KM
621The move command repositions the addressed lines after the line
622addressed by
b5dc1377 623.Ar a .
fd315f2c 624The last of the moved lines becomes the current line.
b5dc1377
CL
625.Tp Cx \&(
626.Ic \&.
627.Cx \&,
628.Ic \&.
629.Cx \&)
630.Ic \&p
631.Cx
fd315f2c 632The print command prints the addressed lines.
b5dc1377
CL
633.Cx `
634.Ic \&.
635.Cx \'
636.Cx
fd315f2c
KM
637is left at the last line printed.
638The
b5dc1377 639.Ic p
fd315f2c
KM
640command
641may
642be placed on the same line after any non-i/o command.
b5dc1377
CL
643.Tp Cx \&(
644.Ic \&.
645.Cx \&,
646.Ic \&.
647.Cx \&)
648.Ic \&P
649.Cx
fd315f2c 650This command is a synonym for
b5dc1377
CL
651.Ic p .
652.Tp Ic q
fd315f2c 653The quit command causes
b5dc1377 654.Nm ed
fd315f2c
KM
655to exit.
656No automatic write
657of a file is done.
b5dc1377 658.Tp Ic Q
fd315f2c 659This command is the same as
b5dc1377 660.Ic q ,
fd315f2c 661except that no diagnostic results when no
b5dc1377 662.Ic w
fd315f2c 663has been given since the last buffer alteration.
b5dc1377
CL
664.Tp Cx \&(
665.Ic $
666.Cx \&)
667.Ic r
668.Cx \&\ \&
669.Ar filename
670.Cx
fd315f2c
KM
671The read command
672reads in the given file after the addressed line.
673If no file name is given,
674the remembered file name, if any, is used
675(see
b5dc1377 676.Ic e
fd315f2c 677and
b5dc1377
CL
678.Ic f
679commands).
fd315f2c
KM
680The file name is remembered if there was no
681remembered file name already.
682Address `0' is legal for
b5dc1377 683.Ic r
fd315f2c
KM
684and causes the
685file to be read at the beginning of the buffer.
686If the read is successful, the number of characters
687read is typed.
b5dc1377
CL
688.Cx `
689.Ic \&.
690.Cx \'
691.Cx
692is left at the last line read in from the file.
693.Tp Cx \&(
694.Ic \&.
695.Cx \&,
696.Ic \&.
697.Cx \&)
698.Ic \&s
699.Ar/regular expression/replacement/
700.Cx \&\tor
701.Cx
702.Tp Cx \&(
703.Ic \&.
704.Cx \&,
705.Ic \&.
706.Cx \&)
707.Ic \&s
708.Ar/regular expression/replacement/
709.Ic \&g
710.Cx
fd315f2c
KM
711The substitute command searches each addressed
712line for an occurrence of the specified regular expression.
713On each line in which a match is found,
714all matched strings are replaced by the replacement specified,
b5dc1377
CL
715if the global replacement indicator
716.Ic \&g
717appears after the command.
fd315f2c
KM
718If the global indicator does not appear, only the first occurrence
719of the matched string is replaced.
720It is an error for the substitution to fail on all addressed lines.
721Any punctuation character
b5dc1377
CL
722may be used instead of
723.Cx `
724.Ic \&/
725.Cx \'
726.Cx
727to delimit the regular expression
fd315f2c 728and the replacement.
b5dc1377
CL
729.Cx `
730.Ic \&.
731.Cx \'
732.Cx
733is left at the last line substituted.
734An ampersand
735.Cx `
736.Ic \&&
737.Cx \'
738.Cx
739appearing in the replacement
fd315f2c 740is replaced by the string matching the regular expression.
b5dc1377
CL
741The special meaning of
742.Cx `
743.Ic \&&
744.Cx \'
745.Cx
746in this context may be
747suppressed by preceding it by
748.Cx `
749.Ic \&\e
750.Cx \'.
751.Cx
fd315f2c 752The characters
b5dc1377
CL
753.Cx `
754.Ic \&\e
755.Ar n
756.Cx \'
757.Cx
fd315f2c 758where
b5dc1377 759.Ar n
fd315f2c
KM
760is a digit,
761are replaced by the text matched by the
b5dc1377
CL
762.Cx Ar n
763.Cx \'th
764.Cx
fd315f2c 765regular subexpression
b5dc1377
CL
766enclosed between
767.Cx `
768.Ic \&\e\&(
769.Cx \'.
770.Cx
771and
772.Cx `
773.Ic \&\e\&)
774.Cx \'.
775.Cx
fd315f2c
KM
776When
777nested, parenthesized subexpressions
778are present,
b5dc1377
CL
779.Ar n
780is determined by counting occurrences of
781.Cx `
782.Ic \&\e\&(
783.Cx \'.
784.Cx
785starting from the left.
fd315f2c
KM
786Lines may be split by substituting new-line characters into them.
787The new-line in the
788replacement string
b5dc1377
CL
789must be escaped by preceding it by
790.Cx `
791.Ic \&\e
792.Cx \'.
793.Cx
fd315f2c 794One or two trailing delimiters may be omitted,
b5dc1377
CL
795implying the
796.Ic p
797suffix.
798The special form
799.Ic s
800followed by
801.Ar no
fd315f2c
KM
802delimiters
803repeats the most recent substitute command
804on the addressed lines.
b5dc1377
CL
805The
806.Ic s
807may be followed by the letters
808.Ic r
fd315f2c
KM
809(use the most recent regular expression for the
810left hand side, instead of the most recent
811left hand side of a substitute command),
b5dc1377 812.Ic p
fd315f2c 813(complement the setting of the
b5dc1377 814.Ic p
fd315f2c 815suffix from the previous substitution), or
b5dc1377 816.Ic g
fd315f2c 817(complement the setting of the
b5dc1377 818.Ic g
fd315f2c
KM
819suffix).
820These letters may be combined in any order.
b5dc1377
CL
821.Tp Cx \&(
822.Ic \&.
823.Cx \&,
824.Ic \&.
825.Cx \&)
826.Ic \&t
827.Ar a
828.Cx
fd315f2c 829This command acts just like the
b5dc1377 830.Ic m
fd315f2c
KM
831command, except that a copy of the addressed lines is placed
832after address
b5dc1377 833.Ad a
fd315f2c 834(which may be 0).
b5dc1377
CL
835.Cx `
836.Ic \&.
837.Cx \'
838.Cx
839is left on the last line of the copy.
840.Tp Cx \&(
841.Ic \&.
842.Cx \&,
843.Ic \&.
844.Cx \&)
845.Ic \&u
846.Cx
fd315f2c
KM
847The undo command restores the buffer to it's state
848before the most recent buffer modifying command.
849The current line is also restored.
850Buffer modifying commands are
b5dc1377 851.Ic a , c , d , g , i , k , m , r , s , t ,
fd315f2c 852and
b5dc1377 853.Ic v .
fd315f2c 854For purposes of undo,
b5dc1377 855.Ic g
fd315f2c 856and
b5dc1377 857.Ic v
fd315f2c
KM
858are considered to be a single buffer modifying command.
859Undo is its own inverse.
fd315f2c 860When
b5dc1377 861.Nm ed
fd315f2c
KM
862runs out of memory
863(at about 8000 lines on any 16 bit mini-computer
864such as the PDP-11)
865This full undo is not possible, and
b5dc1377 866.Ic u
fd315f2c
KM
867can only undo the effect of the most recent
868substitute on the current line.
869This restricted undo also applies to editor scripts
870when
b5dc1377 871.Nm ed
fd315f2c 872is invoked with the
b5dc1377 873.Fl
fd315f2c 874option.
b5dc1377
CL
875.Tp Cx \&(
876.Ic \&1
877.Cx \&,
878.Ic \&$
879.Cx \&)
880.Ic \&v
881.Ar/regular expression/command list
882.Cx
fd315f2c 883This command is the same as the global command
b5dc1377 884.Ic g
fd315f2c 885except that the command list is executed
b5dc1377
CL
886.Ic g
887with
888.Cx `
889.Ic \&.
890.Cx \'
891.Cx
892initially set to every line
893.Em except
fd315f2c
KM
894those
895matching the regular expression.
b5dc1377
CL
896(1, $)\w filename
897.Tp Cx \&(
898.Ic \&1
899.Cx \&,
900.Ic \&$
901.Cx \&)
902.Ic \&w
903.Cx \&\ \&
904.Ar filename
905.Cx
fd315f2c
KM
906The write command writes the addressed lines onto
907the given file.
908If the file does not exist,
909it is created.
b5dc1377 910The file name is remembered if there was no
fd315f2c
KM
911remembered file name already.
912If no file name is given,
913the remembered file name, if any, is used
914(see
b5dc1377 915.Ic e
fd315f2c 916and
b5dc1377
CL
917.Ic f
918commands).
919.Cx `
920.Ic \&.
921.Cx \'
922.Cx
923is unchanged.
fd315f2c
KM
924If the command is successful, the number of characters written is
925printed.
b5dc1377
CL
926.Tp Cx \&(
927.Ic \&1
928.Cx \&,
929.Ic \&$
930.Cx \&)
931.Ic \&W
932.Cx \&\ \&
933.Ar filename
934.Cx
fd315f2c 935This command is the same as
b5dc1377 936.Ic w ,
fd315f2c 937except that the addressed lines are appended to the file.
b5dc1377
CL
938.Tp Cx \&(
939.Ic \&1
940.Cx \&,
941.Ic \&$
942.Cx \&)
943.Ic \&wq
944.Cx \&\ \&
945.Ar filename
946.Cx
fd315f2c 947This command is the same as
b5dc1377 948.Ic w
fd315f2c 949except that afterwards a
b5dc1377 950.Ic q
fd315f2c
KM
951command is done,
952exiting the editor
953after the file is written.
b5dc1377
CL
954.Ic \&1
955.Ic \&+1
956.Cx \&)
957.Ic \&z
958.Cx \&\ \ \&or,
959.Cx
960.Tp Cx \&(
961.Ic \&1
962.Ic \&+1
963.Cx \&)
964.Ic \&z
965.Ar n
966.Cx
fd315f2c
KM
967This command scrolls through the buffer starting at the addressed line.
96822 (or
b5dc1377 969.Ar n ,
fd315f2c
KM
970if given)
971lines are printed.
972The last line printed becomes the current line.
973The value
b5dc1377 974.Ar n
fd315f2c
KM
975is sticky, in that it becomes the default for
976future
b5dc1377 977.Ic z
fd315f2c 978commands.
b5dc1377
CL
979.Tp Cx \&(
980.Ic \&$
981.Cx \&)
982.Ic \&=
983.Cx
fd315f2c 984The line number of the addressed line is typed.
b5dc1377
CL
985.Cx `
986.Ic \&.
987.Cx \'
988.Cx
989is unchanged by this command.
990.Tp Cx Ic \&!
991.Cx <shell\ command>
992.Cx
fd315f2c
KM
993The remainder of the line after the `!' is sent
994to
b5dc1377 995.Xr sh 1
fd315f2c 996to be interpreted as a command.
b5dc1377
CL
997.Cx `
998.Ic \&.
999.Cx \'
1000.Cx
fd315f2c 1001is unchanged.
b5dc1377
CL
1002.Tp Cx \&(
1003.Ic \&.+1
1004.Cx \&,
1005.Ic \&.+1
1006.Cx \&)
1007.Cx <newline>
1008.Cx
fd315f2c 1009An address alone on a line causes the addressed line to be printed.
b5dc1377
CL
1010A blank line alone is equivalent to
1011.Ic .+1
1012it is useful
fd315f2c
KM
1013for stepping through text.
1014If two addresses are present with no
1015intervening semicolon,
b5dc1377 1016.Nm ed
fd315f2c
KM
1017prints the range of lines.
1018If they are separated by a semicolon,
1019the second line is printed.
b5dc1377
CL
1020.Tp
1021.Pp
1022If an interrupt signal (ASCII DEL) is sent,
1023.Nm ed
1024prints
1025.Sq Li ?interrupted
fd315f2c 1026and returns to its command level.
b5dc1377 1027.Pp
fd315f2c
KM
1028Some size limitations:
1029512 characters per line,
1030256 characters per global command list,
103164 characters per file name,
1032and, on mini computers,
1033128K characters in the temporary file.
1034The limit on the number of lines depends on the amount of core:
1035each line takes 2 words.
b5dc1377 1036.Pp
fd315f2c 1037When reading a file,
b5dc1377 1038.Nm ed
fd315f2c
KM
1039discards ASCII NUL characters
1040and all characters after the last newline.
1041It refuses to read files containing non-ASCII characters.
b5dc1377
CL
1042.Sh FILES
1043.Dw edhup
1044.Di L
1045.Dp Pa /tmp/e*
1046.Dp Pa edhup
1047work is saved here if terminal hangs up
1048.Dp
1049.Sh SEE ALSO
1050.Xr ex 1 ,
1051.Xr sed 1 ,
1052.Xr crypt 1
fd315f2c 1053.br
fd315f2c 1054B. W. Kernighan,
b5dc1377 1055.Em A Tutorial Introduction to the ED Text Editor
fd315f2c
KM
1056.br
1057B. W. Kernighan,
b5dc1377
CL
1058.Em Ar Advanced editing on UNIX
1059.Sh HISTORY
1060The
1061.Nm ed
1062command appeared in Version 6 AT&T UNIX.
1063.Sh DIAGNOSTICS
1064.Sq Li name
1065for inaccessible file;
1066.Sq Li ?self-explanatory message
fd315f2c 1067for other errors.
b5dc1377 1068.Pp
fd315f2c
KM
1069To protect against throwing away valuable work,
1070a
b5dc1377 1071.Ic q
fd315f2c 1072or
b5dc1377 1073.Ic e
fd315f2c 1074command is considered to be in error, unless a
b5dc1377 1075.Ic w
fd315f2c
KM
1076has occurred since the last buffer change.
1077A second
b5dc1377 1078.Ic q
fd315f2c 1079or
b5dc1377 1080.Ic e
fd315f2c 1081will be obeyed regardless.
b5dc1377
CL
1082.Sh BUGS
1083The
1084.Ic l
1085command mishandles
1086.Li DEL .
fd315f2c
KM
1087.br
1088The
b5dc1377 1089.Ic undo
fd315f2c 1090command causes marks to be lost on affected lines.