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 characters as
447 and four hexadecimal digits.
448 Long lines are folded,
449 with the second and subsequent sub-lines indented one tab stop.
450 If the last character in the line is a blank,
455 may be appended, like
457 to any non-I/O command.
459 .RB (\|\fL.,.\fP\|) \|m\fIa
461 Reposition the addressed lines after the line
464 Dot is left at the last moved line.
466 .RB (\|\fL.,.\fP\|) \|n
470 prefixing each line with its line number and a tab.
473 may be appended, like
475 to any non-I/O command.
477 .RB (\|\fL.,.\fP\|) \|p
478 Print the addressed lines.
479 Dot is left at the last line printed.
482 appended to any non-I/O command causes the then current line
483 to be printed after the command is executed.
485 .RB (\|\fL.,.\fP\|) \|P
486 This command is a synonym for
497 command is considered to be in error if the buffer has
498 been modified since the last
506 Quit unconditionally.
508 .RB ( $ )\|r\ \fIfilename\fP
509 Read in the given file after the addressed line.
512 is given, the remembered file name is used.
513 The file name is remembered if there were no
514 remembered file name already.
515 If the read is successful, the number of characters
517 Dot is left at the last line read from the file.
519 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/
522 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g
524 .RB (\|\fL.,.\fP\|) \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP
527 Search each addressed
528 line for an occurrence of the specified regular expression.
529 On each line in which
533 defaults to 1 if missing),
536 matched string is replaced by the replacement specified.
537 If the global replacement indicator
539 appears after the command,
540 all subsequent matches on the line are also replaced.
541 It is an error for the substitution to fail on all addressed lines.
542 Any character other than space or newline
543 may be used instead of
545 to delimit the regular expression
547 Dot is left at the last line substituted.
549 .BI s n / regular\ expression / replacement\fP/p\f1.
552 may be omitted if the replacement is
557 appearing in the replacement
558 is replaced by the string matching the regular expression.
564 are replaced by the text matched by the
566 regular subexpression
572 nested parenthesized subexpressions
575 is determined by counting occurrences of
577 starting from the left.
583 or newline may be included in a replacement
587 .RB (\|\fL.,.\fP\|) \|t\|\fIa
589 Copy the addressed lines
590 after the line addressed by
592 Dot is left at the last line of the copy.
594 .RB (\|\fL.,.\fP\|) \|u
596 Restore the preceding contents
597 of the first addressed line (sic), which must be the last line
598 in which a substitution was made (double sic).
600 .RB (\|\fL1,$\fP\|) \|v/\fIregular\ expression\fP/\fIcommand\ list\fP
601 This command is the same as the global command
603 except that the command list is executed with
604 dot initially set to every line
607 matching the regular expression.
609 .RB (\|\fL1,$\fP\|) \|w " \fIfilename\fP"
610 Write the addressed lines to
612 If the file does not exist,
613 it is created with mode 666 (readable and writable by everyone).
616 is given, the remembered file name, if any, is used.
617 The file name is remembered if there were no
618 remembered file name already.
620 If the write is successful, the number of characters written is
623 .RB (\|\fL1,$\fP\|) \|W " \fIfilename\fP"
626 but append to, instead of overwriting, any existing file contents.
629 Print the line number of the addressed line.
633 Send the remainder of the line after the
637 to be interpreted as a command.
640 .RB (\| .+1 )\|<newline>
641 An address without a command is taken as a
646 may be omitted from the address.
647 A blank line alone is equivalent to
650 for stepping through text.
652 If an interrupt signal
658 and returns to its command level.
665 and all characters after the last newline.
670 \ \ work is saved here if terminal hangs up
679 for inaccessible file;
681 for temporary file overflow;
683 for errors in commands or other overflows.