Annotation of lucent/sys/man/1/ed, revision 1.1.1.1

1.1       root        1: .TH ED 1
                      2: .ds . (\|\fL.\fP\|)
                      3: .ds .. (\|\fL.,.\fP\|)
                      4: .ds 1$ (\|\fL1,$\fP\|)
                      5: .SH NAME
                      6: ed \- text editor
                      7: .SH SYNOPSIS
                      8: .B ed
                      9: [
                     10: .B -
                     11: ]
                     12: [
                     13: .B -o
                     14: ]
                     15: [
                     16: .I file
                     17: ]
                     18: .SH DESCRIPTION
                     19: .I Ed
                     20: is a venerable text editor.
                     21: .PP
                     22: If a
                     23: .I file
                     24: argument is given,
                     25: .I ed
                     26: simulates an
                     27: .L e
                     28: command (see below) on that file:
                     29: it is read into
                     30: .I ed's
                     31: buffer so that it can be edited.
                     32: The options are
                     33: .TP
                     34: .B -
                     35: Suppress the printing
                     36: of character counts by
                     37: .LR e ,
                     38: .LR r ,
                     39: and
                     40: .L w
                     41: commands and of the confirming 
                     42: .L !
                     43: by
                     44: .L !
                     45: commands.
                     46: .TP
                     47: .B -o
                     48: (for output piping)
                     49: Write all output to the standard error file except writing by
                     50: .L w
                     51: commands.
                     52: If no 
                     53: .I file
                     54: is given, make
                     55: .B /fd/1
                     56: the remembered file; see the
                     57: .L e
                     58: command below.
                     59: .PP
                     60: .I Ed
                     61: operates on a `buffer', a copy of the file it is editing;
                     62: changes made
                     63: in the buffer have no effect on the file until a
                     64: .L w
                     65: (write)
                     66: command is given.
                     67: The copy of the text being edited resides
                     68: in a temporary file called the 
                     69: .IR buffer .
                     70: .PP
                     71: Commands to
                     72: .I ed
                     73: have a simple and regular structure: zero, one, or
                     74: two
                     75: .I addresses
                     76: followed by a single character
                     77: .IR command ,
                     78: possibly
                     79: followed by parameters to the command.
                     80: These addresses specify one or more lines in the buffer.
                     81: Missing addresses are supplied by default.
                     82: .PP
                     83: In general, only one command may appear on a line.
                     84: Certain commands allow the 
                     85: addition of text to the buffer.
                     86: While
                     87: .I ed
                     88: is accepting text, it is said
                     89: to be in
                     90: .I  "input mode."
                     91: In this mode, no commands are recognized;
                     92: all input is merely collected.
                     93: Input mode is left by typing a period 
                     94: .L .
                     95: alone at the
                     96: beginning of a line.
                     97: .PP
                     98: .I Ed
                     99: supports the 
                    100: .I "regular expression"
                    101: notation described in
                    102: .IR regexp (6).
                    103: Regular expressions are used in addresses to specify
                    104: lines and in one command
                    105: (see
                    106: .I s
                    107: below)
                    108: to specify a portion of a line which is to be replaced.
                    109: If it is desired to use one of
                    110: the regular expression metacharacters as an ordinary
                    111: character, that character may be preceded by
                    112: .RB ` \e '.
                    113: This also applies to the character bounding the regular
                    114: expression (often 
                    115: .LR / )
                    116: and to
                    117: .L \e
                    118: itself.
                    119: .PP
                    120: To understand addressing in
                    121: .I ed
                    122: it is necessary to know that at any time there is a
                    123: .I "current line."
                    124: Generally, the current line is
                    125: the last line affected by a command; however,
                    126: the exact effect on the current line
                    127: is discussed under the description of
                    128: each command.
                    129: Addresses are constructed as follows.
                    130: .TP
                    131: 1.
                    132: The character
                    133: .LR . ,
                    134: customarily called `dot',
                    135: addresses the current line.
                    136: .TP
                    137: 2.
                    138: The character 
                    139: .L $
                    140: addresses the last line of the buffer.
                    141: .TP
                    142: 3.
                    143: A decimal number
                    144: .I n
                    145: addresses the
                    146: .IR n -th
                    147: line of the buffer.
                    148: .TP
                    149: 4.
                    150: .BI \'x
                    151: addresses the line marked with the name
                    152: .IR x ,
                    153: which must be a lower-case letter.
                    154: Lines are marked with the
                    155: .L k
                    156: command.
                    157: .TP
                    158: 5.
                    159: A regular expression enclosed in slashes (
                    160: .LR / )
                    161: addresses
                    162: the line found by searching forward from the current line
                    163: and stopping at the first line containing a
                    164: string that matches the regular expression.
                    165: If necessary the search wraps around to the beginning of the
                    166: buffer.
                    167: .TP
                    168: 6.
                    169: A regular expression enclosed in queries 
                    170: .L ?
                    171: addresses
                    172: the line found by searching backward from the current line
                    173: and stopping at the first line containing
                    174: a string that matches the regular expression.
                    175: If necessary
                    176: the search wraps around to the end of the buffer.
                    177: .TP
                    178: 7.
                    179: An address followed by a plus sign 
                    180: .L +
                    181: or a minus sign
                    182: .L -
                    183: followed by a decimal number specifies that address plus
                    184: (resp. minus) the indicated number of lines.
                    185: The plus sign may be omitted.
                    186: .TP
                    187: 8.
                    188: An address followed by 
                    189: .L +
                    190: (or
                    191: .LR - )
                    192: followed by a
                    193: regular expression enclosed in slashes specifies the first
                    194: matching line following (or preceding) that address.
                    195: The search wraps around if necessary.
                    196: The 
                    197: .L +
                    198: may be omitted, so
                    199: .L 0/x/
                    200: addresses the
                    201: .I first
                    202: line in the buffer with an 
                    203: .LR x .
                    204: Enclosing the regular expression in 
                    205: .L ?
                    206: reverses the search direction.
                    207: .TP
                    208: 9.
                    209: If an address begins with 
                    210: .L +
                    211: or
                    212: .L -
                    213: the addition or subtraction is taken with respect to the current line;
                    214: e.g.\&
                    215: .L -5
                    216: is understood to mean
                    217: .LR .-5 .
                    218: .TP
                    219: 10.
                    220: If an address ends with 
                    221: .L +
                    222: or
                    223: .LR - ,
                    224: then 1 is added (resp. subtracted).
                    225: As a consequence of this rule and rule 9,
                    226: the address
                    227: .L -
                    228: refers to the line before the current line.
                    229: Moreover,
                    230: trailing
                    231: .L +
                    232: and
                    233: .L -
                    234: characters
                    235: have cumulative effect, so
                    236: .L --
                    237: refers to the current
                    238: line less 2.
                    239: .TP
                    240: 11.
                    241: To maintain compatibility with earlier versions of the editor,
                    242: the character 
                    243: .L ^
                    244: in addresses is 
                    245: equivalent to
                    246: .LR - .
                    247: .PP
                    248: Commands may require zero, one, or two addresses.
                    249: Commands which require no addresses regard the presence
                    250: of an address as an error.
                    251: Commands which accept one or two addresses
                    252: assume default addresses when insufficient are given.
                    253: If more addresses are given than a command requires,
                    254: the last one or two (depending on what is accepted) are used.
                    255: .PP
                    256: Addresses are separated from each other typically by a comma
                    257: .LR , .
                    258: They may also be separated by a semicolon
                    259: .LR ; .
                    260: In this case the current line 
                    261: is set to
                    262: the previous address before the next address is interpreted.
                    263: If no address precedes a comma or semicolon, line 1 is assumed;
                    264: if no address follows, the last line of the buffer is assumed.
                    265: The second address of any two-address sequence
                    266: must correspond to a line following the line corresponding to the first address.
                    267: .PP
                    268: In the following list of
                    269: .I ed
                    270: commands, the default addresses
                    271: are shown in parentheses.
                    272: The parentheses are not part of
                    273: the address, but are used to show that the given addresses are
                    274: the default.
                    275: `Dot' means the current line.
                    276: .TP
                    277: .RB \*. \|a
                    278: .br
                    279: .ns
                    280: .TP
                    281: <text>
                    282: .br
                    283: .ns
                    284: .TP
                    285: .B .
                    286: Read the given text
                    287: and append it after the addressed line.
                    288: Dot is left
                    289: on the last line input, if there
                    290: were any, otherwise at the addressed line.
                    291: Address 
                    292: .L 0
                    293: is legal for this command; text is placed
                    294: at the beginning of the buffer.
                    295: .TP
                    296: .RB \*(.. \|b [ +- ][\fIpagesize\fP][ pln\fR]
                    297: Browse.
                    298: Print a `page', normally 20 lines.
                    299: The optional 
                    300: .L +
                    301: (default) or
                    302: .L -
                    303: specifies whether the next or previous
                    304: page is to be printed.
                    305: The optional
                    306: .I pagesize
                    307: is the number of lines in a page.
                    308: The optional
                    309: .LR p ,
                    310: .LR n ,
                    311: or 
                    312: .L l
                    313: causes printing in the specified format, initially
                    314: .LR p .
                    315: Pagesize and format are remembered between 
                    316: .L b
                    317: commands.
                    318: Dot is left at the last line displayed.
                    319: .TP
                    320: .RB \*(.. \|c
                    321: .br
                    322: .ns
                    323: .TP
                    324: <text>
                    325: .br
                    326: .ns
                    327: .TP
                    328: .B .
                    329: Change.
                    330: Delete the addressed lines, then accept input
                    331: text to replace these lines.
                    332: Dot is left at the last line input; if there were none,
                    333: it is left at the line preceding the deleted lines.
                    334: .TP
                    335: .RB \*(.. \|d
                    336: Delete the addressed lines from the buffer.
                    337: Dot is set to the line following the last line deleted, or to
                    338: the last line of the buffer if the deleted lines had no successor.
                    339: .TP
                    340: .BI e " filename"
                    341: Edit.
                    342: Delete the entire contents of the buffer;
                    343: then read the named file into the buffer.
                    344: Dot is set to the last line of the buffer.
                    345: The number of characters read is typed.
                    346: The file name is remembered for possible use in later
                    347: .LR e ,
                    348: .LR r ,
                    349: or
                    350: .L w
                    351: commands.
                    352: If
                    353: .I filename
                    354: is missing, the remembered name is used.
                    355: .TP
                    356: .BI E " filename"
                    357: Unconditional
                    358: .LR e ;
                    359: see
                    360: .RL ` q '
                    361: below.
                    362: .TP
                    363: .BI f " filename"
                    364: Print the currently remembered file name.
                    365: If
                    366: .I filename
                    367: is given,
                    368: the currently remembered file name is first changed to
                    369: .IR filename .
                    370: .TP
                    371: .RB \*(1$ \|g/\fIregular\ expression\fP/\fIcommand\ list\fP
                    372: .PD 0
                    373: .TP
                    374: .RB \*(1$ \|g/\fIregular\ expression\fP/
                    375: .TP
                    376: .RB \*(1$ \|g/\fIregular\ expression\fP
                    377: .PD
                    378: Global.
                    379: First mark every line which matches
                    380: the given
                    381: .I regular expression\f1.
                    382: Then for every such line, execute the
                    383: .I command list
                    384: with dot initially set to that line.
                    385: A single command or the first of multiple commands
                    386: appears on the same line with the global command.
                    387: All lines of a multi-line list except the last line must end with
                    388: .LR \e .
                    389: The
                    390: .RB \&` \&. \&'
                    391: terminating input mode for an
                    392: .LR a ,
                    393: .LR i ,
                    394: .L c
                    395: command may be omitted if it would be on the
                    396: last line of the command list.
                    397: The commands
                    398: .L g
                    399: and
                    400: .L v
                    401: are not permitted in the command list.
                    402: Any character other than space or newline may
                    403: be used instead of 
                    404: .L /
                    405: to delimit the regular expression.
                    406: The second and third forms mean
                    407: .BI g/ regular\ expression /p \f1.
                    408: .TP
                    409: .RB (\| .\| ) \|i
                    410: .PD 0
                    411: .TP
                    412: <text>
                    413: .TP
                    414: .B .
                    415: Insert the given text before the addressed line.
                    416: Dot is left at the last line input, or, if there were none,
                    417: at the line before the addressed line.
                    418: This command differs from the
                    419: .I a
                    420: command only in the placement of the
                    421: text.
                    422: .PD
                    423: .TP
                    424: .RB (\| .,.+1 \|) \|j
                    425: Join the addressed lines into a single line;
                    426: intermediate newlines are deleted.
                    427: Dot is left at the resulting line.
                    428: .TP
                    429: .RB \*. \|k\fIx\fP
                    430: Mark the addressed line with name
                    431: .IR x ,
                    432: which must be a lower-case letter.
                    433: The address form
                    434: .BI \' x
                    435: then addresses this line.
                    436: .ne 2.5
                    437: .TP
                    438: .RB \*(.. \|l
                    439: List.
                    440: Print the addressed lines in an unambiguous way:
                    441: a tab is printed as
                    442: .LR \et ,
                    443: a backspace as
                    444: .LR \eb ,
                    445: backslashes as
                    446: .LR \e\e ,
                    447: and non-printing characters as
                    448: a backslash, an
                    449: .LR x ,
                    450: and four hexadecimal digits.
                    451: Long lines are folded,
                    452: with the second and subsequent sub-lines indented one tab stop.
                    453: If the last character in the line is a blank,
                    454: it is followed by
                    455: .LR \en .
                    456: An
                    457: .L l
                    458: may be appended, like
                    459: .LR p ,
                    460: to any non-I/O command.
                    461: .TP
                    462: .RB \*(.. \|m\fIa
                    463: Move.
                    464: Reposition the addressed lines after the line
                    465: addressed by
                    466: .IR a .
                    467: Dot is left at the last moved line.
                    468: .TP
                    469: .RB \*(.. \|n
                    470: Number.
                    471: Perform
                    472: .LR p ,
                    473: prefixing each line with its line number and a tab.
                    474: An
                    475: .L n
                    476: may be appended, like
                    477: .LR p ,
                    478: to any non-I/O command.
                    479: .TP
                    480: .RB \*(.. \|p
                    481: Print the addressed lines.
                    482: Dot is left at the last line printed.
                    483: A
                    484: .L p
                    485: appended to any non-I/O command causes the then current line
                    486: to be printed after the command is executed.
                    487: .TP
                    488: .RB \*(.. \|P
                    489: This command is a synonym for
                    490: .LR p .
                    491: .TP
                    492: .B q
                    493: Quit the editor.
                    494: No automatic write
                    495: of a file is done.
                    496: A
                    497: .L q
                    498: or
                    499: .L e
                    500: command is considered to be in error if the buffer has
                    501: been modified since the last
                    502: .LR w ,
                    503: .LR q ,
                    504: or
                    505: .L e
                    506: command.
                    507: .TP
                    508: .B Q
                    509: Quit unconditionally.
                    510: .TP
                    511: .RB ( $ )\|r\ \fIfilename\fP
                    512: Read in the given file after the addressed line.
                    513: If no
                    514: .I filename
                    515: is given, the remembered file name is used.
                    516: The file name is remembered if there were no
                    517: remembered file name already.
                    518: If the read is successful, the number of characters
                    519: read is printed.
                    520: Dot is left at the last line read from the file.
                    521: .TP
                    522: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/
                    523: .PD 0
                    524: .TP
                    525: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP/g
                    526: .TP
                    527: .RB \*(.. \|s\fIn\fP/\fIregular\ expression\fP/\fIreplacement\fP
                    528: .PD
                    529: Substitute.
                    530: Search each addressed
                    531: line for an occurrence of the specified regular expression.
                    532: On each line in which
                    533: .I n
                    534: matches are found
                    535: .RI ( n
                    536: defaults to 1 if missing),
                    537: the
                    538: .IR n th
                    539: matched string is replaced by the replacement specified.
                    540: If the global replacement indicator 
                    541: .L g
                    542: appears after the command,
                    543: all subsequent matches on the line are also replaced.
                    544: It is an error for the substitution to fail on all addressed lines.
                    545: Any character other than space or newline
                    546: may be used instead of 
                    547: .L /
                    548: to delimit the regular expression
                    549: and the replacement.
                    550: Dot is left at the last line substituted.
                    551: The third form means
                    552: .BI s n / regular\ expression / replacement\fP/p\f1.
                    553: The second
                    554: .L /
                    555: may be omitted if the replacement is
                    556: empty.
                    557: .IP
                    558: An ampersand 
                    559: .L &
                    560: appearing in the replacement
                    561: is replaced by the string matching the regular expression.
                    562: The characters
                    563: .BI \e n\f1,
                    564: where
                    565: .I n
                    566: is a digit,
                    567: are replaced by the text matched by the
                    568: .IR n -th
                    569: regular subexpression
                    570: enclosed between
                    571: .L (
                    572: and
                    573: .LR ) .
                    574: When
                    575: nested parenthesized subexpressions
                    576: are present,
                    577: .I n
                    578: is determined by counting occurrences of
                    579: .L (
                    580: starting from the left.
                    581: .IP
                    582: A literal 
                    583: .LR & ,
                    584: .LR / ,
                    585: .L \e
                    586: or newline may be included in a replacement
                    587: by prefixing it with
                    588: .LR \e .
                    589: .TP
                    590: .RB \*(.. \|t\|\fIa
                    591: Transfer.
                    592: Copy the addressed lines 
                    593: after the line addressed by
                    594: .IR a .
                    595: Dot is left at the last line of the copy.
                    596: .TP
                    597: .RB \*(.. \|u
                    598: Undo.
                    599: Restore the preceding contents
                    600: of the first addressed line (sic), which must be the last line
                    601: in which a substitution was made (double sic).
                    602: .TP
                    603: .RB \*(1$ \|v/\fIregular\ expression\fP/\fIcommand\ list\fP
                    604: This command is the same as the global command
                    605: .L g
                    606: except that the command list is executed with
                    607: dot initially set to every line
                    608: .I except
                    609: those
                    610: matching the regular expression.
                    611: .TP
                    612: .RB \*(1$ \|w " \fIfilename\fP"
                    613: Write the addressed lines to
                    614: the given file.
                    615: If the file does not exist,
                    616: it is created with mode 666 (readable and writable by everyone).
                    617: If no
                    618: .I filename
                    619: is given, the remembered file name, if any, is used.
                    620: The file name is remembered if there were no 
                    621: remembered file name already.
                    622: Dot is unchanged.
                    623: If the write is successful, the number of characters written is
                    624: printed.
                    625: .TP
                    626: .RB \*(1$ \|W " \fIfilename\fP"
                    627: Perform
                    628: .LR w ,
                    629: but append to, instead of overwriting, any existing file contents.
                    630: .TP
                    631: .RB ( $ ) \|=
                    632: Print the line number of the addressed line.
                    633: Dot is unchanged.
                    634: .TP
                    635: .BI ! shell\ command
                    636: Send the remainder of the line after the 
                    637: .L !
                    638: to
                    639: .IR rc (1)
                    640: to be interpreted as a command.
                    641: Dot is unchanged.
                    642: .TP
                    643: .RB (\| .+1 )\|<newline>
                    644: An address without a command is taken as a
                    645: .L p 
                    646: command.
                    647: A terminal
                    648: .L /
                    649: may be omitted from the address.
                    650: A blank line alone is equivalent to
                    651: .LR .+1p ;
                    652: it is useful
                    653: for stepping through text.
                    654: .PP
                    655: If an interrupt signal 
                    656: .SM (DEL)
                    657: is sent,
                    658: .I ed
                    659: prints a 
                    660: .L ?
                    661: and returns to its command level.
                    662: .PP
                    663: When reading a file,
                    664: .I ed
                    665: discards
                    666: .SM NUL
                    667: characters
                    668: and all characters after the last newline.
                    669: .SH FILES
                    670: .B /tmp/e*
                    671: .br
                    672: .B ed.hup
                    673: \ \ work is saved here if terminal hangs up
                    674: .SH SOURCE
                    675: .B /sys/src/cmd/ed.c
                    676: .SH "SEE ALSO"
                    677: .IR sam (1), 
                    678: .IR sed (1),
                    679: .IR regexp (6)
                    680: .SH DIAGNOSTICS
                    681: .BI ? name
                    682: for inaccessible file;
                    683: .L ?TMP
                    684: for temporary file overflow;
                    685: .L ?
                    686: for errors in commands or other overflows.
                    687: .rm .
                    688: .rm ..

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.