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