| 1 | .\" Copyright (c) 1992 The Regents of the University of California. |
| 2 | .\" All rights reserved. |
| 3 | .\" |
| 4 | .\" This code is derived from software contributed to Berkeley by |
| 5 | .\" Rodney Ruddock of the University of Guelph. |
| 6 | .\" |
| 7 | .\" %sccs.include.redist.roff% |
| 8 | .\" |
| 9 | .\" @(#)ed.1 5.3 (Berkeley) %G% |
| 10 | .\" |
| 11 | .TH ED 1 "" |
| 12 | .SH NAME |
| 13 | ed \- line oriented text editor |
| 14 | .SH SYNOPSIS |
| 15 | .B ed |
| 16 | [ |
| 17 | .B \-p |
| 18 | .I prompt-string |
| 19 | ] [ |
| 20 | .B \-s |
| 21 | ] [ |
| 22 | .B \-v |
| 23 | ] [ |
| 24 | .I filename |
| 25 | ] |
| 26 | .SH DESCRIPTION |
| 27 | .I Ed |
| 28 | is a standard text editor. |
| 29 | .PP |
| 30 | \fIEd\fR is a powerful line oriented editor. Although ex(1)/vi(1) have gained |
| 31 | popularity, \fIed\fR still maintains advantages over them. Most notable points |
| 32 | are the |
| 33 | .I W |
| 34 | command (see below) (which is not part of ex(1)/vi(1)\|), the |
| 35 | smaller executable size (you can often be editing before the others finish |
| 36 | loading), and the better response when editing from slow terminals or across |
| 37 | low baud data lines. \fIEd\fR continues to be used by many system utilities. |
| 38 | .SH OPTIONS |
| 39 | .PP |
| 40 | When a filename is present \fIed\fR starts by simulating an |
| 41 | .I e |
| 42 | command (see below) |
| 43 | If no filename is present \fIed\fR |
| 44 | starts with an empty buffer. |
| 45 | The option |
| 46 | .B \-p |
| 47 | allows for the setting of a prompt string in |
| 48 | .IR ed . |
| 49 | The option |
| 50 | .B \-s |
| 51 | suppresses the printing |
| 52 | of explanatory output |
| 53 | (from the commands |
| 54 | .IR e , |
| 55 | .IR E , |
| 56 | .IR r , |
| 57 | .IR w , |
| 58 | .I W |
| 59 | and |
| 60 | .IR wq ; |
| 61 | see below) and should be used with a script. |
| 62 | The |
| 63 | .B \-v |
| 64 | option will display a message of which mode (BSD or POSIX) |
| 65 | .I ed |
| 66 | as been set locally. This is useful for determining the described |
| 67 | behavior below. |
| 68 | .PP |
| 69 | .I Ed |
| 70 | performs all changes to a copy of the file which is contained in a \fBbuffer\fR. |
| 71 | For the changes to have an effect one of the write commands ( |
| 72 | .IR w , |
| 73 | .IR W , |
| 74 | .IR wq , |
| 75 | or |
| 76 | .IR Wq ) |
| 77 | must be issued. |
| 78 | .PP |
| 79 | The contents of the |
| 80 | .B buffer |
| 81 | can changed by issuing commands that are lead |
| 82 | by zero, one, or two addresses. All commands are alphabetically listed below |
| 83 | with their parameter structures if applicable; trailing structures not |
| 84 | described with commands are regarded as erroneous. Commands that |
| 85 | accept zero addresses regard the presence of any address as an error. |
| 86 | .PP |
| 87 | .I Ed |
| 88 | works in two modes: command, and input. The two modes are exclusive of |
| 89 | each other. While in command mode |
| 90 | .I ed |
| 91 | accepts commands that display, modify, or give information about the |
| 92 | .BR buffer . |
| 93 | While in input mode |
| 94 | .I ed |
| 95 | accepts lines of text to be added to the |
| 96 | .BR buffer . |
| 97 | .PP |
| 98 | Addressing in \fIed\fR specifies one or more lines contained in the |
| 99 | .BR buffer . |
| 100 | For commands that expect at least one address, and none are given, default |
| 101 | addresses will be used. |
| 102 | Using addresses in |
| 103 | .I ed |
| 104 | involves understanding that during the execution of most |
| 105 | .I ed |
| 106 | commands that a |
| 107 | .I "current line" |
| 108 | ( |
| 109 | .BR current ) |
| 110 | exists. |
| 111 | .B Current |
| 112 | (as a rule of thumb) is the location in the |
| 113 | .B buffer |
| 114 | that the last command issued affected; some |
| 115 | commands do not affect |
| 116 | .BR current . |
| 117 | Each command description (below) describes |
| 118 | its affects on |
| 119 | .B current |
| 120 | as the affect will vary depending under which compile option (BSD or POSIX) |
| 121 | .I ed |
| 122 | was compiled under. |
| 123 | Addresses can be divided into three cases: one |
| 124 | address (\fBsingle address\fR), two addresses (an \fBaddress pair\fR), |
| 125 | and special address forms. |
| 126 | |
| 127 | For the first two cases |
| 128 | an address is formed with the use of: |
| 129 | .TP |
| 130 | 1. |
| 131 | A positive decimal integer (e.g. 123) indicating a line number in the buffer. |
| 132 | Line number 1 is the first line in the buffer. |
| 133 | .TP |
| 134 | 2. |
| 135 | The `.' character indicating the current line (\fBcurrent\fR). |
| 136 | .TP |
| 137 | 3. |
| 138 | The `$' character which indicates the last line in the buffer. |
| 139 | .TP |
| 140 | 4. |
| 141 | A regular expression (RE) enclosed with `/'s as delimiters (i.e. /RE/). |
| 142 | This causes a forward search to the first occurrence of the specified RE. The |
| 143 | address will then become this line. |
| 144 | The character sequence \e/ escapes the forwardslash from being a |
| 145 | delimiter. |
| 146 | The search will wrap from the bottom of |
| 147 | the buffer to the top of the buffer if need be. |
| 148 | .I Ed |
| 149 | RE's are, outside of this document, now refered to as |
| 150 | .IR "basic regular expressions" . |
| 151 | Basic regular expressions (BRE's), traditionally described in \fIed(1)\fR are |
| 152 | now fully described in regex(1). BRE's are, for the most part, the same as |
| 153 | the old RE's - the name has changed and the expressions extended to meet |
| 154 | POSIX 1003.2 specifications. (See the search command for more details.) |
| 155 | .TP |
| 156 | 5. |
| 157 | A RE enclosed with `?'s as delimiters (i.e. ?RE?). |
| 158 | This will cause a backward search to the first occurrence of the |
| 159 | specified BRE. The address will then become this line. |
| 160 | The character sequence \e? escapes the questionmark from being a |
| 161 | delimiter. |
| 162 | The search will wrap |
| 163 | from the top of the buffer to the |
| 164 | bottom of the buffer if need be. (See the search command for more details.) |
| 165 | .TP |
| 166 | 6. |
| 167 | A line previously marked by the `k' command (see below). \fB`x\fR addresses |
| 168 | the line marked by the single lower-case letter `\fBx\fR' (from the |
| 169 | portable character set in the range a-z). |
| 170 | .TP |
| 171 | 7. |
| 172 | An address of the form 1-6 followed by a `+' followed by an integer number, |
| 173 | .BR n , |
| 174 | specifies the line to be addressed is |
| 175 | .B n |
| 176 | lines after the address of the form |
| 177 | 1-6. |
| 178 | If the address starts with a `+' then by default the addressed line is taken |
| 179 | with respect to |
| 180 | .B current |
| 181 | (equivalent to `.'\|; form 2). |
| 182 | If no integer number is given then 1 is added to the address. |
| 183 | Hence, if |
| 184 | more than one `+' is given in a sequence, with no integer number following, |
| 185 | 1 is added to the address for each `+'. Therefore, +++ is eqivalent to +3, |
| 186 | but +++1 is equivalent to +1. |
| 187 | .TP |
| 188 | 8. |
| 189 | An address of the form 1-6 followed by a `\-' followed by an integer number, |
| 190 | .BR n , |
| 191 | specifies the line to be addressed is |
| 192 | .B n |
| 193 | lines before the address of the form |
| 194 | 1-6. |
| 195 | If the address starts with a `\-' then by default the |
| 196 | addressed line is taken |
| 197 | with respect to |
| 198 | .B current |
| 199 | (`.'\|; form 1). |
| 200 | If no integer number is given then 1 is subtracted from the address. |
| 201 | Hence, if |
| 202 | more than one `\-' is given in a sequence, with no integer number following, |
| 203 | 1 is subtracted from the address for each `\-'. Therefore, \-\-\- |
| 204 | is eqivalent to \-3, |
| 205 | but \-\-\-1 is equivalent to \-1. |
| 206 | For backward compatibility `^' is the equivalent to `\-'. |
| 207 | .TP |
| 208 | 9. |
| 209 | A `,' (comma) may be used to separate two addresses of the form 1-8 to |
| 210 | create an \fBaddress pair\fR. |
| 211 | The first address must occur no later in |
| 212 | the buffer than the second address to be legal. |
| 213 | .TP |
| 214 | 10. |
| 215 | A `;' (semicolon) may be used to separate two addresses of the form 1-8 to |
| 216 | create an \fBaddress pair\fR. |
| 217 | With this form the second address is evaluated with respect to |
| 218 | and after the first address has been evaluated. This is useful when |
| 219 | addresses of the forms 2-8 are used. |
| 220 | The first address must occur no later in |
| 221 | the buffer than the second address to be legal. |
| 222 | .TP |
| 223 | NOTE: |
| 224 | Addresses of the forms 7 and 8 cannot be followed by addresses |
| 225 | of forms 2-6; it is an error. |
| 226 | .PP |
| 227 | The following are special address forms that cannot be combined |
| 228 | with any of the address forms listed above. |
| 229 | A `,' by itself represents the address pair `1,$'. |
| 230 | Likewise `%' by itself represents the address pair `1,$'. |
| 231 | A `;' by itself represents the address pair `.,$'. |
| 232 | .PP |
| 233 | The \fIed\fR commands listed below default to the addresses prefixing the |
| 234 | commands. Commands without default addresses accept zero addresses. |
| 235 | The parentheses with the default addresses are not part of |
| 236 | the address; they are used to show that the addresses are |
| 237 | default. |
| 238 | .PP |
| 239 | Generally only one command appears on a line at a time. |
| 240 | However, many of the commands may be suffixed by `l', `n', |
| 241 | or `p', in which case |
| 242 | the current line is printed |
| 243 | in the manner discussed below. |
| 244 | These suffixes may be combined in any order. |
| 245 | .TP 5 |
| 246 | .RB (\|.\|)\|a |
| 247 | .br |
| 248 | .ns |
| 249 | .TP 5 |
| 250 | <text> |
| 251 | .br |
| 252 | .ns |
| 253 | .TP 5 |
| 254 | .B . |
| 255 | .br |
| 256 | Append text after the addressed line. A `.' in the first column |
| 257 | followed immediately by a <newline> places |
| 258 | .I ed |
| 259 | back in command mode - the `.' is not included in the text. Line 0 |
| 260 | is legal for this command; text will be placed at the top of the buffer. |
| 261 | .B Current |
| 262 | is the last line appended (or the addressed line if no text given). |
| 263 | .TP 5 |
| 264 | .RB (\|.\|,\|.\|)\|c |
| 265 | .br |
| 266 | .ns |
| 267 | .TP 5 |
| 268 | <text> |
| 269 | .br |
| 270 | .ns |
| 271 | .TP 5 |
| 272 | .B . |
| 273 | .br |
| 274 | Change text on the addressed line(s). The addressed lines are deleted |
| 275 | before |
| 276 | .I |
| 277 | ed |
| 278 | is placed in input mode. A `.' in the first column |
| 279 | followed immediately by a <newline> places |
| 280 | .I ed |
| 281 | back in command mode - the `.' is not included in the text. |
| 282 | .B Current |
| 283 | is the new last line appended (or if no text is given the line after |
| 284 | the addressed line deleted). |
| 285 | .TP 5 |
| 286 | .RB (\|.\|,\|.\|)\|d |
| 287 | Delete the addressed line(s) from the buffer. Deleted lines may be |
| 288 | recovered with the undo command (\fIu\fR; see below). |
| 289 | .B |
| 290 | Current |
| 291 | is the line after the last addressed line deleted. |
| 292 | .TP 5 |
| 293 | e [filename] |
| 294 | Edit the new file `filename'. The |
| 295 | .B buffer |
| 296 | is cleared and the new file is placed in the |
| 297 | .BR buffer . |
| 298 | If the |
| 299 | .B buffer |
| 300 | has been modified since the last write command |
| 301 | .I ed |
| 302 | will issue a warning (`?'); a second issuing of |
| 303 | the command will be obeyed regardless. |
| 304 | The number of characters read is printed (unless -s is specified |
| 305 | at startup). If `filename' is missing, the remembered |
| 306 | name is used. |
| 307 | If `filename' is lead by ! then it shall be interpreted as a shell |
| 308 | command from which the output will be used as a non-remembered name. |
| 309 | Undo will not restore the |
| 310 | .B buffer |
| 311 | to its state before the edit command. |
| 312 | .B Current |
| 313 | is the last line in the |
| 314 | .B buffer |
| 315 | (`$'). |
| 316 | .TP 5 |
| 317 | E [filename] |
| 318 | .I E |
| 319 | works the same as |
| 320 | .I e |
| 321 | except if the buffer has been modified no warning is issued. |
| 322 | .TP 5 |
| 323 | f [filename] |
| 324 | Print the |
| 325 | .BR "remembered filename" . |
| 326 | If `filename' is specified the |
| 327 | .B "remembered filename" |
| 328 | will be set to `filename'. |
| 329 | If `filename' is lead by ! then it shall be interpreted as a shell |
| 330 | command from which the output will be used as a non-remembered name. |
| 331 | .B Current |
| 332 | is unchanged. |
| 333 | .TP 5 |
| 334 | (1,$)\|g/regular expression/command list |
| 335 | The global command first marks all lines matching |
| 336 | the regular expression. |
| 337 | For each matching line, the |
| 338 | command list is executed. At the start of each command list execution, |
| 339 | \fBcurrent\fR is set to equal that line; \fBcurrent\fR may change |
| 340 | as each command in the command list is executed for that line. |
| 341 | The first command of the command list begins on the same line as |
| 342 | the global command. |
| 343 | Generally, in the command list one command occupies a line. Thus to |
| 344 | have multiple commands in the command list it is necessary to escape the |
| 345 | <newline> at the end of each line so that the global command does not |
| 346 | interpret it as an indication that the command list entry has ended. |
| 347 | The <newline> is escaped by proceeding it with a backslash (\e). |
| 348 | Similarly with the commands that set \fIed\fR into input mode the <newlines> |
| 349 | of the entered text need to be escaped. If the `.' used to end input mode |
| 350 | is the last line of the command list the <newline> following the `.' need |
| 351 | not be escaped, or the `.' may be omitted entirely. |
| 352 | Commands in the command list can affect any line in the buffer. |
| 353 | For the behaviour of each \fIed\fR command within a command list refer to the |
| 354 | information on the individual command. |
| 355 | The commands |
| 356 | .IR g , |
| 357 | .IR G , |
| 358 | .IR v , |
| 359 | .IR V , |
| 360 | and \fI!\fR |
| 361 | are permitted in the command list, but should be used with caution. |
| 362 | The command list defaults to |
| 363 | .I p |
| 364 | if left empty (i.e. g/RE/p). |
| 365 | For the regular expression the delimiters can be any characters except |
| 366 | for <space> and <newline>; delimiters within a regular expression can |
| 367 | be escaped with a backslash preceeding it. |
| 368 | .TP 5 |
| 369 | (1,$)\|G/regular expression/ |
| 370 | .br |
| 371 | The interactive global command works similar to \fIg\fR. The first step |
| 372 | is to mark every line which matches the given regular expression. |
| 373 | For every line matched it will print this line, set \fBcurrent\fR |
| 374 | to this line, and accept one command (not including \fIa\fR, \fIc\fR, \fIi\fR, \fIg\fR, \fIG\fR, \fIv\fR, and \fIV\fR) |
| 375 | for execution. |
| 376 | The command can affect any line in the buffer. `%' by itself executes |
| 377 | the last non-null command. |
| 378 | A return by itself will act as a null command. \fBCurrent\fR |
| 379 | will be set to the last line affected by the last successful command |
| 380 | input. If no match or an input command error occurs \fBcurrent\fR |
| 381 | will be set to the last line searched by \fIG\fR. \fIG\fR can be prematurely |
| 382 | ended by `ctrl-C' (SIGINT). |
| 383 | |
| 384 | .TP 5 |
| 385 | h |
| 386 | .br |
| 387 | The help command displays a message explaining the most recent command |
| 388 | error (indicated by `?'). \fBCurrent\fR is unchanged. |
| 389 | .TP 5 |
| 390 | H |
| 391 | .br |
| 392 | This toggles on or off the automatic display of messages explaining |
| 393 | the most recent command error in place of `?'. \fBCurrent\fR is |
| 394 | unchanged. |
| 395 | .TP 5 |
| 396 | .RB (\|.\|)\|i |
| 397 | .TP 5 |
| 398 | <text> |
| 399 | .br |
| 400 | .TP 5 |
| 401 | .B . |
| 402 | .br |
| 403 | The insert command places |
| 404 | .I ed |
| 405 | in input mode with the text being placed before the |
| 406 | addressed line. Line 0 is invalid for this command. |
| 407 | A `.' in the first column |
| 408 | followed immediately by a return places |
| 409 | .I ed |
| 410 | back in command mode - the `.' is not included in the text. |
| 411 | .B Current |
| 412 | is the last line inserted. If no text is inserted then |
| 413 | .B current |
| 414 | is the addressed when |
| 415 | .I ed |
| 416 | is compiled for POSIX; compiled for BSD, |
| 417 | .B current |
| 418 | is the addressed line -1. |
| 419 | .TP 5 |
| 420 | .RB (\|.\|,\|.+1)\|j |
| 421 | The join command joins the addressed lines together to make one |
| 422 | line. If no addresses are specified |
| 423 | .B current |
| 424 | and |
| 425 | .BR current +1 |
| 426 | lines are joined. |
| 427 | If one address only is given then |
| 428 | no join is performed. |
| 429 | .B Current |
| 430 | becomes that line if |
| 431 | .I ed |
| 432 | has been compiled under the BSD option; if compiled under the POSIX |
| 433 | option |
| 434 | .B current |
| 435 | is unchanged. |
| 436 | .TP 5 |
| 437 | ( \fB. \fR)\|k\fBx\fR |
| 438 | The mark command marks the addressed line with label |
| 439 | .BR x , |
| 440 | where |
| 441 | .B x |
| 442 | is a lowercase letter from the portable character set (a-z). |
| 443 | The address form \fB`x\fR will refer to |
| 444 | this line (address form 6 above). |
| 445 | .B Current |
| 446 | is unchanged. |
| 447 | .TP 5 |
| 448 | .RB (\|.\|,\|.\|)\|l |
| 449 | The list command |
| 450 | prints the addressed lines in an unambiguous way: |
| 451 | non-graphic characters are |
| 452 | printed in three-digit octal preceded by a \e |
| 453 | unless they are one of the following in which case they will be printed |
| 454 | as indicated in the brackets: |
| 455 | backslash (`\e\\'), |
| 456 | horizontal tab (\et), form feed (\ef). |
| 457 | return (\er), vertical tab (\ev), and backspace (\eb). |
| 458 | Long lines will be broken base on the type of terminal currently in |
| 459 | use. |
| 460 | .B Current |
| 461 | is set to the last line printed. |
| 462 | The |
| 463 | .I l |
| 464 | command may be placed on the same line after any |
| 465 | command except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). |
| 466 | .TP 5 |
| 467 | .RB (\|.\|,\|.\|)\|m\fBa\fR |
| 468 | The move command moves the addressed lines in the buffer |
| 469 | to after the address |
| 470 | .BR a . |
| 471 | Line 0 is valid for this command. |
| 472 | .B Current |
| 473 | is the location in the |
| 474 | .B buffer |
| 475 | of the last line moved. |
| 476 | .TP 5 |
| 477 | .RB (\|.\|,\|.\|)\|n |
| 478 | The number command prints the addressed lines preceding the text with the line number. |
| 479 | The |
| 480 | .I n |
| 481 | command |
| 482 | may |
| 483 | be placed on the same line after any command |
| 484 | except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). |
| 485 | .B Current |
| 486 | is the last line printed. |
| 487 | .TP 5 |
| 488 | .RB (\|.\|,\|.\|)\|p |
| 489 | The print command prints the addressed lines. |
| 490 | The |
| 491 | .I p |
| 492 | command |
| 493 | may |
| 494 | be placed on the same line after any command |
| 495 | except (\fIe\fR, \fIE\fR, \fIf\fR, \fIq\fR, \fIQ\fR, \fIr\fR, \fIw\fR, \fIW\fR, or \fI!\fR). |
| 496 | .B Current |
| 497 | is the last line printed. |
| 498 | .TP |
| 499 | .RB (\|.\|,\|.\|)\|P |
| 500 | This command is a synonym for |
| 501 | .I p |
| 502 | if |
| 503 | .I ed |
| 504 | has been compiled under the BSD option. If |
| 505 | .I ed |
| 506 | has been compiled under the POSIX option then the prompt is toggled on or off. |
| 507 | .B Current |
| 508 | is unchanged when compiled under the POSIX option. |
| 509 | The default prompt is "*" if not specified with the \-p option at startup. |
| 510 | The prompt is initially off unless the \-p option is specified. |
| 511 | .TP 5 |
| 512 | q |
| 513 | The quit command causes |
| 514 | .I ed |
| 515 | to exit. If the |
| 516 | .B buffer |
| 517 | has been modified since the last write command |
| 518 | .I ed |
| 519 | will |
| 520 | issue a warning once (`?'); a second issuing of the command will be obeyed |
| 521 | regardless. |
| 522 | .TP 5 |
| 523 | Q |
| 524 | .I Q |
| 525 | works the same as |
| 526 | .I q |
| 527 | except if the buffer has been modified no warning is issued. |
| 528 | .TP 5 |
| 529 | ($)\|r [filename] |
| 530 | The read command reads in the file `filename' after the |
| 531 | addressed line. If no `filename' is specified then the |
| 532 | .B "remembered filename" |
| 533 | is used. Address 0 is valid for this command. |
| 534 | If read is successful then the number of characters |
| 535 | read is printed (unless the -s option is specified). |
| 536 | If `filename' is lead by ! then it shall be interpreted as a shell |
| 537 | command from which the output will be used as a non-remembered name. |
| 538 | .B Current |
| 539 | is the last line read. |
| 540 | .TP 5 |
| 541 | (\| \fB.\fR\|, \fB.\fR\|)\|s/regular expression/\fBreplacement\fR/\fBflags\fR |
| 542 | .br |
| 543 | The substitute command searches for the regular expression in the |
| 544 | addressed lines. |
| 545 | On each line in which a match is found, |
| 546 | matched strings are replaced by the \fBreplacement\fR as specified |
| 547 | by the \fBflags\fR (see below). |
| 548 | If no \fBflags\fR appear, by default only the first occurrence |
| 549 | of the matched string in each line is replaced. |
| 550 | It is an error if no matches to the RE occur. |
| 551 | .IP |
| 552 | The delimiters may be any character except <space> or <newline>. |
| 553 | The delimiter lead by a \e will escape it to be a literal |
| 554 | in the RE or |
| 555 | .BR replacement . |
| 556 | .IP |
| 557 | An ampersand, `&', appearing in the replacement |
| 558 | will equal the string matching the RE. |
| 559 | The `&'s special meaning is supressable by leading |
| 560 | it with a `\e'. |
| 561 | When `%' is the only replacement character in |
| 562 | .B replacement |
| 563 | the most recent |
| 564 | replacement is used. |
| 565 | The `%'s special meaning is supressable by leading |
| 566 | it with a `\e'. |
| 567 | .IP |
| 568 | The characters `\fB\en\fR' (where \fBn\fR is a digit 1-9) is |
| 569 | replaced by the text matching the RE subexpression |
| 570 | .B n |
| 571 | (known as backreferencing). |
| 572 | .I S |
| 573 | may be used to break lines by including a <newline> in |
| 574 | .B replacement |
| 575 | preceeded by a backslash (`\e') to escape it. |
| 576 | .B Replacement |
| 577 | can continue on the next line and can include another escaped <newline>. |
| 578 | .IP |
| 579 | The following extention should not be included in portable scripts. |
| 580 | When spliting lines using \fIs\fR with the global commands (\fIg\fR, |
| 581 | \fIG\fR, \fIv\fR, or \fIV\fR) the new-line in the replacement string |
| 582 | must be escaped by preceding it with `\e\e\e' (three adjacent `\e'\|s \- |
| 583 | the first \e escapes the second \e so that it is passed to \fIs\fR |
| 584 | to escape the <newline>). |
| 585 | .IP |
| 586 | The \fBflags\fR may be any combination of: |
| 587 | .RS |
| 588 | .IP \fIcount\fR |
| 589 | in each addressed line replace the \fIcount\fR\-th matching occurrence. |
| 590 | .IP g |
| 591 | in each addressed line replace all matching occurrences. When \fIcount\fR and |
| 592 | g are specified together inclusively replace in each addressed line |
| 593 | all matches from the \fIcount\fR\-th match to the end of line. |
| 594 | .IP l |
| 595 | write the line after replacement in the manner specified by the \fIl\fR |
| 596 | command. |
| 597 | .IP n |
| 598 | write the line after replacement in the manner specified by the \fIn\fR |
| 599 | command. |
| 600 | .IP p |
| 601 | write the line after replacement in the manner specified by the \fIp\fR |
| 602 | command. |
| 603 | .RE |
| 604 | .IP |
| 605 | The following special form |
| 606 | should not be included in portable scripts. |
| 607 | This form is maintained for backward compatibility and |
| 608 | is extended to dovetail into the above forms of |
| 609 | .BR s . |
| 610 | .I S |
| 611 | followed by |
| 612 | .I no |
| 613 | delimiters |
| 614 | repeats the most recent substitute command |
| 615 | on the addressed lines. |
| 616 | .I S |
| 617 | may be suffixed with the letters |
| 618 | .BR r " (use the most recent RE rather than the last RE used with \fIs\fR)," |
| 619 | .B p |
| 620 | (complement the setting of the |
| 621 | any print command (l, n, p) |
| 622 | suffix from the previous substitution), |
| 623 | .B g |
| 624 | (complement the setting of the |
| 625 | .I g |
| 626 | suffix) or |
| 627 | .B N |
| 628 | (negate the previous \fIcount\fR flag). |
| 629 | These modifying letters may be combined in any order |
| 630 | (N.B. multiple use of the modifying letters may cause them |
| 631 | to be interpreted as delimiters). |
| 632 | .IP |
| 633 | .B Current |
| 634 | is set to the last line search (BSD) or where the last replacement |
| 635 | occurred (POSIX). |
| 636 | .TP 5 |
| 637 | .RB (\|.\|,\|.\|)\|t\|\fBa\fR |
| 638 | The transcribe command copies the addressed lines in |
| 639 | the |
| 640 | .B buffer |
| 641 | to after the address |
| 642 | .BR a . |
| 643 | Address 0 is valid for this command. |
| 644 | .B Current |
| 645 | is the last line transcribed. |
| 646 | .TP 5 |
| 647 | .RB (\|.\|,\|.\|)\|u |
| 648 | The undo command nullifies the most recent |
| 649 | .B buffer |
| 650 | modifying command. |
| 651 | Buffer modifying commands undo works on are |
| 652 | .IR a , |
| 653 | .IR c , |
| 654 | .IR d , |
| 655 | .IR g , |
| 656 | .IR G , |
| 657 | .IR i , |
| 658 | .IR j , |
| 659 | .IR m , |
| 660 | .IR r , |
| 661 | .IR s , |
| 662 | .IR t , |
| 663 | .IR u , |
| 664 | .IR v , |
| 665 | and |
| 666 | .I V. |
| 667 | Marks set by the \fIk\fR command will also be restored. |
| 668 | All commands (including nested \fIg\fR, \fIG\fR, \fIv\fR, and |
| 669 | \fIV\fR commands within the \fIg\fR or \fIv\fR) |
| 670 | that undo works on are treated as a single buffer modification. |
| 671 | \fBCurrent\fR is set to the line it addressed before the last |
| 672 | buffer modification. |
| 673 | .TP 5 |
| 674 | (1, $)\|v/regular expression/command list |
| 675 | The global non-matching command performs as the |
| 676 | .I g |
| 677 | command does except that the command list is executed for every line |
| 678 | that does not match the RE. |
| 679 | .TP 5 |
| 680 | (1, $)\|V/regular expression/ |
| 681 | The interactive global non-matching command is the same as the |
| 682 | .I G |
| 683 | except that one command will be accepted as input |
| 684 | with \fBcurrent\fR initially set to every line |
| 685 | that does not match the RE. |
| 686 | .TP 5 |
| 687 | (1, $)\|w [filename] |
| 688 | .br |
| 689 | The write command writes the addressed lines to the file `filename'. |
| 690 | If no `filename' is specified then the |
| 691 | .B "remembered filename" |
| 692 | is used. If no addresses are specified the whole |
| 693 | .B buffer |
| 694 | is written. |
| 695 | If the command is successful, the number of characters written is |
| 696 | printed (unless the -s option is specified). |
| 697 | If `filename' is lead by ! then it shall be interpreted as a shell |
| 698 | command from which the output will be used as a non-remembered name. |
| 699 | \fBCurrent\fR is unchanged. |
| 700 | .TP |
| 701 | (1, $)\|W [filename] |
| 702 | .I W |
| 703 | works as the |
| 704 | .I w |
| 705 | command does except the addressed contents of the |
| 706 | .B buffer |
| 707 | are appended to `filename' (or the |
| 708 | .B "remember filename" |
| 709 | if `filename' is not specified). |
| 710 | \fBCurrent\fR is unchanged. |
| 711 | .TP 5 |
| 712 | (1, $)\|wq [filename] |
| 713 | .I wq |
| 714 | works as the |
| 715 | .I w |
| 716 | command does with the addition that |
| 717 | .I ed |
| 718 | exits immediately after the write is complete. |
| 719 | \fBCurrent\fR is unchanged. |
| 720 | .TP 5 |
| 721 | (1,$)\|Wq [filename] |
| 722 | .I Wq |
| 723 | works as the |
| 724 | .I W |
| 725 | command does with the addition that |
| 726 | .I ed |
| 727 | exits immediately after the write is complete. |
| 728 | \fBCurrent\fR is unchanged. |
| 729 | .TP 5 |
| 730 | .RB (\|.\|+1)\|z\ \ \ \ or, |
| 731 | .br |
| 732 | .TP 5 |
| 733 | .RB (\|.\|+1)\|z\fBn\fR |
| 734 | Scroll through the |
| 735 | .BR buffer . |
| 736 | Starting from the addressed line (or |
| 737 | .BR current +1) |
| 738 | print the next 22 (by default or |
| 739 | .BR n ) |
| 740 | lines. The |
| 741 | .B n |
| 742 | is a sticky value; it becomes the default number of lines printed |
| 743 | for successive scrolls. |
| 744 | .B Current |
| 745 | is the last line printed. |
| 746 | .TP 5 |
| 747 | ($)\|= |
| 748 | Print the number of lines in the |
| 749 | .BR buffer . |
| 750 | If an address is provided (in the forms 1-8 above) then the line number |
| 751 | for that line will be printed. |
| 752 | \fBCurrent\fR is unchanged. |
| 753 | .TP 5 |
| 754 | !<shell command> |
| 755 | The command after the |
| 756 | .I ! |
| 757 | is executed by \fIsh(1)\fR and the results are printed. A `!' is |
| 758 | printed in the first column when execution has completed (unless the -s |
| 759 | option has been specified). |
| 760 | A `!' after \fI!\fR repeats the last shell command. An unescaped `%' |
| 761 | represents the remembered pathname. |
| 762 | \fBCurrent\fR is unchanged. |
| 763 | .TP 5 |
| 764 | /regular expression/\|\|\|\|\|or, |
| 765 | .br |
| 766 | .TP 5 |
| 767 | ?regular expression? |
| 768 | .br |
| 769 | The search command searches forward, `/', (or backward, `?') through the |
| 770 | .B buffer |
| 771 | attempting to find |
| 772 | a line that matches the RE. The search will wrap to the top (or bottom) |
| 773 | of the |
| 774 | .B buffer |
| 775 | if necessary. Search returns the line number that the match occurs on - |
| 776 | combined with the null command (see below) this causes the line to be printed. |
| 777 | .B Current |
| 778 | is the matching line. |
| 779 | .TP 5 |
| 780 | .RB (\|.+1,\|.+1)\|<newline> |
| 781 | .br |
| 782 | The null command is equivalent to asking for the line |
| 783 | .BR current +1 |
| 784 | to be printed according to the |
| 785 | .I p |
| 786 | command. This is a useful command to quickly print the next couple of |
| 787 | lines. If more than a couple of lines are needed the |
| 788 | .I z |
| 789 | command (see above) is much better to use. |
| 790 | \fBCurrent\fR is the last line printed. |
| 791 | |
| 792 | .SH OTHER |
| 793 | .PP |
| 794 | If an interrupt signal (SIGINT)\| is sent, |
| 795 | .I ed |
| 796 | prints `?' |
| 797 | and returns to command mode. |
| 798 | .PP |
| 799 | BSD command pairs (pp, ll, etc.) are permitted. Additionally any single |
| 800 | print command may follow any of the non-I/O commands (I/O commands: |
| 801 | e, E, f, r, w, W, wq, and !). This will cause the current line to be |
| 802 | printed in the specified manner after the command has completed. |
| 803 | .PP |
| 804 | Previous limitations on the number of characters per line and per command |
| 805 | list have been lifted; there is now no maximum. |
| 806 | File name and path length is restricted to the maximum length that |
| 807 | the current file system supports. |
| 808 | The |
| 809 | .I undo |
| 810 | command now restores marks to affected lines. |
| 811 | The temporary buffer method will vary dependent on the method selected at |
| 812 | compile. Two methods work with a temporary file (stdio and db), while the |
| 813 | third uses memory. |
| 814 | The limit on the number of lines depends on the amount of memory. |
| 815 | .SH FILES |
| 816 | /tmp/_bsd44_ed* |
| 817 | .br |
| 818 | .XP |
| 819 | ed.hup: the buffer is written to this file in the current |
| 820 | directory if possible and in the HOME directory is not |
| 821 | (if the signal SIGHUP (hangup) is received). |
| 822 | .SH "SEE ALSO" |
| 823 | B. W. Kernighan, |
| 824 | .I |
| 825 | A Tutorial Introduction to the ED Text Editor |
| 826 | .br |
| 827 | B. W. Kernighan, |
| 828 | .I |
| 829 | Advanced editing on UNIX |
| 830 | .br |
| 831 | regex(7), sed(1), learn(1), ex(1), POSIX 1003.2 (4.20) |
| 832 | .SH "AUTHOR" |
| 833 | Rodney Ruddock |
| 834 | .SH DIAGNOSTICS |
| 835 | `?name' for a file that is either inaccessible, does not exist, or is |
| 836 | a directory. `?' |
| 837 | for all other errors unless the help messages have been toggled on (with |
| 838 | the H command) in which case a descriptive message will be printed. |
| 839 | .PP |
| 840 | All NULL characters are ignored during input from the user or files. |
| 841 | EOF is treated as a newline so that characters after the last <newline> |
| 842 | are included into the \fBbuffer\fR. |
| 843 | .PP |
| 844 | .I Ed |
| 845 | returns 0 on successful completion. A value >0 is returned |
| 846 | when an \fIed\fR command failed. |
| 847 | .SH NOTES |
| 848 | .PP |
| 849 | Regular expressions are now described on regex(7). |
| 850 | .I Ed |
| 851 | follows basic regular expressions (BRE's) as described on regex(7). |
| 852 | BRE's, for the most part, are the same as previous |
| 853 | .I ed |
| 854 | RE's. The changes to the RE's are extension for internationalization |
| 855 | under POSIX 1003.2. Old scripts with RE's should work without |
| 856 | modification. |
| 857 | .PP |
| 858 | The special form of substitute has been maintained for backward |
| 859 | compatability and should not be used in scripts if they are to |
| 860 | portable. |
| 861 | .PP |
| 862 | Help messages may appear ambiguous to beginners - particularly when BRE's |
| 863 | form part of the command. |
| 864 | .PP |
| 865 | For backward compatability, when more addresses are provided |
| 866 | than required by a command the one or two addresses closest to the |
| 867 | command are used (depending on how may addresses the command accepts). |
| 868 | Portable scripts should not rely on this feature. |
| 869 | .PP |
| 870 | For backward compatibility the option `-' is |
| 871 | equivalent to the `-s' option at the startup of |
| 872 | .IR ed . |