|
|
1.1 ! root 1: .TH ED 1 "14 September 1979" ! 2: .UC ! 3: .if t .ds q \(aa ! 4: .if n .ds q ' ! 5: .SH NAME ! 6: ed \- text editor ! 7: .SH SYNOPSIS ! 8: .B ed ! 9: [ ! 10: .B \- ! 11: ] [ ! 12: .B \-x ! 13: ] [ name ] ! 14: .SH DESCRIPTION ! 15: .I Ed ! 16: is the standard text editor. ! 17: .PP ! 18: If a ! 19: .I name ! 20: argument is given, ! 21: .I ed ! 22: simulates an ! 23: .I e ! 24: command (see below)\| on the named file; that is to say, ! 25: the file is read into ! 26: .I ed's ! 27: buffer so that it can be edited. ! 28: If ! 29: .B \-x ! 30: is present, an ! 31: .I x ! 32: command is simulated first to handle an encrypted file. ! 33: The optional ! 34: .B \- ! 35: suppresses the printing ! 36: of explanatory output ! 37: and should be used ! 38: when the standard input is ! 39: an editor script. ! 40: .PP ! 41: .I Ed ! 42: operates on a copy of any file it is editing; changes made ! 43: in the copy have no effect on the file until a ! 44: .IR w "" ! 45: (write)\| ! 46: command is given. ! 47: The copy of the text being edited resides ! 48: in a temporary file called the ! 49: .IR buffer . ! 50: .PP ! 51: Commands to ! 52: .I ed ! 53: have a simple and regular structure: zero or ! 54: more ! 55: .I addresses ! 56: followed by a single character ! 57: .I command, ! 58: possibly ! 59: followed by parameters to the command. ! 60: These addresses specify one or more lines in the buffer. ! 61: Missing addresses are supplied by default. ! 62: .PP ! 63: In general, only one command may appear on a line. ! 64: Certain commands allow the ! 65: addition of text to the buffer. ! 66: While ! 67: .I ed ! 68: is accepting text, it is said ! 69: to be in ! 70: .I "input mode." ! 71: In this mode, no commands are recognized; ! 72: all input is merely collected. ! 73: Input mode is left by typing a period `\fB.\fR' alone at the ! 74: beginning of a line. ! 75: .PP ! 76: .I Ed ! 77: supports a limited form of ! 78: .I "regular expression" ! 79: notation. ! 80: A regular expression specifies ! 81: a set of strings of characters. ! 82: A member of this set of strings is said to be ! 83: .I matched ! 84: by the regular expression. ! 85: In the following specification for regular expressions ! 86: the word `character' means any character but newline. ! 87: .IP 1. ! 88: Any character except a special character ! 89: matches itself. ! 90: Special characters are ! 91: the regular expression delimiter plus ! 92: .RB \e\|[\| . ! 93: and sometimes ^\|*\|$. ! 94: .IP 2. ! 95: A ! 96: .B . ! 97: matches any character. ! 98: .IP 3. ! 99: A \e followed by any character except a digit or (\|) matches that character. ! 100: .IP 4. ! 101: A nonempty string ! 102: .I s ! 103: bracketed ! 104: .RI [ \|s\| ] ! 105: (or ! 106: .RI [^ s\| ]) ! 107: matches any character in (or not in) ! 108: .I s. ! 109: In ! 110: .I s, ! 111: \e has no special meaning, and ] may only appear as ! 112: the first letter. ! 113: A substring ! 114: .I a\-b, ! 115: with ! 116: .I a ! 117: and ! 118: .I b ! 119: in ascending ASCII order, stands for the inclusive ! 120: range of ASCII characters. ! 121: .IP 5. ! 122: A regular expression of form 1-4 followed by * matches a sequence of ! 123: 0 or more matches of the regular expression. ! 124: .IP 6. ! 125: A regular expression, ! 126: .I x, ! 127: of form 1-8, bracketed ! 128: .RI \e( \|x\| \e) ! 129: matches what ! 130: .I x ! 131: matches. ! 132: .IP 7. ! 133: A \e followed by a digit ! 134: .I n ! 135: matches a copy of the string that the ! 136: bracketed regular expression beginning with the ! 137: .IR n th ! 138: \e( matched. ! 139: .IP 8. ! 140: A regular expression of form 1-8, ! 141: .I x, ! 142: followed by a regular expression of form 1-7, ! 143: .I y ! 144: matches a match for ! 145: .I x ! 146: followed by a match for ! 147: .I y, ! 148: with the ! 149: .I x ! 150: match being as long as possible while still permitting a ! 151: .I y ! 152: match. ! 153: .IP 9. ! 154: A regular expression of form 1-8 preceded by ^ ! 155: (or followed by $), is constrained to matches that ! 156: begin at the left (or end at the right) end of a line. ! 157: .IP 10. ! 158: A regular expression of form 1-9 picks out the ! 159: longest among the leftmost matches in a line. ! 160: .IP 11. ! 161: An empty regular expression stands for a copy of the ! 162: last regular expression encountered. ! 163: .PP ! 164: Regular expressions are used in addresses to specify ! 165: lines and in one command ! 166: (see ! 167: .I s ! 168: below)\| ! 169: to specify a portion of a line which is to be replaced. ! 170: If it is desired to use one of ! 171: the regular expression metacharacters as an ordinary ! 172: character, that character may be preceded by `\e'. ! 173: This also applies to the character bounding the regular ! 174: expression (often `/')\| and to `\e' itself. ! 175: .PP ! 176: To understand addressing in ! 177: .I ed ! 178: it is necessary to know that at any time there is a ! 179: .I "current line." ! 180: Generally speaking, the current line is ! 181: the last line affected by a command; however, ! 182: the exact effect on the current line ! 183: is discussed under the description of ! 184: the command. ! 185: Addresses are constructed as follows. ! 186: .TP ! 187: 1. ! 188: The character `\fB.\fR' addresses the current line. ! 189: .TP ! 190: 2. ! 191: The character `$' addresses the last line of the buffer. ! 192: .TP ! 193: 3. ! 194: A decimal number ! 195: .I n ! 196: addresses the ! 197: .IR n -th ! 198: line of the buffer. ! 199: .TP ! 200: 4. ! 201: `\(fm\fIx\fR' addresses the line marked with the name ! 202: .IR x , ! 203: which must be a lower-case letter. ! 204: Lines are marked with the ! 205: .I k ! 206: command described below. ! 207: .TP ! 208: 5. ! 209: A regular expression enclosed in slashes `/' addresses ! 210: the line found by searching forward from the current line ! 211: and stopping at the first line containing a ! 212: string that matches the regular expression. ! 213: If necessary the search wraps around to the beginning of the ! 214: buffer. ! 215: .TP ! 216: 6. ! 217: A regular expression enclosed in queries `?' addresses ! 218: the line found by searching backward from the current line ! 219: and stopping at the first line containing ! 220: a string that matches the regular expression. ! 221: If necessary ! 222: the search wraps around to the end of the buffer. ! 223: .TP ! 224: 7. ! 225: An address followed by a plus sign `+' ! 226: or a minus sign `\-' followed by a decimal number specifies that address plus ! 227: (resp. minus)\| the indicated number of lines. ! 228: The plus sign may be omitted. ! 229: .TP ! 230: 8. ! 231: If an address begins with `+' or `\-' ! 232: the addition or subtraction is taken with respect to the current line; ! 233: e.g. `\-5' is understood to mean `\fB.\fR\-5'. ! 234: .TP ! 235: 9. ! 236: If an address ends with `+' or `\-', ! 237: then 1 is added (resp. subtracted). ! 238: As a consequence of this rule and rule 8, ! 239: the address `\-' refers to the line before the current line. ! 240: Moreover, ! 241: trailing ! 242: `+' and `\-' characters ! 243: have cumulative effect, so `\-\-' refers to the current ! 244: line less 2. ! 245: .TP ! 246: 10. ! 247: To maintain compatibility with earlier versions of the editor, ! 248: the character `^' in addresses is ! 249: equivalent to `\-'. ! 250: .PP ! 251: Commands may require zero, one, or two addresses. ! 252: Commands which require no addresses regard the presence ! 253: of an address as an error. ! 254: Commands which accept one or two addresses ! 255: assume default addresses when insufficient are given. ! 256: If more addresses are given than such a command requires, ! 257: the last one or two (depending on what is accepted)\| are used. ! 258: .PP ! 259: Addresses are separated from each other typically by a comma ! 260: `\fB,\fR'. ! 261: They may also be separated by a semicolon ! 262: `\fB;\fR'. ! 263: In this case the current line `\fB.\fR' is set to ! 264: the previous address before the next address is interpreted. ! 265: This feature can be used to determine the starting ! 266: line for forward and backward searches (`/', `?')\|. ! 267: The second address of any two-address sequence ! 268: must correspond to a line following the line corresponding to the first address. ! 269: The special form `%' ! 270: is an abbreviation for the address pair `1,$'. ! 271: .PP ! 272: In the following list of ! 273: .I ed ! 274: commands, the default addresses ! 275: are shown in parentheses. ! 276: The parentheses are not part of ! 277: the address, but are used to show that the given addresses are ! 278: the default. ! 279: .PP ! 280: As mentioned, it is generally illegal for more than one ! 281: command to appear on a line. ! 282: However, most commands may be suffixed by `p' ! 283: or by `l', in which case ! 284: the current line is either ! 285: printed or listed respectively ! 286: in the way discussed below. ! 287: Commands may also be suffixed by `n', ! 288: meaning the output of the command is to ! 289: be line numbered. ! 290: These suffixes may be combined in any order. ! 291: .TP 5 ! 292: .RB (\| .\| )\|a ! 293: .br ! 294: .ns ! 295: .TP 5 ! 296: <text> ! 297: .br ! 298: .ns ! 299: .TP 5 ! 300: .B . ! 301: .br ! 302: The append command reads the given text ! 303: and appends it after the addressed line. ! 304: `\fB.\fR' is left ! 305: on the last line input, if there ! 306: were any, otherwise at the addressed line. ! 307: Address `0' is legal for this command; text is placed ! 308: at the beginning of the buffer. ! 309: .TP 5 ! 310: .RB (\| .\| ,\ .\| )\|c ! 311: .br ! 312: .ns ! 313: .TP 5 ! 314: <text> ! 315: .br ! 316: .ns ! 317: .TP 5 ! 318: .B . ! 319: .br ! 320: The change ! 321: command deletes the addressed lines, then accepts input ! 322: text which replaces these lines. ! 323: `\fB.\fR' is left at the last line input; if there were none, ! 324: it is left at the line preceding the deleted lines. ! 325: .TP 5 ! 326: .RB (\| .\| ,\ .\| )\|d ! 327: The delete command deletes the addressed lines from the buffer. ! 328: The line originally after the last line deleted becomes the current line; ! 329: if the lines deleted were originally at the end, ! 330: the new last line becomes the current line. ! 331: .TP 5 ! 332: e filename ! 333: The edit ! 334: command causes the entire contents of the buffer to be deleted, ! 335: and then the named file to be read in. ! 336: `\fB.\fR' is set to the last line of the buffer. ! 337: The number of characters read is typed. ! 338: `filename' is remembered for possible use as a default file name ! 339: in a subsequent ! 340: .I r ! 341: or ! 342: .I w ! 343: command. ! 344: If `filename' is missing, the remembered name is used. ! 345: .TP 5 ! 346: E filename ! 347: This command is the same as ! 348: .I e, ! 349: except that no diagnostic results when no ! 350: .I w ! 351: has been given since the last buffer alteration. ! 352: .TP 5 ! 353: f filename ! 354: The filename command prints the currently remembered file name. ! 355: If `filename' is given, ! 356: the currently remembered file name is changed to `filename'. ! 357: .TP 5 ! 358: (1,$)\|g/regular expression/command list ! 359: In the global ! 360: command, the first step is to mark every line which matches ! 361: the given regular expression. ! 362: Then for every such line, the ! 363: given command list is executed with `\fB.\fR' initially set to that line. ! 364: A single command or the first of multiple commands ! 365: appears on the same line with the global command. ! 366: All lines of a multi-line list except the last line must be ended with `\e'. ! 367: .I A, ! 368: .I i, ! 369: and ! 370: .I c ! 371: commands and associated input are permitted; ! 372: the `\fB.\fR' terminating input mode may be omitted if it would be on the ! 373: last line of the command list. ! 374: The commands ! 375: .I g ! 376: and ! 377: .I v ! 378: are not permitted in the command list. ! 379: .TP 5 ! 380: .RB (\| .\| )\|i ! 381: .ns ! 382: .TP 5 ! 383: <text> ! 384: .br ! 385: .ns ! 386: .TP 5 ! 387: .B . ! 388: .br ! 389: This command inserts the given text before the addressed line. ! 390: `\fB.\fR' is left at the last line input, or, if there were none, ! 391: at the line before the addressed line. ! 392: This command differs from the ! 393: .I a ! 394: command only in the placement of the ! 395: text. ! 396: .TP 5 ! 397: .RB (\| .\| ,\ . +1)\|j ! 398: This command joins the addressed lines into a single line; ! 399: intermediate newlines simply disappear. ! 400: `\fB.\fR' is left at the resulting line. ! 401: .TP 5 ! 402: ( \fB. \fR)\|k\fIx\fR ! 403: The mark command marks the addressed line with ! 404: name ! 405: .I x, ! 406: which must be a lower-case letter. ! 407: The address form `\(fm\fIx\fR' then addresses this line. ! 408: .ne 2.5 ! 409: .TP 5 ! 410: .RB (\| .\| ,\ .\| )\|l ! 411: The list command ! 412: prints the addressed lines in an unambiguous way: ! 413: non-graphic characters are ! 414: printed in two-digit octal, ! 415: and long lines are folded. ! 416: The ! 417: .I l ! 418: command may be placed on the same line after any non-i/o ! 419: command. ! 420: .TP 5 ! 421: .RB (\| .\| ,\ .\| )\|m\fIa ! 422: The move command repositions the addressed lines after the line ! 423: addressed by ! 424: .IR a . ! 425: The last of the moved lines becomes the current line. ! 426: .TP 5 ! 427: .RB (\| .\| ,\ .\| )\|p ! 428: The print command prints the addressed lines. ! 429: `\fB.\fR' ! 430: is left at the last line printed. ! 431: The ! 432: .I p ! 433: command ! 434: may ! 435: be placed on the same line after any non-i/o command. ! 436: .TP ! 437: .RB (\| .\| ,\ .\| )\|P ! 438: This command is a synonym for ! 439: .I p. ! 440: .TP 5 ! 441: q ! 442: The quit command causes ! 443: .I ed ! 444: to exit. ! 445: No automatic write ! 446: of a file is done. ! 447: .TP 5 ! 448: Q ! 449: This command is the same as ! 450: .I q, ! 451: except that no diagnostic results when no ! 452: .I w ! 453: has been given since the last buffer alteration. ! 454: .TP 5 ! 455: ($)\|r filename ! 456: The read command ! 457: reads in the given file after the addressed line. ! 458: If no file name is given, ! 459: the remembered file name, if any, is used ! 460: (see ! 461: .I e ! 462: and ! 463: .I f ! 464: commands)\|. ! 465: The file name is remembered if there was no ! 466: remembered file name already. ! 467: Address `0' is legal for ! 468: .I r ! 469: and causes the ! 470: file to be read at the beginning of the buffer. ! 471: If the read is successful, the number of characters ! 472: read is typed. ! 473: `\fB.\fR' is left at the last line read in from the file. ! 474: .TP 5 ! 475: (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/ or, ! 476: .br ! 477: .ns ! 478: .TP 5 ! 479: (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/replacement/g ! 480: The substitute command searches each addressed ! 481: line for an occurrence of the specified regular expression. ! 482: On each line in which a match is found, ! 483: all matched strings are replaced by the replacement specified, ! 484: if the global replacement indicator `g' appears after the command. ! 485: If the global indicator does not appear, only the first occurrence ! 486: of the matched string is replaced. ! 487: It is an error for the substitution to fail on all addressed lines. ! 488: Any punctuation character ! 489: may be used instead of `/' to delimit the regular expression ! 490: and the replacement. ! 491: `\fB.\fR' is left at the last line substituted. ! 492: .IP ! 493: An ampersand `&' appearing in the replacement ! 494: is replaced by the string matching the regular expression. ! 495: The special meaning of `&' in this context may be ! 496: suppressed by preceding it by `\e'. ! 497: The characters ! 498: .I `\|\en' ! 499: where ! 500: .I n ! 501: is a digit, ! 502: are replaced by the text matched by the ! 503: .IR n -th ! 504: regular subexpression ! 505: enclosed between `\e(' and `\e)'. ! 506: When ! 507: nested, parenthesized subexpressions ! 508: are present, ! 509: .I n ! 510: is determined by counting occurrences of `\e(' starting from the left. ! 511: .IP ! 512: Lines may be split by substituting new-line characters into them. ! 513: The new-line in the ! 514: replacement string ! 515: must be escaped by preceding it by `\e'. ! 516: .IP ! 517: One or two trailing delimiters may be omitted, ! 518: implying the `p' suffix. ! 519: The special form `s' followed by ! 520: .I no ! 521: delimiters ! 522: repeats the most recent substitute command ! 523: on the addressed lines. ! 524: The `s' may be followed by the letters ! 525: .B r ! 526: (use the most recent regular expression for the ! 527: left hand side, instead of the most recent ! 528: left hand side of a substitute command), ! 529: .B p ! 530: (complement the setting of the ! 531: .I p ! 532: suffix from the previous substitution), or ! 533: .B g ! 534: (complement the setting of the ! 535: .I g ! 536: suffix). ! 537: These letters may be combined in any order. ! 538: .TP 5 ! 539: .RB (\| .\| ,\ .\| )\|t\|\fIa ! 540: This command acts just like the ! 541: .I m ! 542: command, except that a copy of the addressed lines is placed ! 543: after address ! 544: .I a ! 545: (which may be 0). ! 546: `\fB.\fR' is left on the last line of the copy. ! 547: .TP 5 ! 548: .RB (\| .\| ,\ .\| )\|u ! 549: The undo command restores the buffer to it's state ! 550: before the most recent buffer modifying command. ! 551: The current line is also restored. ! 552: Buffer modifying commands are ! 553: .I a, c, d, g, i, k, m, r, s, t, ! 554: and ! 555: .I v. ! 556: For purposes of undo, ! 557: .I g ! 558: and ! 559: .I v ! 560: are considered to be a single buffer modifying command. ! 561: Undo is its own inverse. ! 562: .IP ! 563: When ! 564: .I ed ! 565: runs out of memory ! 566: (at about 8000 lines on any 16 bit mini-computer ! 567: such as the PDP-11) ! 568: This full undo is not possible, and ! 569: .I u ! 570: can only undo the effect of the most recent ! 571: substitute on the current line. ! 572: This restricted undo also applies to editor scripts ! 573: when ! 574: .I ed ! 575: is invoked with the ! 576: .B - ! 577: option. ! 578: .TP 5 ! 579: (1, $)\|v/regular expression/command list ! 580: This command is the same as the global command ! 581: .I g ! 582: except that the command list is executed ! 583: .I g ! 584: with `\fB.\fR' initially set to every line ! 585: .I except ! 586: those ! 587: matching the regular expression. ! 588: .TP 5 ! 589: (1, $)\|w filename ! 590: .br ! 591: The write command writes the addressed lines onto ! 592: the given file. ! 593: If the file does not exist, ! 594: it is created. ! 595: The file name is remembered if there was no ! 596: remembered file name already. ! 597: If no file name is given, ! 598: the remembered file name, if any, is used ! 599: (see ! 600: .I e ! 601: and ! 602: .I f ! 603: commands)\|. ! 604: `\fB.\fR' is unchanged. ! 605: If the command is successful, the number of characters written is ! 606: printed. ! 607: .TP ! 608: (1, $)\|W filename ! 609: This command is the same as ! 610: .I w, ! 611: except that the addressed lines are appended to the file. ! 612: .TP 5 ! 613: (1, $)\|wq filename ! 614: This command is the same as ! 615: .I w ! 616: except that afterwards a ! 617: .I q ! 618: command is done, ! 619: exiting the editor ! 620: after the file is written. ! 621: .TP 5 ! 622: x ! 623: A key string is demanded from the standard input. ! 624: Later ! 625: .I r, e ! 626: and ! 627: .I w ! 628: commands will encrypt and decrypt the text ! 629: with this key by the algorithm of ! 630: .IR crypt (1). ! 631: An explicitly empty key turns off encryption. ! 632: .TP 5 ! 633: ($)\|= ! 634: The line number of the addressed line is typed. ! 635: `\fB.\fR' is unchanged by this command. ! 636: .TP 5 ! 637: !<shell command> ! 638: The remainder of the line after the `!' is sent ! 639: to ! 640: .IR sh (1) ! 641: to be interpreted as a command. ! 642: .RB ` . ' ! 643: is unchanged. ! 644: .TP 5 ! 645: .RB (\| . +1,\| . +1)\|<newline> ! 646: An address alone on a line causes the addressed line to be printed. ! 647: A blank line alone is equivalent to `.+1p'; it is useful ! 648: for stepping through text. ! 649: If two addresses are present with no ! 650: intervening semicolon, ! 651: .I ed ! 652: prints the range of lines. ! 653: If they are separated by a semicolon, ! 654: the second line is printed. ! 655: .PP ! 656: If an interrupt signal (ASCII DEL)\| is sent, ! 657: .I ed ! 658: prints `?interrupted' ! 659: and returns to its command level. ! 660: .PP ! 661: Some size limitations: ! 662: 512 characters per line, ! 663: 256 characters per global command list, ! 664: 64 characters per file name, ! 665: and, on mini computers, ! 666: 128K characters in the temporary file. ! 667: The limit on the number of lines depends on the amount of core: ! 668: each line takes 2 words. ! 669: .PP ! 670: When reading a file, ! 671: .I ed ! 672: discards ASCII NUL characters ! 673: and all characters after the last newline. ! 674: It refuses to read files containing non-ASCII characters. ! 675: .SH FILES ! 676: /tmp/e* ! 677: .br ! 678: edhup: work is saved here if terminal hangs up ! 679: .SH "SEE ALSO" ! 680: B. W. Kernighan, ! 681: .I ! 682: A Tutorial Introduction to the ED Text Editor ! 683: .br ! 684: B. W. Kernighan, ! 685: .I Advanced editing on UNIX ! 686: .br ! 687: ex(1), sed(1), crypt(1) ! 688: .SH DIAGNOSTICS ! 689: `?name' for inaccessible file; ! 690: `?self-explanatory message' ! 691: for other errors. ! 692: .PP ! 693: To protect against throwing away valuable work, ! 694: a ! 695: .I q ! 696: or ! 697: .I e ! 698: command is considered to be in error, unless a ! 699: .I w ! 700: has occurred since the last buffer change. ! 701: A second ! 702: .I q ! 703: or ! 704: .I e ! 705: will be obeyed regardless. ! 706: .SH BUGS ! 707: The ! 708: .I l ! 709: command mishandles DEL. ! 710: .br ! 711: The ! 712: .I undo ! 713: command causes marks to be lost on affected lines. ! 714: .br ! 715: The ! 716: .I x ! 717: command, ! 718: .B -x ! 719: option, ! 720: and ! 721: special treatment of hangups ! 722: only work on UNIX.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.