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