|
|
1.1 ! root 1: .\" Copyright (c) 1990 Regents of the University of California. ! 2: .\" All rights reserved. The Berkeley software License Agreement ! 3: .\" specifies the terms and conditions for redistribution. ! 4: .\" ! 5: .\" @(#)ed.1 6.5.1.1 (Berkeley) 10/21/90 ! 6: .\" ! 7: .Dd October 21, 1990 ! 8: .Dt ED 1 ! 9: .Os ATT 7th ! 10: .if t .ds q \(aa ! 11: .if n .ds q ' ! 12: .Sh NAME ! 13: .Nm ed ! 14: .Nd text editor ! 15: .Sh SYNOPSIS ! 16: .Nm ed ! 17: .Op Fl ! 18: .Op Ar file ! 19: .Sh DESCRIPTION ! 20: .Nm Ed ! 21: is the standard text editor. ! 22: .Pp ! 23: If a ! 24: .Ar file ! 25: argument is given, ! 26: .Nm ed ! 27: simulates an ! 28: .Ic e ! 29: command (see below) on the named file; that is to say, ! 30: the file is read into ! 31: .Nm ed 's ! 32: buffer so that it can be edited. ! 33: .Tw Ds ! 34: .Tp Fl ! 35: Suppresses the printing ! 36: of explanatory output ! 37: and should be used ! 38: when the standard input is ! 39: an editor script. ! 40: .Tp ! 41: .Pp ! 42: .Nm Ed ! 43: operates on a copy of any file it is editing; changes made ! 44: in the copy have no effect on the file until a ! 45: .Ic w ! 46: (write) command is given. ! 47: The copy of the text being edited resides ! 48: in a temporary file called the ! 49: .Ar buffer . ! 50: .Pp ! 51: Commands to ! 52: .Nm ed ! 53: have a simple and regular structure: zero or ! 54: more ! 55: .Ar addresses ! 56: followed by a single character ! 57: .Ar 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: .Nm ed ! 68: is accepting text, it is said ! 69: to be in ! 70: .Ar 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 ! 74: .Sq Ic \&. ! 75: alone at the ! 76: beginning of a line. ! 77: .Pp ! 78: .Nm Ed ! 79: supports a limited form of ! 80: .Ar 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: .Ar matched ! 86: by the regular expression. ! 87: In the following specification for regular expressions ! 88: the word `character' means any character but newline. ! 89: .Tw Ds ! 90: .Tp 1. ! 91: Any character except a special character ! 92: matches itself. ! 93: Special characters are ! 94: the regular expression delimiter plus ! 95: .Sq Cm \e\[. ! 96: and sometimes ! 97: .Sq Cm ^*$ . ! 98: .Tp 2. ! 99: A ! 100: .Sq Cm \&. ! 101: matches any character. ! 102: .Tp 3. ! 103: A ! 104: .Sq Li \e ! 105: followed by any character except a digit or ! 106: .Li (\) ! 107: matches that character. ! 108: .Tp 4. ! 109: A nonempty string ! 110: .Op Ar s ! 111: or ! 112: .Oo ! 113: .Cx \&( ! 114: .Op Cm \&^ Ar s ! 115: .Cx \&) ! 116: .Cx ! 117: .Oo ! 118: matches any character in (or not in) ! 119: .Ar s . ! 120: In ! 121: .Ar s , ! 122: .Sq Li \e ! 123: has no special meaning, and ! 124: may only appear as ! 125: the first letter. ! 126: A substring ! 127: .Ar a\-b , ! 128: with ! 129: .Ar a ! 130: and ! 131: .Ar b ! 132: in ascending ASCII order, stands for the inclusive ! 133: range of ASCII characters. ! 134: .Tp 5. ! 135: A regular expression of form 1\-4 followed by * matches a sequence of ! 136: 0 or more matches of the regular expression. ! 137: .Tp 6. ! 138: A regular expression, ! 139: .Ar x , ! 140: of form 1\-8, bracketed ! 141: .Cx Li \e( ! 142: .Ar x ! 143: .Li \e) ! 144: .Cx ! 145: matches what ! 146: .Ar x ! 147: matches. ! 148: .Tp 7. ! 149: A \e followed by a digit ! 150: .Ar n ! 151: matches a copy of the string that the ! 152: bracketed regular expression beginning with the ! 153: .Cx Ar n ! 154: .Cx \'th ! 155: .Cx ! 156: .Li \e( ! 157: matched. ! 158: .Tp 8. ! 159: A regular expression of form 1\-8, ! 160: .Ar x , ! 161: followed by a regular expression of form 1\-7, ! 162: .Ar y ! 163: matches a match for ! 164: .Ar x ! 165: followed by a match for ! 166: .Ar y , ! 167: with the ! 168: .Ar x ! 169: match being as long as possible while still permitting a ! 170: .Ar y ! 171: match. ! 172: .Tp 9. ! 173: A regular expression of form 1\-8 preceded by ! 174: .Sq Li ^ ! 175: (or followed by ! 176: .Sq Li $ ) , ! 177: is constrained to matches that ! 178: begin at the left (or end at the right) end of a line. ! 179: .Tp 10. ! 180: A regular expression of form 1\-9 picks out the ! 181: longest among the leftmost matches in a line. ! 182: .Tp 11. ! 183: An empty regular expression stands for a copy of the ! 184: last regular expression encountered. ! 185: .Tp ! 186: .Pp ! 187: Regular expressions are used in addresses to specify ! 188: lines and in one command ! 189: (see ! 190: .Ar s ! 191: below) ! 192: to specify a portion of a line which is to be replaced. ! 193: If it is desired to use one of ! 194: the regular expression metacharacters as an ordinary ! 195: character, that character may be preceded by ! 196: .Sq Li \e . ! 197: This also applies to the character bounding the regular ! 198: expression (often ! 199: .Sq Li \&/ ) ! 200: and to ! 201: .Sq Li \e ! 202: itself. ! 203: .Pp ! 204: To understand addressing in ! 205: .Nm ed ! 206: it is necessary to know that at any time there is a ! 207: .Ar current line. ! 208: Generally speaking, the current line is ! 209: the last line affected by a command; however, ! 210: the exact effect on the current line ! 211: is discussed under the description of ! 212: the command. ! 213: Addresses are constructed as follows. ! 214: .Tw Ds ! 215: .Tp 1. ! 216: The character ! 217: .Sq Ic \&. ! 218: addresses the current line. ! 219: .Tp 2. ! 220: The character ! 221: .Cx ` ! 222: .Ic $ ! 223: .Cx \' ! 224: .Cx ! 225: addresses the last line of the buffer. ! 226: .Tp 3. ! 227: A decimal number ! 228: .Ar n ! 229: addresses the ! 230: .Cx Ar n ! 231: .Cx \'th ! 232: .Cx ! 233: line of the buffer. ! 234: .Tp 4. ! 235: .Cx `\(fm ! 236: .Ar x ! 237: .Cx \' ! 238: .Cx ! 239: addresses the line marked with the name ! 240: .Ar x , ! 241: which must be a lower-case letter. ! 242: Lines are marked with the ! 243: .Ar k ! 244: command described below. ! 245: .Tp 5. ! 246: A regular expression enclosed in slashes ! 247: .Cx ` ! 248: .Li / ! 249: .Cx \' ! 250: .Cx ! 251: addresses ! 252: the line found by searching forward from the current line ! 253: and stopping at the first line containing a ! 254: string that matches the regular expression. ! 255: If necessary the search wraps around to the beginning of the ! 256: buffer. ! 257: .Tp 6. ! 258: A regular expression enclosed in queries ! 259: .Cx ` ! 260: .Li ? ! 261: .Cx \' ! 262: .Cx ! 263: addresses ! 264: the line found by searching backward from the current line ! 265: and stopping at the first line containing ! 266: a string that matches the regular expression. ! 267: If necessary ! 268: the search wraps around to the end of the buffer. ! 269: .Tp 7. ! 270: An address followed by a plus sign ! 271: .Cx ` ! 272: .Li + ! 273: .Cx \' ! 274: .Cx ! 275: or a minus sign ! 276: .Cx ` ! 277: .Li \- ! 278: .Cx \' ! 279: .Cx ! 280: followed by a decimal number specifies that address plus ! 281: (resp. minus) the indicated number of lines. ! 282: The plus sign may be omitted. ! 283: .Tp 8. ! 284: If an address begins with ! 285: .Cx ` ! 286: .Li + ! 287: .Cx \' ! 288: .Cx ! 289: or ! 290: .Cx ` ! 291: .Li \- ! 292: .Cx \' ! 293: .Cx ! 294: the addition or subtraction is taken with respect to the current line; ! 295: e.g. ! 296: .Cx ` ! 297: .Li \-5 ! 298: .Cx \' ! 299: .Cx ! 300: is understood to mean ! 301: .Cx ` ! 302: .Li .\-5 ! 303: .Cx \' ! 304: .Cx ! 305: .Nm . ! 306: .Tp 9. ! 307: If an address ends with ! 308: .Cx ` ! 309: .Li + ! 310: .Cx \' ! 311: .Cx ! 312: .Cx ` ! 313: .Li \- ! 314: .Cx \', ! 315: .Cx ! 316: then 1 is added (resp. subtracted). ! 317: As a consequence of this rule and rule 8, ! 318: the address ! 319: .Cx ` ! 320: .Li \- ! 321: .Cx \' ! 322: .Cx ! 323: refers to the line before the current line. ! 324: Moreover, ! 325: trailing ! 326: .Cx ` ! 327: .Li + ! 328: .Cx \' ! 329: .Cx ! 330: and ! 331: .Cx ` ! 332: .Li \- ! 333: .Cx \' ! 334: .Cx ! 335: characters ! 336: have cumulative effect, so ! 337: .Cx ` ! 338: .Li \-\- ! 339: .Cx \' ! 340: .Cx ! 341: refers to the current ! 342: line less 2. ! 343: .Tp 10. ! 344: To maintain compatibility with earlier versions of the editor, ! 345: the character ! 346: .Cx ` ! 347: .Li ^ ! 348: .Cx \' ! 349: .Cx ! 350: in addresses is ! 351: equivalent to ! 352: .Cx ` ! 353: .Li \- ! 354: .Cx \'. ! 355: .Cx ! 356: .Tp ! 357: .Pp ! 358: Commands may require zero, one, or two addresses. ! 359: Commands which require no addresses regard the presence ! 360: of an address as an error. ! 361: Commands which accept one or two addresses ! 362: assume default addresses when insufficient are given. ! 363: If more addresses are given than such a command requires, ! 364: the last one or two (depending on what is accepted) are used. ! 365: .Pp ! 366: Addresses are separated from each other typically by a comma ! 367: .Cx ` ! 368: .Li , ! 369: .Cx \' ! 370: .Cx ! 371: They may also be separated by a semicolon ! 372: .Cx ` ! 373: .Li ; ! 374: .Cx \' ! 375: .Cx ! 376: In this case the current line ! 377: .Cx ` ! 378: .Li . ! 379: .Cx \' ! 380: .Cx ! 381: .Nm . ! 382: is set to ! 383: the previous address before the next address is interpreted. ! 384: This feature can be used to determine the starting ! 385: line for forward and backward searches ! 386: .Cx \&(` ! 387: .Li / ! 388: .Cx \' ! 389: .Cx ! 390: .Cx ` ! 391: .Li ? ! 392: .Cx \'). ! 393: .Cx ! 394: The second address of any two-address sequence ! 395: must correspond to a line following the line corresponding to the first address. ! 396: The special form ! 397: .Cx ` ! 398: .Li \&% ! 399: .Cx \' ! 400: .Cx ! 401: is an abbreviation for the address pair ! 402: .Cx ` ! 403: .Li 1,$ ! 404: .Cx \'. ! 405: .Cx ! 406: .Pp ! 407: In the following list of ! 408: .Nm ed ! 409: commands, the default addresses ! 410: are shown in parentheses. ! 411: The parentheses are not part of ! 412: the address, but are used to show that the given addresses are ! 413: the default. ! 414: .Pp ! 415: As mentioned, it is generally illegal for more than one ! 416: command to appear on a line. ! 417: However, most commands may be suffixed by `p' ! 418: or by `l', in which case ! 419: the current line is either ! 420: printed or listed respectively ! 421: in the way discussed below. ! 422: Commands may also be suffixed by `n', ! 423: meaning the output of the command is to ! 424: be line numbered. ! 425: These suffixes may be combined in any order. ! 426: .Tw Ds ! 427: .Tp Cx \&( ! 428: .Ic . ! 429: .Cx \&) ! 430: .Ic a ! 431: .Cx ! 432: .Tp <text> ! 433: .Tp Ic \&. ! 434: The append command reads the given text ! 435: and appends it after the addressed line. ! 436: .Sq Ic \&. ! 437: is left ! 438: on the last line input, if there ! 439: were any, otherwise at the addressed line. ! 440: Address `0' is legal for this command; text is placed ! 441: at the beginning of the buffer. ! 442: .Tp Cx \&( ! 443: .Ic \&. ! 444: .Cx \&, ! 445: .Ic \&. ! 446: .Cx \&) ! 447: .Ic \&c ! 448: .Cx ! 449: .Tp <text> ! 450: .Tp Ic \&. ! 451: The change ! 452: command deletes the addressed lines, then accepts input ! 453: text which replaces these lines. ! 454: .Sq Ic \&. ! 455: is left at the last line input; if there were none, ! 456: it is left at the line preceding the deleted lines. ! 457: .Tp Cx \&( ! 458: .Ic \&. ! 459: .Cx \&, ! 460: .Ic \&. ! 461: .Cx \&) ! 462: .Ic \&d ! 463: .Cx ! 464: The delete command deletes the addressed lines from the buffer. ! 465: The line originally after the last line deleted becomes the current line; ! 466: if the lines deleted were originally at the end, ! 467: the new last line becomes the current line. ! 468: .Tp Cx Ic \&e ! 469: .Cx \&\ \& ! 470: .Ar filename ! 471: .Cx ! 472: The edit ! 473: command causes the entire contents of the buffer to be deleted, ! 474: and then the named file to be read in. ! 475: .Sq Ic \&. ! 476: is set to the last line of the buffer. ! 477: The number of characters read is typed. ! 478: .Ar filename ! 479: is remembered for possible use as a default file name ! 480: in a subsequent ! 481: .Ic r ! 482: or ! 483: .Ic w ! 484: command. ! 485: If ! 486: .Ar filename ! 487: is missing, the remembered name is used. ! 488: .Tp Cx Ic E ! 489: .Cx \&\ \& ! 490: .Ar filename ! 491: .Cx ! 492: This command is the same as ! 493: .Ic e , ! 494: except that no diagnostic results when no ! 495: .Ic w ! 496: has been given since the last buffer alteration. ! 497: .Tp Cx Ic f ! 498: .Cx \&\ \& ! 499: .Ar filename ! 500: .Cx ! 501: The filename command prints the currently remembered file name. ! 502: If ! 503: .Ar filename ! 504: is given, ! 505: the currently remembered file name is changed to ! 506: .Ar filename . ! 507: .Tp Cx \&( ! 508: .Ic \&1 ! 509: .Cx \&, ! 510: .Ic \&$ ! 511: .Cx \&) ! 512: .Ic \&g ! 513: .Ar/regular expression/command list ! 514: .Cx ! 515: In the global ! 516: command, the first step is to mark every line which matches ! 517: the given regular expression. ! 518: Then for every such line, the ! 519: given command list is executed with ! 520: .Cx ` ! 521: .Ic \&. ! 522: .Cx \' ! 523: .Cx ! 524: initially set to that line. ! 525: A single command or the first of multiple commands ! 526: appears on the same line with the global command. ! 527: All lines of a multi-line list except the last line must be ended with ! 528: .Cx ` ! 529: .Ic \&\e ! 530: .Cx \'. ! 531: .Cx ! 532: .Ic A , ! 533: .Ic i, ! 534: and ! 535: .Ic c ! 536: commands and associated input are permitted; ! 537: the ! 538: .Cx ` ! 539: .Ic \&. ! 540: .Cx \' ! 541: .Cx ! 542: terminating input mode may be omitted if it would be on the ! 543: last line of the command list. ! 544: The commands ! 545: .Ic g ! 546: and ! 547: .Ic v ! 548: are not permitted in the command list. ! 549: .Tp Cx \&( ! 550: .Ic . ! 551: .Cx \&) ! 552: .Ic i ! 553: .Cx ! 554: .Tp <text> ! 555: .Tp Ic \&. ! 556: This command inserts the given text before the addressed line. ! 557: .Cx ` ! 558: .Ic \&. ! 559: .Cx \' ! 560: .Cx ! 561: is left at the last line input, or, if there were none, ! 562: at the line before the addressed line. ! 563: This command differs from the ! 564: .Ic a ! 565: command only in the placement of the ! 566: text. ! 567: .Tp Cx \&( ! 568: .Ic \&. ! 569: .Cx \&, ! 570: .Ic \&.+1 ! 571: .Cx \&) ! 572: .Ic \&j ! 573: .Cx ! 574: This command joins the addressed lines into a single line; ! 575: intermediate newlines simply disappear. ! 576: .Cx ` ! 577: .Ic \&. ! 578: .Cx \' ! 579: .Cx ! 580: is left at the resulting line. ! 581: .Tp Cx \&( ! 582: .Ic . ! 583: .Cx \&) ! 584: .Ic k ! 585: .Ar x ! 586: .Cx ! 587: The mark command marks the addressed line with ! 588: name ! 589: .Ar x , ! 590: which must be a lower-case letter. ! 591: The address form ! 592: .Cx `\(fm ! 593: .Ar x ! 594: .Cx \' ! 595: .Cx ! 596: then addresses this line. ! 597: .Tp Cx \&( ! 598: .Ic \&. ! 599: .Cx \&, ! 600: .Ic \&. ! 601: .Cx \&) ! 602: .Ic \&l ! 603: .Cx ! 604: The list command ! 605: prints the addressed lines in an unambiguous way: ! 606: non-graphic characters are ! 607: printed in two-digit octal, ! 608: and long lines are folded. ! 609: The ! 610: .Ar l ! 611: command may be placed on the same line after any non-i/o ! 612: command. ! 613: .Tp Cx \&( ! 614: .Ic \&. ! 615: .Cx \&, ! 616: .Ic \&. ! 617: .Cx \&) ! 618: .Ic \&m ! 619: .Ar a ! 620: .Cx ! 621: The move command repositions the addressed lines after the line ! 622: addressed by ! 623: .Ar a . ! 624: The last of the moved lines becomes the current line. ! 625: .Tp Cx \&( ! 626: .Ic \&. ! 627: .Cx \&, ! 628: .Ic \&. ! 629: .Cx \&) ! 630: .Ic \&p ! 631: .Cx ! 632: The print command prints the addressed lines. ! 633: .Cx ` ! 634: .Ic \&. ! 635: .Cx \' ! 636: .Cx ! 637: is left at the last line printed. ! 638: The ! 639: .Ic p ! 640: command ! 641: may ! 642: be placed on the same line after any non-i/o command. ! 643: .Tp Cx \&( ! 644: .Ic \&. ! 645: .Cx \&, ! 646: .Ic \&. ! 647: .Cx \&) ! 648: .Ic \&P ! 649: .Cx ! 650: This command is a synonym for ! 651: .Ic p . ! 652: .Tp Ic q ! 653: The quit command causes ! 654: .Nm ed ! 655: to exit. ! 656: No automatic write ! 657: of a file is done. ! 658: .Tp Ic Q ! 659: This command is the same as ! 660: .Ic q , ! 661: except that no diagnostic results when no ! 662: .Ic w ! 663: has been given since the last buffer alteration. ! 664: .Tp Cx \&( ! 665: .Ic $ ! 666: .Cx \&) ! 667: .Ic r ! 668: .Cx \&\ \& ! 669: .Ar filename ! 670: .Cx ! 671: The read command ! 672: reads in the given file after the addressed line. ! 673: If no file name is given, ! 674: the remembered file name, if any, is used ! 675: (see ! 676: .Ic e ! 677: and ! 678: .Ic f ! 679: commands). ! 680: The file name is remembered if there was no ! 681: remembered file name already. ! 682: Address `0' is legal for ! 683: .Ic r ! 684: and causes the ! 685: file to be read at the beginning of the buffer. ! 686: If the read is successful, the number of characters ! 687: read is typed. ! 688: .Cx ` ! 689: .Ic \&. ! 690: .Cx \' ! 691: .Cx ! 692: is left at the last line read in from the file. ! 693: .Tp Cx \&( ! 694: .Ic \&. ! 695: .Cx \&, ! 696: .Ic \&. ! 697: .Cx \&) ! 698: .Ic \&s ! 699: .Ar/regular expression/replacement/ ! 700: .Cx \&\tor ! 701: .Cx ! 702: .Tp Cx \&( ! 703: .Ic \&. ! 704: .Cx \&, ! 705: .Ic \&. ! 706: .Cx \&) ! 707: .Ic \&s ! 708: .Ar/regular expression/replacement/ ! 709: .Ic \&g ! 710: .Cx ! 711: The substitute command searches each addressed ! 712: line for an occurrence of the specified regular expression. ! 713: On each line in which a match is found, ! 714: all matched strings are replaced by the replacement specified, ! 715: if the global replacement indicator ! 716: .Ic \&g ! 717: appears after the command. ! 718: If the global indicator does not appear, only the first occurrence ! 719: of the matched string is replaced. ! 720: It is an error for the substitution to fail on all addressed lines. ! 721: Any punctuation character ! 722: may be used instead of ! 723: .Cx ` ! 724: .Ic \&/ ! 725: .Cx \' ! 726: .Cx ! 727: to delimit the regular expression ! 728: and the replacement. ! 729: .Cx ` ! 730: .Ic \&. ! 731: .Cx \' ! 732: .Cx ! 733: is left at the last line substituted. ! 734: An ampersand ! 735: .Cx ` ! 736: .Ic \&& ! 737: .Cx \' ! 738: .Cx ! 739: appearing in the replacement ! 740: is replaced by the string matching the regular expression. ! 741: The special meaning of ! 742: .Cx ` ! 743: .Ic \&& ! 744: .Cx \' ! 745: .Cx ! 746: in this context may be ! 747: suppressed by preceding it by ! 748: .Cx ` ! 749: .Ic \&\e ! 750: .Cx \'. ! 751: .Cx ! 752: The characters ! 753: .Cx ` ! 754: .Ic \&\e ! 755: .Ar n ! 756: .Cx \' ! 757: .Cx ! 758: where ! 759: .Ar n ! 760: is a digit, ! 761: are replaced by the text matched by the ! 762: .Cx Ar n ! 763: .Cx \'th ! 764: .Cx ! 765: regular subexpression ! 766: enclosed between ! 767: .Cx ` ! 768: .Ic \&\e\&( ! 769: .Cx \'. ! 770: .Cx ! 771: and ! 772: .Cx ` ! 773: .Ic \&\e\&) ! 774: .Cx \'. ! 775: .Cx ! 776: When ! 777: nested, parenthesized subexpressions ! 778: are present, ! 779: .Ar n ! 780: is determined by counting occurrences of ! 781: .Cx ` ! 782: .Ic \&\e\&( ! 783: .Cx \'. ! 784: .Cx ! 785: starting from the left. ! 786: Lines may be split by substituting new-line characters into them. ! 787: The new-line in the ! 788: replacement string ! 789: must be escaped by preceding it by ! 790: .Cx ` ! 791: .Ic \&\e ! 792: .Cx \'. ! 793: .Cx ! 794: One or two trailing delimiters may be omitted, ! 795: implying the ! 796: .Ic p ! 797: suffix. ! 798: The special form ! 799: .Ic s ! 800: followed by ! 801: .Ar no ! 802: delimiters ! 803: repeats the most recent substitute command ! 804: on the addressed lines. ! 805: The ! 806: .Ic s ! 807: may be followed by the letters ! 808: .Ic r ! 809: (use the most recent regular expression for the ! 810: left hand side, instead of the most recent ! 811: left hand side of a substitute command), ! 812: .Ic p ! 813: (complement the setting of the ! 814: .Ic p ! 815: suffix from the previous substitution), or ! 816: .Ic g ! 817: (complement the setting of the ! 818: .Ic g ! 819: suffix). ! 820: These letters may be combined in any order. ! 821: .Tp Cx \&( ! 822: .Ic \&. ! 823: .Cx \&, ! 824: .Ic \&. ! 825: .Cx \&) ! 826: .Ic \&t ! 827: .Ar a ! 828: .Cx ! 829: This command acts just like the ! 830: .Ic m ! 831: command, except that a copy of the addressed lines is placed ! 832: after address ! 833: .Ad a ! 834: (which may be 0). ! 835: .Cx ` ! 836: .Ic \&. ! 837: .Cx \' ! 838: .Cx ! 839: is left on the last line of the copy. ! 840: .Tp Cx \&( ! 841: .Ic \&. ! 842: .Cx \&, ! 843: .Ic \&. ! 844: .Cx \&) ! 845: .Ic \&u ! 846: .Cx ! 847: The undo command restores the buffer to it's state ! 848: before the most recent buffer modifying command. ! 849: The current line is also restored. ! 850: Buffer modifying commands are ! 851: .Ic a , c , d , g , i , k , m , r , s , t , ! 852: and ! 853: .Ic v . ! 854: For purposes of undo, ! 855: .Ic g ! 856: and ! 857: .Ic v ! 858: are considered to be a single buffer modifying command. ! 859: Undo is its own inverse. ! 860: When ! 861: .Nm ed ! 862: runs out of memory ! 863: (at about 8000 lines on any 16 bit mini-computer ! 864: such as the PDP-11) ! 865: This full undo is not possible, and ! 866: .Ic u ! 867: can only undo the effect of the most recent ! 868: substitute on the current line. ! 869: This restricted undo also applies to editor scripts ! 870: when ! 871: .Nm ed ! 872: is invoked with the ! 873: .Fl ! 874: option. ! 875: .Tp Cx \&( ! 876: .Ic \&1 ! 877: .Cx \&, ! 878: .Ic \&$ ! 879: .Cx \&) ! 880: .Ic \&v ! 881: .Ar/regular expression/command list ! 882: .Cx ! 883: This command is the same as the global command ! 884: .Ic g ! 885: except that the command list is executed ! 886: .Ic g ! 887: with ! 888: .Cx ` ! 889: .Ic \&. ! 890: .Cx \' ! 891: .Cx ! 892: initially set to every line ! 893: .Em except ! 894: those ! 895: matching the regular expression. ! 896: (1, $)\w filename ! 897: .Tp Cx \&( ! 898: .Ic \&1 ! 899: .Cx \&, ! 900: .Ic \&$ ! 901: .Cx \&) ! 902: .Ic \&w ! 903: .Cx \&\ \& ! 904: .Ar filename ! 905: .Cx ! 906: The write command writes the addressed lines onto ! 907: the given file. ! 908: If the file does not exist, ! 909: it is created. ! 910: The file name is remembered if there was no ! 911: remembered file name already. ! 912: If no file name is given, ! 913: the remembered file name, if any, is used ! 914: (see ! 915: .Ic e ! 916: and ! 917: .Ic f ! 918: commands). ! 919: .Cx ` ! 920: .Ic \&. ! 921: .Cx \' ! 922: .Cx ! 923: is unchanged. ! 924: If the command is successful, the number of characters written is ! 925: printed. ! 926: .Tp Cx \&( ! 927: .Ic \&1 ! 928: .Cx \&, ! 929: .Ic \&$ ! 930: .Cx \&) ! 931: .Ic \&W ! 932: .Cx \&\ \& ! 933: .Ar filename ! 934: .Cx ! 935: This command is the same as ! 936: .Ic w , ! 937: except that the addressed lines are appended to the file. ! 938: .Tp Cx \&( ! 939: .Ic \&1 ! 940: .Cx \&, ! 941: .Ic \&$ ! 942: .Cx \&) ! 943: .Ic \&wq ! 944: .Cx \&\ \& ! 945: .Ar filename ! 946: .Cx ! 947: This command is the same as ! 948: .Ic w ! 949: except that afterwards a ! 950: .Ic q ! 951: command is done, ! 952: exiting the editor ! 953: after the file is written. ! 954: .Ic \&1 ! 955: .Ic \&+1 ! 956: .Cx \&) ! 957: .Ic \&z ! 958: .Cx \&\ \ \&or, ! 959: .Cx ! 960: .Tp Cx \&( ! 961: .Ic \&1 ! 962: .Ic \&+1 ! 963: .Cx \&) ! 964: .Ic \&z ! 965: .Ar n ! 966: .Cx ! 967: This command scrolls through the buffer starting at the addressed line. ! 968: 22 (or ! 969: .Ar n , ! 970: if given) ! 971: lines are printed. ! 972: The last line printed becomes the current line. ! 973: The value ! 974: .Ar n ! 975: is sticky, in that it becomes the default for ! 976: future ! 977: .Ic z ! 978: commands. ! 979: .Tp Cx \&( ! 980: .Ic \&$ ! 981: .Cx \&) ! 982: .Ic \&= ! 983: .Cx ! 984: The line number of the addressed line is typed. ! 985: .Cx ` ! 986: .Ic \&. ! 987: .Cx \' ! 988: .Cx ! 989: is unchanged by this command. ! 990: .Tp Cx Ic \&! ! 991: .Cx <shell\ command> ! 992: .Cx ! 993: The remainder of the line after the `!' is sent ! 994: to ! 995: .Xr sh 1 ! 996: to be interpreted as a command. ! 997: .Cx ` ! 998: .Ic \&. ! 999: .Cx \' ! 1000: .Cx ! 1001: is unchanged. ! 1002: .Tp Cx \&( ! 1003: .Ic \&.+1 ! 1004: .Cx \&, ! 1005: .Ic \&.+1 ! 1006: .Cx \&) ! 1007: .Cx <newline> ! 1008: .Cx ! 1009: An address alone on a line causes the addressed line to be printed. ! 1010: A blank line alone is equivalent to ! 1011: .Ic .+1 ! 1012: it is useful ! 1013: for stepping through text. ! 1014: If two addresses are present with no ! 1015: intervening semicolon, ! 1016: .Nm ed ! 1017: prints the range of lines. ! 1018: If they are separated by a semicolon, ! 1019: the second line is printed. ! 1020: .Tp ! 1021: .Pp ! 1022: If an interrupt signal (ASCII DEL) is sent, ! 1023: .Nm ed ! 1024: prints ! 1025: .Sq Li ?interrupted ! 1026: and returns to its command level. ! 1027: .Pp ! 1028: Some size limitations: ! 1029: 512 characters per line, ! 1030: 256 characters per global command list, ! 1031: 64 characters per file name, ! 1032: and, on mini computers, ! 1033: 128K characters in the temporary file. ! 1034: The limit on the number of lines depends on the amount of core: ! 1035: each line takes 2 words. ! 1036: .Pp ! 1037: When reading a file, ! 1038: .Nm ed ! 1039: discards ASCII NUL characters ! 1040: and all characters after the last newline. ! 1041: It refuses to read files containing non-ASCII characters. ! 1042: .Sh FILES ! 1043: .Dw edhup ! 1044: .Di L ! 1045: .Dp Pa /tmp/e* ! 1046: .Dp Pa edhup ! 1047: work is saved here if terminal hangs up ! 1048: .Dp ! 1049: .Sh SEE ALSO ! 1050: .Xr ex 1 , ! 1051: .Xr sed 1 , ! 1052: .Xr crypt 1 ! 1053: .br ! 1054: B. W. Kernighan, ! 1055: .Em A Tutorial Introduction to the ED Text Editor ! 1056: .br ! 1057: B. W. Kernighan, ! 1058: .Em Ar Advanced editing on UNIX ! 1059: .Sh HISTORY ! 1060: The ! 1061: .Nm ed ! 1062: command appeared in Version 6 AT&T UNIX. ! 1063: .Sh DIAGNOSTICS ! 1064: .Sq Li name ! 1065: for inaccessible file; ! 1066: .Sq Li ?self-explanatory message ! 1067: for other errors. ! 1068: .Pp ! 1069: To protect against throwing away valuable work, ! 1070: a ! 1071: .Ic q ! 1072: or ! 1073: .Ic e ! 1074: command is considered to be in error, unless a ! 1075: .Ic w ! 1076: has occurred since the last buffer change. ! 1077: A second ! 1078: .Ic q ! 1079: or ! 1080: .Ic e ! 1081: will be obeyed regardless. ! 1082: .Sh BUGS ! 1083: The ! 1084: .Ic l ! 1085: command mishandles ! 1086: .Li DEL . ! 1087: .br ! 1088: The ! 1089: .Ic undo ! 1090: command causes marks to be lost on affected lines.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.