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