17 is a venerable text editor.
25 command (see below) on that file:
28 buffer so that it can be edited.
33 of character counts by
38 commands and of the confirming
46 Write all output to the standard error file except writing by
53 the remembered file; see the
58 operates on a `buffer', a copy of the file it is editing;
60 in the buffer have no effect on the file until a
64 The copy of the text being edited resides
65 in a temporary file called the
70 have a simple and regular structure: zero, one, or
73 followed by a single character
76 followed by parameters to the command.
77 These addresses specify one or more lines in the buffer.
78 Missing addresses are supplied by default.
80 In general, only one command may appear on a line.
81 Certain commands allow the
82 addition of text to the buffer.
85 is accepting text, it is said
88 In this mode, no commands are recognized;
89 all input is merely collected.
90 Input mode is left by typing a period
97 .I "regular expression"
100 Regular expressions are used in addresses to specify
101 lines and in one command
105 to specify a portion of a line which is to be replaced.
106 If it is desired to use one of
107 the regular expression metacharacters as an ordinary
108 character, that character may be preceded by
110 This also applies to the character bounding the regular
117 To understand addressing in
119 it is necessary to know that at any time there is a
121 Generally, the current line is
122 the last line affected by a command; however,
123 the exact effect on the current line
124 is discussed under the description of
126 Addresses are constructed as follows.
131 customarily called `dot',
132 addresses the current line.
137 addresses the last line of the buffer.
148 addresses the line marked with the name
150 which must be a lower-case letter.
151 Lines are marked with the
156 A regular expression enclosed in slashes (
159 the line found by searching forward from the current line
160 and stopping at the first line containing a
161 string that matches the regular expression.
162 If necessary the search wraps around to the beginning of the
166 A regular expression enclosed in queries
169 the line found by searching backward from the current line
170 and stopping at the first line containing
171 a string that matches the regular expression.
173 the search wraps around to the end of the buffer.
176 An address followed by a plus sign
180 followed by a decimal number specifies that address plus
181 (resp. minus) the indicated number of lines.
182 The plus sign may be omitted.
185 An address followed by
190 regular expression enclosed in slashes specifies the first
191 matching line following (or preceding) that address.
192 The search wraps around if necessary.
199 line in the buffer with an
201 Enclosing the regular expression in
203 reverses the search direction.
206 If an address begins with
210 the addition or subtraction is taken with respect to the current line;
213 is understood to mean
217 If an address ends with
221 then 1 is added (resp. subtracted).
222 As a consequence of this rule and rule 9,
225 refers to the line before the current line.
232 have cumulative effect, so
234 refers to the current
238 To maintain compatibility with earlier versions of the editor,
245 Commands may require zero, one, or two addresses.
246 Commands which require no addresses regard the presence
247 of an address as an error.
248 Commands which accept one or two addresses
249 assume default addresses when insufficient are given.
250 If more addresses are given than a command requires,
251 the last one or two (depending on what is accepted) are used.
253 Addresses are separated from each other typically by a comma
255 They may also be separated by a semicolon
257 In this case the current line
259 the previous address before the next address is interpreted.
260 If no address precedes a comma or semicolon, line 1 is assumed;
261 if no address follows, the last line of the buffer is assumed.
262 The second address of any two-address sequence
263 must correspond to a line following the line corresponding to the first address.
265 In the following list of
267 commands, the default addresses
268 are shown in parentheses.
269 The parentheses are not part of
270 the address, but are used to show that the given addresses are
272 `Dot' means the current line.
274 .RB (\|\fL.\fP\|) \|a
284 and append it after the addressed line.
286 on the last line input, if there
287 were any, otherwise at the addressed line.
290 is legal for this command; text is placed
291 at the beginning of the buffer.
293 .RB (\|\fL.,.\fP\|) \|b [ +- ][\fIpagesize\fP][ pln\fR]
295 Print a `page', normally 20 lines.
300 specifies whether the next or previous
301 page is to be printed.
304 is the number of lines in a page.
310 causes printing in the specified format, initially
312 Pagesize and format are remembered between
315 Dot is left at the last line displayed.
317 .RB (\|\fL.,.\fP\|) \|c
327 Delete the addressed lines, then accept input
328 text to replace these lines.
329 Dot is left at the last line input; if there were none,
330 it is left at the line preceding the deleted lines.
332 .RB (\|\fL.,.\fP\|) \|d
333 Delete the addressed lines from the buffer.
334 Dot is set to the line following the last line deleted, or to
335 the last line of the buffer if the deleted lines had no successor.
339 Delete the entire contents of the buffer;
340 then read the named file into the buffer.
341 Dot is set to the last line of the buffer.
342 The number of characters read is typed.
343 The file name is remembered for possible use in later
351 is missing, the remembered name is used.
361 Print the currently remembered file name.
365 the currently remembered file name is first changed to
368 .RB (\|\fL1,$\fP\|) \|g/\fIregular\ expression\fP/\fIcommand\ list\fP
371 .RB (\|\fL1,$\fP\|) \|g/\fIregular\ expression\fP/
373 .RB (\|\fL1,$\fP\|) \|g/\fIregular\ expression\fP
376 First mark every line which matches
378 .IR regular expression .
379 Then for every such line, execute the
381 with dot initially set to that line.
382 A single command or the first of multiple commands
383 appears on the same line with the global command.
384 All lines of a multi-line list except the last line must end with
388 terminating input mode for an
392 command may be omitted if it would be on the
393 last line of the command list.
398 are not permitted in the command list.
399 Any character other than space or newline may
402 to delimit the regular expression.
403 The second and third forms mean
404 .BI g/ regular\ expression /p \f1.
412 Insert the given text before the addressed line.
413 Dot is left at the last line input, or, if there were none,
414 at the line before the addressed line.
415 This command differs from the
417 command only in the placement of the
421 .RB (\| .,.+1 \|) \|j
422 Join the addressed lines into a single line;
423 intermediate newlines are deleted.
424 Dot is left at the resulting line.
426 .RB (\|\fL.\fP\|) \|k\fIx\fP
427 Mark the addressed line with name
429 which must be a lower-case letter.
432 then addresses this line.
435 .RB (\|\fL.,.\fP\|) \|l
437 Print the addressed lines in an unambiguous way:
444 and non-printing ASCII characters as
447 and two hexadecimal digits.
448 non-ASCII characters in the Basic Multilingual Plane
449 are printed as a backslash, a small
451 and four hexadecimal digits; and characters above the
452 Basic Multilingual Plane are printed as a backslash,
455 and eight hexadecimal digits.
456 Long lines are folded,
457 with the second and subsequent sub-lines indented one tab stop.
458 If the last character in the line is a blank,
463 may be appended, like
465 to any non-I/O command.
467 .RB (\|\fL.,.\fP\|) \|m\fIa
469 Reposition the addressed lines after the line
472 Dot is left at the last moved line.
474 .RB (\|\fL.,.\fP\|) \|n
478 prefixing each line with its line number and a tab.
481 may be appended, like
483 to any non-I/O command.
485 .RB (\|\fL.,.\fP\|) \|p
486 Print the addressed lines.
487 Dot is left at the last line printed.
490 appended to any non-I/O command causes the then current line
491 to be printed after the command is executed.
493 .RB (\|\fL.,.\fP\|) \|P
494 This command is a synonym for
505 command is considered to be in error if the buffer has
506 been modified since the last
514 Quit unconditionally.
516 .RB ( $ )\|r\ \fIfilename\fP
517 Read in the given file after the addressed line.
520 is given, the remembered file name is used.
521 The file name is remembered if there were no
522 remembered file name already.
523 If the read is successful, the number of characters
525 Dot is left at the last line read from the file.
527 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/
530 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g
532 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP
535 Search each addressed
536 line for an occurrence of the specified regular expression.
537 On each line in which
541 defaults to 1 if missing),
544 matched string is replaced by the replacement specified.
545 If the global replacement indicator
547 appears after the command,
548 all subsequent matches on the line are also replaced.
549 It is an error for the substitution to fail on all addressed lines.
550 Any character other than space or newline
551 may be used instead of
553 to delimit the regular expression
555 Dot is left at the last line substituted.
557 .BI s n / regular\ expression / replacement\fP/p\f1.
560 may be omitted if the replacement is
565 appearing in the replacement
566 is replaced by the string matching the regular expression.
572 are replaced by the text matched by the
574 regular subexpression
580 nested parenthesized subexpressions
583 is determined by counting occurrences of
585 starting from the left.
591 or newline may be included in a replacement
595 .RB (\|\fL.,.\fP\|) \|t\|\fIa
597 Copy the addressed lines
598 after the line addressed by
600 Dot is left at the last line of the copy.
602 .RB (\|\fL.,.\fP\|) \|u
604 Restore the preceding contents
605 of the first addressed line (sic), which must be the last line
606 in which a substitution was made (double sic).
608 .RB (\|\fL1,$\fP\|) \|v/\fIregular\ expression\fP/\fIcommand\ list\fP
609 This command is the same as the global command
611 except that the command list is executed with
612 dot initially set to every line
615 matching the regular expression.
617 .RB (\|\fL1,$\fP\|) \|w " \fIfilename\fP"
618 Write the addressed lines to
620 If the file does not exist,
621 it is created with mode 666 (readable and writable by everyone).
624 is given, the remembered file name, if any, is used.
625 The file name is remembered if there were no
626 remembered file name already.
628 If the write is successful, the number of characters written is
631 .RB (\|\fL1,$\fP\|) \|W " \fIfilename\fP"
634 but append to, instead of overwriting, any existing file contents.
637 Print the line number of the addressed line.
641 Send the remainder of the line after the
645 to be interpreted as a command.
648 .RB (\| .+1 )\|<newline>
649 An address without a command is taken as a
654 may be omitted from the address.
655 A blank line alone is equivalent to
658 for stepping through text.
660 If an interrupt signal
666 and returns to its command level.
673 and all characters after the last newline.
678 \ \ work is saved here if terminal hangs up
687 for inaccessible file;
689 for temporary file overflow;
691 for errors in commands or other overflows.