xref: /minix/bin/ed/ed.1 (revision 83ee113e)
1.\"	$NetBSD: ed.1,v 1.30 2010/05/14 02:09:58 joerg Exp $
2.\"	$OpenBSD: ed.1,v 1.42 2003/07/27 13:25:43 jmc Exp $
3.\"
4.\" Copyright (c) 1993 Andrew Moore, Talke Studio.
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd January 23, 2002
29.Dt ED 1
30.Os
31.Sh NAME
32.Nm ed
33.Nd text editor
34.Sh SYNOPSIS
35.Nm
36.Op Fl
37.Op Fl Esx
38.Op Fl p Ar string
39.Op Ar file
40.Sh DESCRIPTION
41.Nm
42is a line-oriented text editor.
43It is used to create, display, modify, and otherwise manipulate text files.
44If invoked with a
45.Ar file
46argument, then a copy of
47.Ar file
48is read into the editor's buffer.
49Changes are made to this copy and not directly to
50.Ar file
51itself.
52Upon quitting
53.Nm ,
54any changes not explicitly saved with a
55.Ic w
56command are lost.
57.Pp
58Editing is done in two distinct modes:
59.Em command
60and
61.Em input .
62When first invoked,
63.Nm
64is in command mode.
65In this mode, commands are read from the standard input and
66executed to manipulate the contents of the editor buffer.
67.Pp
68A typical command might look like:
69.Bd -literal -offset indent
70,s/old/new/g
71.Ed
72.Pp
73which replaces all occurrences of the string
74.Pa old
75with
76.Pa new .
77.Pp
78When an input command, such as
79.Ic a
80(append),
81.Ic i
82(insert),
83or
84.Ic c
85(change) is given,
86.Nm
87enters input mode.
88This is the primary means of adding text to a file.
89In this mode, no commands are available;
90instead, the standard input is written directly to the editor buffer.
91Lines consist of text up to and including a newline character.
92Input mode is terminated by entering a single period
93.Pq Ql \&.
94on a line.
95.Pp
96All
97.Nm
98commands operate on whole lines or ranges of lines; e.g.,
99the
100.Ic d
101command deletes lines; the
102.Ic m
103command moves lines, and so on.
104It is possible to modify only a portion of a line by means of replacement,
105as in the example above.
106However, even here, the
107.Ic s
108command is applied to whole lines at a time.
109.Pp
110In general,
111.Nm
112commands consist of zero or more line addresses, followed by a single
113character command and possibly additional parameters; i.e.,
114commands have the structure:
115.Bd -literal -offset indent
116[address [,address]]command[parameters]
117.Ed
118.Pp
119The address(es) indicate the line or range of lines to be affected by the
120command.
121If fewer addresses are given than the command accepts, then
122default addresses are supplied.
123.Pp
124The options are as follows:
125.Bl -tag -width Ds
126.It Fl
127Same as the
128.Fl s
129option (deprecated).
130.It Fl E
131Enables the use of extended regular expressions instead of the basic
132regular expressions that are normally used.
133.It Fl p Ar string
134Specifies a command prompt.
135This may be toggled on and off with the
136.Ic P
137command.
138.It Fl s
139Suppress diagnostics.
140This should be used if
141.Nm
142standard input is from a script.
143.It Fl x
144Prompt for an encryption key to be used in subsequent reads and writes
145(see the
146.Ic x
147command).
148.It Ar file
149Specifies the name of a file to read.
150If
151.Ar file
152is prefixed with a
153bang
154.Pq Ql \&! ,
155then it is interpreted as a shell command.
156In this case, what is read is the standard output of
157.Ar file
158executed via
159.Xr sh 1 .
160To read a file whose name begins with a bang, prefix the
161name with a backslash
162.Pq Ql \e .
163The default filename is set to
164.Ar file
165only if it is not prefixed with a bang.
166.El
167.Ss LINE ADDRESSING
168An address represents the number of a line in the buffer.
169.Nm
170maintains a
171.Em current address
172which is typically supplied to commands as the default address
173when none is specified.
174When a file is first read, the current address is set to the last line
175of the file.
176In general, the current address is set to the last line affected by a command.
177.Pp
178A line address is
179constructed from one of the bases in the list below, optionally followed
180by a numeric offset.
181The offset may include any combination of digits, operators (i.e.,
182.Sq + ,
183.Sq - ,
184and
185.Sq ^ ) ,
186and whitespace.
187Addresses are read from left to right, and their values are computed
188relative to the current address.
189.Pp
190One exception to the rule that addresses represent line numbers is the
191address
192.Em 0
193(zero).
194This means
195.Dq before the first line ,
196and is legal wherever it makes sense.
197.Pp
198An address range is two addresses separated either by a comma or semi-colon.
199The value of the first address in a range cannot exceed the
200value of the second.
201If only one address is given in a range,
202then the second address is set to the given address.
203If an
204.Em n Ns No -tuple
205of addresses is given where
206.Em n \*[Gt] 2 ,
207then the corresponding range is determined by the last two addresses in the
208.Em n Ns No -tuple.
209If only one address is expected, then the last address is used.
210.Pp
211Each address in a comma-delimited range is interpreted relative to the
212current address.
213In a semi-colon-delimited range, the first address is
214used to set the current address, and the second address is interpreted
215relative to the first.
216.Pp
217The following address symbols are recognized:
218.Bl -tag -width Ds
219.It Em \&.
220The current line (address) in the buffer.
221.It Em $
222The last line in the buffer.
223.It Em n
224The
225.Em n Ns No th
226line in the buffer where
227.Em n
228is a number in the range
229.Em [0,$] .
230.It Em - No or Em ^
231The previous line.
232This is equivalent to
233.Em -1
234and may be repeated with cumulative effect.
235.It Em -n No or Em ^n
236The
237.Em n Ns No th
238previous line, where
239.Em n
240is a non-negative number.
241.It Em +
242The next line.
243This is equivalent to
244.Em +1
245and may be repeated with cumulative effect.
246.It Em +n
247The
248.Em n Ns No th
249next line, where
250.Em n
251is a non-negative number.
252.It Em whitespace Em n
253.Em whitespace
254followed by a number
255.Em n
256is interpreted as
257.Sq Em +n .
258.It Em \&, No or Em %
259The first through last lines in the buffer.
260This is equivalent to the address range
261.Em 1,$ .
262.It Em \&;
263The current through last lines in the buffer.
264This is equivalent to the address range
265.Em .,$ .
266.It Em / Ns Ar re Ns Em /
267The next line containing the regular expression
268.Ar re .
269The search wraps to the beginning of the buffer and continues down to the
270current line, if necessary.
271.Em //
272repeats the last search.
273.It Em \&? Ns Ar re Ns Em \&?
274The previous line containing the regular expression
275.Ar re .
276The search wraps to the end of the buffer and continues up to the
277current line, if necessary.
278.Em ??
279repeats the last search.
280.It Em \&\' Ns Ar lc
281The line previously marked by a
282.Ic k
283(mark) command, where
284.Ar lc
285is a lower case letter.
286.El
287.Ss REGULAR EXPRESSIONS
288Regular expressions are patterns used in selecting text.
289For example, the
290.Nm
291command
292.Bd -literal -offset indent
293g/string/
294.Ed
295.Pp
296prints all lines containing
297.Em string .
298Regular expressions are also used by the
299.Ic s
300command for selecting old text to be replaced with new.
301.Pp
302In addition to specifying string literals, regular expressions can
303represent classes of strings.
304Strings thus represented are said to be matched by the
305corresponding regular expression.
306If it is possible for a regular expression to match several strings in
307a line, then the leftmost longest match is the one selected.
308.Pp
309The following symbols are used in constructing regular expressions:
310.Bl -tag -width Dsasdfsd
311.It Em c
312Any character
313.Em c
314not listed below, including
315.Sq { ,
316.Sq } ,
317.Sq \&( ,
318.Sq \&) ,
319.Sq \*[Lt] ,
320and
321.Sq \*[Gt]
322matches itself.
323.It Em \ec
324Any backslash-escaped character
325.Em c ,
326except for
327.Sq { ,
328.Sq } ,
329.Sq \&( ,
330.Sq \&) ,
331.Sq \*[Lt] ,
332and
333.Sq \*[Gt]
334matches itself.
335.It Em \&.
336Matches any single character.
337.It Em [char-class]
338Matches any single character in the character class
339.Em char-class .
340See
341.Sx CHARACTER CLASSES
342below for further information.
343.It Em [^char-class]
344Matches any single character, other than newline, not in the
345character class
346.Em char-class .
347.It Em ^
348If
349.Em ^
350is the first character of a regular expression, then it
351anchors the regular expression to the beginning of a line.
352Otherwise, it matches itself.
353.It Em $
354If
355.Em $
356is the last character of a regular expression,
357it anchors the regular expression to the end of a line.
358Otherwise, it matches itself.
359.It Em \e\*[Lt]
360Anchors the single character regular expression or subexpression
361immediately following it to the beginning of a word.
362(This may not be available.)
363.It Em \e\*[Gt]
364Anchors the single character regular expression or subexpression
365immediately following it to the end of a word.
366(This may not be available.)
367.It Em \e( Ns Ar re Ns Em \e)
368Defines a subexpression
369.Ar re .
370Subexpressions may be nested.
371A subsequent backreference of the form
372.Em \en ,
373where
374.Em n
375is a number in the range [1,9], expands to the text matched by the
376.Em n Ns No th
377subexpression.
378For example, the regular expression
379.Em \e(.*\e)\e1
380matches any string consisting of identical adjacent substrings.
381Subexpressions are ordered relative to their left delimiter.
382.It Em *
383Matches the single character regular expression or subexpression
384immediately preceding it zero or more times.
385If
386.Em *
387is the first character of a regular expression or subexpression,
388then it matches itself.
389The
390.Em *
391operator sometimes yields unexpected results.
392For example, the regular expression
393.Em b*
394matches the beginning of the string
395.Em abbb
396(as opposed to the substring
397.Em bbb ) ,
398since a null match is the only leftmost match.
399.Sm off
400.It Em \e{ No n,m Em \e}\ \e{ No n, Em \e}\ \& Em \e{ No n Em \e}
401.Sm on
402Matches the single character regular expression or subexpression
403immediately preceding it at least
404.Em n
405and at most
406.Em m
407times.
408If
409.Em m
410is omitted, then it matches at least
411.Em n
412times.
413If the comma is also omitted, then it matches exactly
414.Em n
415times.
416.El
417.Pp
418Additional regular expression operators may be defined depending on the
419particular
420.Xr regex 3
421implementation.
422.Ss CHARACTER CLASSES
423A character class specifies a set of characters. It is written within
424square brackets
425.Pq []
426and in its most basic form contains just the characters in the set.
427.Pp
428To include a
429.Sq \&]
430in a character class, it must be the first character.
431A range of characters may be specified by separating the end characters
432of the range with a
433.Sq \&- ,
434e.g.,
435.Sq a-z
436specifies the lower case characters.
437.Pp
438The following literals can also be used within character classes as
439shorthand for particular sets of characters:
440.Bl -tag -offset indent -compact -width [:blahblah:]
441.It [:alnum:]
442Alphanumeric characters.
443.It [:cntrl:]
444Control characters.
445.It [:lower:]
446Lowercase alphabetic characters.
447.It [:space:]
448Whitespace (space, tab, newline, form feed, etc.)
449.It [:alpha:]
450Alphabetic characters.
451.It [:digit:]
452Numeric characters (digits).
453.It [:print:]
454Printable characters.
455.It [:upper:]
456Uppercase alphabetic characters.
457.It [:blank:]
458Blank characters (space and tab).
459.It [:graph:]
460Graphical characters (printing nonblank characters).
461.It [:punct:]
462Punctuation characters.
463.It [:xdigit:]
464Hexadecimal digits.
465.El
466If
467.Sq \&-
468appears as the first or last character of a character class, then
469it matches itself.
470All other characters in a character class match themselves.
471.Pp
472Patterns in
473a character class
474of the form
475.Em [.col-elm.]
476or
477.Em [=col-elm=]
478where
479.Em col-elm
480is a
481.Em collating element
482are interpreted according to
483.Xr locale 5
484(not currently supported).
485See
486.Xr regex 3
487for an explanation of these constructs.
488.Ss COMMANDS
489All
490.Nm
491commands are single characters, though some require additional parameters.
492If a command's parameters extend over several lines, then
493each line except for the last must be terminated with a backslash
494.Pq Ql \e .
495.Pp
496In general, at most one command is allowed per line.
497However, most commands accept a print suffix, which is any of
498.Ic p
499(print),
500.Ic l
501(list),
502or
503.Ic n
504(enumerate), to print the last line affected by the command.
505.Pp
506An interrupt (typically ^C) has the effect of aborting the current command
507and returning the editor to command mode.
508.Pp
509.Nm
510recognizes the following commands.
511The commands are shown together with
512the default address or address range supplied if none is
513specified (in parentheses), and other possible arguments on the right.
514.Bl -tag -width Dxxs
515.It (.) Ns Ic a
516Appends text to the buffer after the addressed line.
517Text is entered in input mode.
518The current address is set to last line entered.
519.It (.,.) Ns Ic c
520Changes lines in the buffer.
521The addressed lines are deleted from the buffer,
522and text is appended in their place.
523Text is entered in input mode.
524The current address is set to last line entered.
525.It (.,.) Ns Ic d
526Deletes the addressed lines from the buffer.
527If there is a line after the deleted range, then the current address is set
528to this line.
529Otherwise the current address is set to the line before the deleted range.
530.It Ic e Ar file
531Edits
532.Ar file ,
533and sets the default filename.
534If
535.Ar file
536is not specified, then the default filename is used.
537Any lines in the buffer are deleted before the new file is read.
538The current address is set to the last line read.
539.It Ic e Ar !command
540Edits the standard output of
541.Ar command ,
542(see
543.Ic \&! Ar command
544below).
545The default filename is unchanged.
546Any lines in the buffer are deleted before the output of
547.Em command
548is read.
549The current address is set to the last line read.
550.It Ic E Ar file
551Edits
552.Ar file
553unconditionally.
554This is similar to the
555.Ic e
556command, except that unwritten changes are discarded without warning.
557The current address is set to the last line read.
558.It Ic f Ar file
559Sets the default filename to
560.Ar file .
561If
562.Ar file
563is not specified, then the default unescaped filename is printed.
564.It (1,$) Ns Ic g Ns Ar /re/command-list
565Applies
566.Ar command-list
567to each of the addressed lines matching a regular expression
568.Ar re .
569The current address is set to the line currently matched before
570.Ar command-list
571is executed.
572At the end of the
573.Ic g
574command, the current address is set to the last line affected by
575.Ar command-list .
576.Pp
577Each command in
578.Ar command-list
579must be on a separate line,
580and every line except for the last must be terminated by a backslash
581.Pq Sq \e .
582Any commands are allowed, except for
583.Ic g ,
584.Ic G ,
585.Ic v ,
586and
587.Ic V .
588A newline alone in
589.Ar command-list
590is equivalent to a
591.Ic p
592command.
593.It (1,$) Ns Ic G Ns Ar /re/
594Interactively edits the addressed lines matching a regular expression
595.Ar re .
596For each matching line, the line is printed, the current address is set,
597and the user is prompted to enter a
598.Ar command-list .
599At the end of the
600.Ic G
601command, the current address is set to the last line affected by (the last)
602.Ar command-list .
603.Pp
604The format of
605.Ar command-list
606is the same as that of the
607.Ic g
608command.
609A newline alone acts as a null command list.
610A single
611.Sq \*[Am]
612repeats the last non-null command list.
613.It Ic H
614Toggles the printing of error explanations.
615By default, explanations are not printed.
616It is recommended that
617.Nm
618scripts begin with this command to aid in debugging.
619.It Ic h
620Prints an explanation of the last error.
621.It (.) Ns Ic i
622Inserts text in the buffer before the current line.
623Text is entered in input mode.
624The current address is set to the last line entered.
625.It (.,.+1) Ns Ic j
626Joins the addressed lines.
627The addressed lines are deleted from the buffer and replaced by a single
628line containing their joined text.
629The current address is set to the resultant line.
630.It (.) Ns Ic k Ns Ar lc
631Marks a line with a lower case letter
632.Ar lc .
633The line can then be addressed as
634.Ar \&'lc
635(i.e., a single quote followed by
636.Ar lc )
637in subsequent commands.
638The mark is not cleared until the line is deleted or otherwise modified.
639.It (.,.) Ns Ic l
640Prints the addressed lines unambiguously.
641If a single line fills more than one screen (as might be the case
642when viewing a binary file, for instance), a
643.Dq --More--
644prompt is printed on the last line.
645.Nm
646waits until the RETURN key is pressed before displaying the next screen.
647The current address is set to the last line printed.
648.It (.,.) Ns Ic m Ns No (.)
649Moves lines in the buffer.
650The addressed lines are moved to after the
651right-hand destination address, which may be the address
652.Em 0
653(zero).
654The current address is set to the last line moved.
655.It (.,.) Ns Ic n
656Prints the addressed lines along with their line numbers.
657The current address is set to the last line printed.
658.It (.,.) Ns Ic p
659Prints the addressed lines.
660The current address is set to the last line printed.
661.It Ic P
662Toggles the command prompt on and off.
663Unless a prompt was specified with the command-line option
664.Fl p Ar string ,
665the command prompt is by default turned off.
666.It Ic q
667Quits
668.Nm .
669.It Ic Q
670Quits
671.Nm
672unconditionally.
673This is similar to the
674.Ic q
675command, except that unwritten changes are discarded without warning.
676.It ($) Ns Ic r Ar file
677Reads
678.Ar file
679to after the addressed line.
680If
681.Ar file
682is not specified, then the default filename is used.
683If there was no default filename prior to the command,
684then the default filename is set to
685.Ar file .
686Otherwise, the default filename is unchanged.
687The current address is set to the last line read.
688.It ($) Ns Ic r Ar !command
689Reads to after the addressed line the standard output of
690.Ar command ,
691(see the
692.Ic \&!
693command below).
694The default filename is unchanged.
695The current address is set to the last line read.
696.Sm off
697.It (.,.) Ic s Ar /re/replacement/ , \ (.,.) \
698Ic s Ar /re/replacement/ Em g , Ar \ (.,.) \
699Ic s Ar /re/replacement/ Em n
700.Sm on
701Replaces text in the addressed lines matching a regular expression
702.Ar re
703with
704.Ar replacement .
705By default, only the first match in each line is replaced.
706If the
707.Em g
708(global) suffix is given, then every match to be replaced.
709The
710.Em n
711suffix, where
712.Em n
713is a positive number, causes only the
714.Em n Ns No th
715match to be replaced.
716It is an error if no substitutions are performed on any of the addressed
717lines.
718The current address is set the last line affected.
719.Pp
720.Ar re
721and
722.Ar replacement
723may be delimited by any character other than space and newline
724(see the
725.Ic s
726command below).
727If one or two of the last delimiters is omitted, then the last line
728affected is printed as though the print suffix
729.Em p
730were specified.
731.Pp
732An unescaped
733.Ql \*[Am]
734in
735.Ar replacement
736is replaced by the currently matched text.
737The character sequence
738.Em \em ,
739where
740.Em m
741is a number in the range [1,9], is replaced by the
742.Em m Ns No th
743backreference expression of the matched text.
744If
745.Ar replacement
746consists of a single
747.Ql % ,
748then
749.Ar replacement
750from the last substitution is used.
751Newlines may be embedded in
752.Ar replacement
753if they are escaped with a backslash
754.Pq Ql \e .
755.It (.,.) Ns Ic s
756Repeats the last substitution.
757This form of the
758.Ic s
759command accepts a count suffix
760.Em n ,
761or any combination of the characters
762.Em r ,
763.Em g ,
764and
765.Em p .
766If a count suffix
767.Em n
768is given, then only the
769.Em n Ns No th
770match is replaced.
771The
772.Em r
773suffix causes
774the regular expression of the last search to be used instead of
775that of the last substitution.
776The
777.Em g
778suffix toggles the global suffix of the last substitution.
779The
780.Em p
781suffix toggles the print suffix of the last substitution.
782The current address is set to the last line affected.
783.It (.,.) Ns Ic t Ns No (.)
784Copies (i.e., transfers) the addressed lines to after the right-hand
785destination address, which may be the address
786.Em 0
787(zero).
788The current address is set to the last line copied.
789.It Ic u
790Undoes the last command and restores the current address
791to what it was before the command.
792The global commands
793.Ic g ,
794.Ic G ,
795.Ic v ,
796and
797.Ic V
798are treated as a single command by undo.
799.Ic u
800is its own inverse.
801.It (1,$) Ns Ic v Ns Ar /re/command-list
802Applies
803.Ar command-list
804to each of the addressed lines not matching a regular expression
805.Ar re .
806This is similar to the
807.Ic g
808command.
809.It (1,$) Ns Ic V Ns Ar /re/
810Interactively edits the addressed lines not matching a regular expression
811.Ar re .
812This is similar to the
813.Ic G
814command.
815.It (1,$) Ns Ic w Ar file
816Writes the addressed lines to
817.Ar file .
818Any previous contents of
819.Ar file
820are lost without warning.
821If there is no default filename, then the default filename is set to
822.Ar file ,
823otherwise it is unchanged.
824If no filename is specified, then the default filename is used.
825The current address is unchanged.
826.It (1,$) Ns Ic wq Ar file
827Writes the addressed lines to
828.Ar file ,
829and then executes a
830.Ic q
831command.
832.It (1,$) Ns Ic w Ar !command
833Writes the addressed lines to the standard input of
834.Ar command ,
835(see the
836.Ic \&!
837command below).
838The default filename and current address are unchanged.
839.It (1,$) Ns Ic W Ar file
840Appends the addressed lines to the end of
841.Ar file .
842This is similar to the
843.Ic w
844command, except that the previous contents of file are not clobbered.
845The current address is unchanged.
846.It Ic x
847Prompts for an encryption key which is used in subsequent reads and writes.
848If a newline alone is entered as the key, then encryption is turned off.
849Otherwise, echoing is disabled while a key is read.
850Encryption/decryption is done using the
851.Xr bdes 1
852algorithm.
853.It (.+1) Ns Ic z Ns Ar n
854Scrolls
855.Ar n
856lines at a time starting at addressed line.
857If
858.Ar n
859is not specified, then the current window size is used.
860The current address is set to the last line printed.
861.It ($) Ns Ic =
862Prints the line number of the addressed line.
863.It (.+1) Ns Ic newline
864Prints the addressed line, and sets the current address to that line.
865.It Ic \&! Ns Ar command
866Executes
867.Ar command
868via
869.Xr sh 1 .
870If the first character of
871.Ar command
872is
873.Ic \&! ,
874then it is replaced by text of the previous
875.Ic !command .
876.Nm
877does not process
878.Ar command
879for
880.Sq \e
881(backslash) escapes.
882However, an unescaped
883.Sq %
884is replaced by the default filename.
885When the shell returns from execution, a
886.Sq \&!
887is printed to the standard output.
888The current line is unchanged.
889.El
890.Sh LIMITATIONS
891.Nm
892processes
893.Em file
894arguments for backslash escapes, i.e., in a filename,
895any characters preceded by a backslash
896.Pq Ql \e
897are interpreted literally.
898.Pp
899If a text (non-binary) file is not terminated by a newline character,
900then
901.Nm
902appends one on reading/writing it.
903In the case of a binary file,
904.Nm
905does not append a newline on reading/writing.
906.Sh ENVIRONMENT
907.Bl -tag -width iTMPDIR
908.It Ev TMPDIR
909The location used to store temporary files.
910.El
911.Sh FILES
912.Bl -tag -width /tmp/ed.* -compact
913.It Pa /tmp/ed.*
914buffer file
915.It Pa ed.hup
916where
917.Nm
918attempts to write the buffer if the terminal hangs up
919.El
920.Sh DIAGNOSTICS
921When an error occurs,
922.Nm
923prints a
924.Dq \&?
925and either returns to command mode or exits if its input is from a script.
926An explanation of the last error can be printed with the
927.Ic h
928(help) command.
929.Pp
930Since the
931.Ic g
932(global) command masks any errors from failed searches and substitutions,
933it can be used to perform conditional operations in scripts; e.g.,
934.Bd -literal -offset indent
935g/old/s//new/
936.Ed
937.Pp
938replaces any occurrences of
939.Em old
940with
941.Em new .
942.Pp
943If the
944.Ic u
945(undo) command occurs in a global command list, then
946the command list is executed only once.
947.Pp
948If diagnostics are not disabled, attempting to quit
949.Nm
950or edit another file before writing a modified buffer results in an error.
951If the command is entered a second time, it succeeds,
952but any changes to the buffer are lost.
953.Sh SEE ALSO
954.Xr bdes 1 ,
955.Xr sed 1 ,
956.Xr sh 1 ,
957.Xr vi 1 ,
958.Xr regex 3
959.Pp
960USD:09-10
961.Rs
962.%A B. W. Kernighan
963.%A P. J. Plauger
964.%B Software Tools in Pascal
965.%I Addison-Wesley
966.%D 1981
967.Re
968.Sh HISTORY
969An
970.Nm
971command appeared in
972.At v1 .
973