Commit | Line | Data |
---|---|---|
dd9e2e8d CL |
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. | |
fd315f2c | 4 | .\" |
1c15e888 | 5 | .\" @(#)ed.1 6.5.1.1 (Berkeley) 10/21/90 |
b5dc1377 | 6 | .\" |
1c15e888 | 7 | .Dd October 21, 1990 |
b5dc1377 CL |
8 | .Dt ED 1 |
9 | .Os ATT 7th | |
fd315f2c KM |
10 | .if t .ds q \(aa |
11 | .if n .ds q ' | |
b5dc1377 CL |
12 | .Sh NAME |
13 | .Nm ed | |
14 | .Nd text editor | |
15 | .Sh SYNOPSIS | |
16 | .Nm ed | |
17 | .Op Fl | |
b5dc1377 CL |
18 | .Op Ar file |
19 | .Sh DESCRIPTION | |
20 | .Nm Ed | |
fd315f2c | 21 | is the standard text editor. |
b5dc1377 | 22 | .Pp |
fd315f2c | 23 | If a |
b5dc1377 | 24 | .Ar file |
fd315f2c | 25 | argument is given, |
b5dc1377 | 26 | .Nm ed |
fd315f2c | 27 | simulates an |
b5dc1377 CL |
28 | .Ic e |
29 | command (see below) on the named file; that is to say, | |
fd315f2c | 30 | the file is read into |
b5dc1377 | 31 | .Nm ed 's |
fd315f2c | 32 | buffer so that it can be edited. |
5325ced3 | 33 | .Tw Ds |
b5dc1377 CL |
34 | .Tp Fl |
35 | Suppresses the printing | |
fd315f2c KM |
36 | of explanatory output |
37 | and should be used | |
38 | when the standard input is | |
39 | an editor script. | |
b5dc1377 CL |
40 | .Tp |
41 | .Pp | |
42 | .Nm Ed | |
fd315f2c KM |
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 | |
b5dc1377 CL |
45 | .Ic w |
46 | (write) command is given. | |
fd315f2c | 47 | The copy of the text being edited resides |
b5dc1377 CL |
48 | in a temporary file called the |
49 | .Ar buffer . | |
50 | .Pp | |
fd315f2c | 51 | Commands to |
b5dc1377 | 52 | .Nm ed |
fd315f2c KM |
53 | have a simple and regular structure: zero or |
54 | more | |
b5dc1377 | 55 | .Ar addresses |
fd315f2c | 56 | followed by a single character |
b5dc1377 | 57 | .Ar command , |
fd315f2c KM |
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. | |
b5dc1377 | 62 | .Pp |
fd315f2c | 63 | In general, only one command may appear on a line. |
b5dc1377 | 64 | Certain commands allow the |
fd315f2c KM |
65 | addition of text to the buffer. |
66 | While | |
b5dc1377 | 67 | .Nm ed |
fd315f2c KM |
68 | is accepting text, it is said |
69 | to be in | |
b5dc1377 | 70 | .Ar input mode . |
fd315f2c KM |
71 | In this mode, no commands are recognized; |
72 | all input is merely collected. | |
b5dc1377 CL |
73 | Input mode is left by typing a period |
74 | .Sq Ic \&. | |
75 | alone at the | |
fd315f2c | 76 | beginning of a line. |
b5dc1377 CL |
77 | .Pp |
78 | .Nm Ed | |
fd315f2c | 79 | supports a limited form of |
b5dc1377 | 80 | .Ar regular expression |
fd315f2c KM |
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 | |
b5dc1377 | 85 | .Ar matched |
fd315f2c KM |
86 | by the regular expression. |
87 | In the following specification for regular expressions | |
88 | the word `character' means any character but newline. | |
b5dc1377 CL |
89 | .Tw Ds |
90 | .Tp 1. | |
fd315f2c KM |
91 | Any character except a special character |
92 | matches itself. | |
93 | Special characters are | |
94 | the regular expression delimiter plus | |
5325ced3 | 95 | .Sq Cm \e\[. |
b5dc1377 | 96 | and sometimes |
5325ced3 | 97 | .Sq Cm ^*$ . |
b5dc1377 | 98 | .Tp 2. |
fd315f2c | 99 | A |
5325ced3 | 100 | .Sq Cm \&. |
fd315f2c | 101 | matches any character. |
b5dc1377 CL |
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. | |
fd315f2c | 109 | A nonempty string |
b5dc1377 CL |
110 | .Op Ar s |
111 | or | |
5325ced3 | 112 | .Oo |
b5dc1377 | 113 | .Cx \&( |
5325ced3 | 114 | .Op Cm \&^ Ar s |
b5dc1377 CL |
115 | .Cx \&) |
116 | .Cx | |
5325ced3 | 117 | .Oo |
fd315f2c | 118 | matches any character in (or not in) |
b5dc1377 CL |
119 | .Ar s . |
120 | In | |
121 | .Ar s , | |
122 | .Sq Li \e | |
123 | has no special meaning, and | |
124 | may only appear as | |
fd315f2c | 125 | the first letter. |
b5dc1377 CL |
126 | A substring |
127 | .Ar a\-b , | |
fd315f2c | 128 | with |
b5dc1377 | 129 | .Ar a |
fd315f2c | 130 | and |
b5dc1377 | 131 | .Ar b |
fd315f2c KM |
132 | in ascending ASCII order, stands for the inclusive |
133 | range of ASCII characters. | |
b5dc1377 CL |
134 | .Tp 5. |
135 | A regular expression of form 1\-4 followed by * matches a sequence of | |
fd315f2c | 136 | 0 or more matches of the regular expression. |
b5dc1377 | 137 | .Tp 6. |
fd315f2c | 138 | A regular expression, |
b5dc1377 CL |
139 | .Ar x , |
140 | of form 1\-8, bracketed | |
141 | .Cx Li \e( | |
142 | .Ar x | |
143 | .Li \e) | |
144 | .Cx | |
fd315f2c | 145 | matches what |
b5dc1377 | 146 | .Ar x |
fd315f2c | 147 | matches. |
b5dc1377 CL |
148 | .Tp 7. |
149 | A \e followed by a digit | |
150 | .Ar n | |
fd315f2c KM |
151 | matches a copy of the string that the |
152 | bracketed regular expression beginning with the | |
b5dc1377 CL |
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 | |
fd315f2c | 163 | matches a match for |
b5dc1377 | 164 | .Ar x |
fd315f2c | 165 | followed by a match for |
b5dc1377 | 166 | .Ar y , |
fd315f2c | 167 | with the |
b5dc1377 | 168 | .Ar x |
fd315f2c | 169 | match being as long as possible while still permitting a |
b5dc1377 | 170 | .Ar y |
fd315f2c | 171 | match. |
b5dc1377 CL |
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 | |
fd315f2c | 178 | begin at the left (or end at the right) end of a line. |
b5dc1377 CL |
179 | .Tp 10. |
180 | A regular expression of form 1\-9 picks out the | |
fd315f2c | 181 | longest among the leftmost matches in a line. |
b5dc1377 | 182 | .Tp 11. |
fd315f2c KM |
183 | An empty regular expression stands for a copy of the |
184 | last regular expression encountered. | |
b5dc1377 CL |
185 | .Tp |
186 | .Pp | |
fd315f2c KM |
187 | Regular expressions are used in addresses to specify |
188 | lines and in one command | |
189 | (see | |
b5dc1377 CL |
190 | .Ar s |
191 | below) | |
fd315f2c KM |
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 | |
b5dc1377 CL |
195 | character, that character may be preceded by |
196 | .Sq Li \e . | |
fd315f2c | 197 | This also applies to the character bounding the regular |
b5dc1377 CL |
198 | expression (often |
199 | .Sq Li \&/ ) | |
200 | and to | |
201 | .Sq Li \e | |
202 | itself. | |
203 | .Pp | |
fd315f2c | 204 | To understand addressing in |
b5dc1377 | 205 | .Nm ed |
fd315f2c | 206 | it is necessary to know that at any time there is a |
b5dc1377 | 207 | .Ar current line. |
fd315f2c KM |
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. | |
b5dc1377 CL |
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. | |
fd315f2c | 227 | A decimal number |
b5dc1377 | 228 | .Ar n |
fd315f2c | 229 | addresses the |
b5dc1377 CL |
230 | .Cx Ar n |
231 | .Cx \'th | |
232 | .Cx | |
fd315f2c | 233 | line of the buffer. |
b5dc1377 CL |
234 | .Tp 4. |
235 | .Cx `\(fm | |
236 | .Ar x | |
237 | .Cx \' | |
238 | .Cx | |
239 | addresses the line marked with the name | |
240 | .Ar x , | |
fd315f2c KM |
241 | which must be a lower-case letter. |
242 | Lines are marked with the | |
b5dc1377 | 243 | .Ar k |
fd315f2c | 244 | command described below. |
b5dc1377 CL |
245 | .Tp 5. |
246 | A regular expression enclosed in slashes | |
247 | .Cx ` | |
248 | .Li / | |
249 | .Cx \' | |
250 | .Cx | |
251 | addresses | |
fd315f2c KM |
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. | |
b5dc1377 CL |
257 | .Tp 6. |
258 | A regular expression enclosed in queries | |
259 | .Cx ` | |
260 | .Li ? | |
261 | .Cx \' | |
262 | .Cx | |
263 | addresses | |
fd315f2c KM |
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. | |
b5dc1377 CL |
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. | |
fd315f2c | 282 | The plus sign may be omitted. |
b5dc1377 CL |
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 | |
fd315f2c | 294 | the addition or subtraction is taken with respect to the current line; |
b5dc1377 CL |
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 | |
fd315f2c KM |
316 | then 1 is added (resp. subtracted). |
317 | As a consequence of this rule and rule 8, | |
b5dc1377 CL |
318 | the address |
319 | .Cx ` | |
320 | .Li \- | |
321 | .Cx \' | |
322 | .Cx | |
323 | refers to the line before the current line. | |
fd315f2c KM |
324 | Moreover, |
325 | trailing | |
b5dc1377 CL |
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 | |
fd315f2c | 342 | line less 2. |
b5dc1377 | 343 | .Tp 10. |
fd315f2c | 344 | To maintain compatibility with earlier versions of the editor, |
b5dc1377 CL |
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 | |
fd315f2c KM |
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, | |
b5dc1377 CL |
364 | the last one or two (depending on what is accepted) are used. |
365 | .Pp | |
fd315f2c | 366 | Addresses are separated from each other typically by a comma |
b5dc1377 CL |
367 | .Cx ` |
368 | .Li , | |
369 | .Cx \' | |
370 | .Cx | |
fd315f2c | 371 | They may also be separated by a semicolon |
b5dc1377 CL |
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 | |
fd315f2c KM |
383 | the previous address before the next address is interpreted. |
384 | This feature can be used to determine the starting | |
b5dc1377 CL |
385 | line for forward and backward searches |
386 | .Cx \&(` | |
387 | .Li / | |
388 | .Cx \' | |
389 | .Cx | |
390 | .Cx ` | |
391 | .Li ? | |
392 | .Cx \'). | |
393 | .Cx | |
fd315f2c KM |
394 | The second address of any two-address sequence |
395 | must correspond to a line following the line corresponding to the first address. | |
b5dc1377 CL |
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 | |
fd315f2c | 407 | In the following list of |
b5dc1377 | 408 | .Nm ed |
fd315f2c KM |
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. | |
b5dc1377 | 414 | .Pp |
fd315f2c KM |
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. | |
b5dc1377 CL |
426 | .Tw Ds |
427 | .Tp Cx \&( | |
428 | .Ic . | |
429 | .Cx \&) | |
430 | .Ic a | |
431 | .Cx | |
432 | .Tp <text> | |
433 | .Tp Ic \&. | |
fd315f2c KM |
434 | The append command reads the given text |
435 | and appends it after the addressed line. | |
b5dc1377 CL |
436 | .Sq Ic \&. |
437 | is left | |
fd315f2c KM |
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. | |
b5dc1377 CL |
442 | .Tp Cx \&( |
443 | .Ic \&. | |
444 | .Cx \&, | |
445 | .Ic \&. | |
446 | .Cx \&) | |
447 | .Ic \&c | |
448 | .Cx | |
449 | .Tp <text> | |
450 | .Tp Ic \&. | |
fd315f2c KM |
451 | The change |
452 | command deletes the addressed lines, then accepts input | |
453 | text which replaces these lines. | |
b5dc1377 CL |
454 | .Sq Ic \&. |
455 | is left at the last line input; if there were none, | |
fd315f2c | 456 | it is left at the line preceding the deleted lines. |
b5dc1377 CL |
457 | .Tp Cx \&( |
458 | .Ic \&. | |
459 | .Cx \&, | |
460 | .Ic \&. | |
461 | .Cx \&) | |
462 | .Ic \&d | |
463 | .Cx | |
fd315f2c KM |
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. | |
b5dc1377 CL |
468 | .Tp Cx Ic \&e |
469 | .Cx \&\ \& | |
470 | .Ar filename | |
471 | .Cx | |
fd315f2c KM |
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. | |
b5dc1377 CL |
475 | .Sq Ic \&. |
476 | is set to the last line of the buffer. | |
fd315f2c | 477 | The number of characters read is typed. |
b5dc1377 CL |
478 | .Ar filename |
479 | is remembered for possible use as a default file name | |
fd315f2c | 480 | in a subsequent |
b5dc1377 | 481 | .Ic r |
fd315f2c | 482 | or |
b5dc1377 | 483 | .Ic w |
fd315f2c | 484 | command. |
b5dc1377 CL |
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 | |
fd315f2c | 492 | This command is the same as |
b5dc1377 | 493 | .Ic e , |
fd315f2c | 494 | except that no diagnostic results when no |
b5dc1377 | 495 | .Ic w |
fd315f2c | 496 | has been given since the last buffer alteration. |
b5dc1377 CL |
497 | .Tp Cx Ic f |
498 | .Cx \&\ \& | |
499 | .Ar filename | |
500 | .Cx | |
fd315f2c | 501 | The filename command prints the currently remembered file name. |
b5dc1377 CL |
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 | |
fd315f2c KM |
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 | |
b5dc1377 CL |
519 | given command list is executed with |
520 | .Cx ` | |
521 | .Ic \&. | |
522 | .Cx \' | |
523 | .Cx | |
524 | initially set to that line. | |
fd315f2c KM |
525 | A single command or the first of multiple commands |
526 | appears on the same line with the global command. | |
b5dc1377 CL |
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, | |
fd315f2c | 534 | and |
b5dc1377 | 535 | .Ic c |
fd315f2c | 536 | commands and associated input are permitted; |
b5dc1377 CL |
537 | the |
538 | .Cx ` | |
539 | .Ic \&. | |
540 | .Cx \' | |
541 | .Cx | |
542 | terminating input mode may be omitted if it would be on the | |
fd315f2c KM |
543 | last line of the command list. |
544 | The commands | |
b5dc1377 | 545 | .Ic g |
fd315f2c | 546 | and |
b5dc1377 | 547 | .Ic v |
fd315f2c | 548 | are not permitted in the command list. |
b5dc1377 CL |
549 | .Tp Cx \&( |
550 | .Ic . | |
551 | .Cx \&) | |
552 | .Ic i | |
553 | .Cx | |
554 | .Tp <text> | |
555 | .Tp Ic \&. | |
fd315f2c | 556 | This command inserts the given text before the addressed line. |
b5dc1377 CL |
557 | .Cx ` |
558 | .Ic \&. | |
559 | .Cx \' | |
560 | .Cx | |
561 | is left at the last line input, or, if there were none, | |
fd315f2c KM |
562 | at the line before the addressed line. |
563 | This command differs from the | |
b5dc1377 | 564 | .Ic a |
fd315f2c KM |
565 | command only in the placement of the |
566 | text. | |
b5dc1377 CL |
567 | .Tp Cx \&( |
568 | .Ic \&. | |
569 | .Cx \&, | |
570 | .Ic \&.+1 | |
571 | .Cx \&) | |
572 | .Ic \&j | |
573 | .Cx | |
fd315f2c KM |
574 | This command joins the addressed lines into a single line; |
575 | intermediate newlines simply disappear. | |
b5dc1377 CL |
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 | |
fd315f2c KM |
587 | The mark command marks the addressed line with |
588 | name | |
b5dc1377 | 589 | .Ar x , |
fd315f2c | 590 | which must be a lower-case letter. |
b5dc1377 CL |
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 | |
fd315f2c KM |
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 | |
b5dc1377 | 610 | .Ar l |
fd315f2c KM |
611 | command may be placed on the same line after any non-i/o |
612 | command. | |
b5dc1377 CL |
613 | .Tp Cx \&( |
614 | .Ic \&. | |
615 | .Cx \&, | |
616 | .Ic \&. | |
617 | .Cx \&) | |
618 | .Ic \&m | |
619 | .Ar a | |
620 | .Cx | |
fd315f2c KM |
621 | The move command repositions the addressed lines after the line |
622 | addressed by | |
b5dc1377 | 623 | .Ar a . |
fd315f2c | 624 | The last of the moved lines becomes the current line. |
b5dc1377 CL |
625 | .Tp Cx \&( |
626 | .Ic \&. | |
627 | .Cx \&, | |
628 | .Ic \&. | |
629 | .Cx \&) | |
630 | .Ic \&p | |
631 | .Cx | |
fd315f2c | 632 | The print command prints the addressed lines. |
b5dc1377 CL |
633 | .Cx ` |
634 | .Ic \&. | |
635 | .Cx \' | |
636 | .Cx | |
fd315f2c KM |
637 | is left at the last line printed. |
638 | The | |
b5dc1377 | 639 | .Ic p |
fd315f2c KM |
640 | command |
641 | may | |
642 | be placed on the same line after any non-i/o command. | |
b5dc1377 CL |
643 | .Tp Cx \&( |
644 | .Ic \&. | |
645 | .Cx \&, | |
646 | .Ic \&. | |
647 | .Cx \&) | |
648 | .Ic \&P | |
649 | .Cx | |
fd315f2c | 650 | This command is a synonym for |
b5dc1377 CL |
651 | .Ic p . |
652 | .Tp Ic q | |
fd315f2c | 653 | The quit command causes |
b5dc1377 | 654 | .Nm ed |
fd315f2c KM |
655 | to exit. |
656 | No automatic write | |
657 | of a file is done. | |
b5dc1377 | 658 | .Tp Ic Q |
fd315f2c | 659 | This command is the same as |
b5dc1377 | 660 | .Ic q , |
fd315f2c | 661 | except that no diagnostic results when no |
b5dc1377 | 662 | .Ic w |
fd315f2c | 663 | has been given since the last buffer alteration. |
b5dc1377 CL |
664 | .Tp Cx \&( |
665 | .Ic $ | |
666 | .Cx \&) | |
667 | .Ic r | |
668 | .Cx \&\ \& | |
669 | .Ar filename | |
670 | .Cx | |
fd315f2c KM |
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 | |
b5dc1377 | 676 | .Ic e |
fd315f2c | 677 | and |
b5dc1377 CL |
678 | .Ic f |
679 | commands). | |
fd315f2c KM |
680 | The file name is remembered if there was no |
681 | remembered file name already. | |
682 | Address `0' is legal for | |
b5dc1377 | 683 | .Ic r |
fd315f2c KM |
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. | |
b5dc1377 CL |
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 | |
fd315f2c KM |
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, | |
b5dc1377 CL |
715 | if the global replacement indicator |
716 | .Ic \&g | |
717 | appears after the command. | |
fd315f2c KM |
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 | |
b5dc1377 CL |
722 | may be used instead of |
723 | .Cx ` | |
724 | .Ic \&/ | |
725 | .Cx \' | |
726 | .Cx | |
727 | to delimit the regular expression | |
fd315f2c | 728 | and the replacement. |
b5dc1377 CL |
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 | |
fd315f2c | 740 | is replaced by the string matching the regular expression. |
b5dc1377 CL |
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 | |
fd315f2c | 752 | The characters |
b5dc1377 CL |
753 | .Cx ` |
754 | .Ic \&\e | |
755 | .Ar n | |
756 | .Cx \' | |
757 | .Cx | |
fd315f2c | 758 | where |
b5dc1377 | 759 | .Ar n |
fd315f2c KM |
760 | is a digit, |
761 | are replaced by the text matched by the | |
b5dc1377 CL |
762 | .Cx Ar n |
763 | .Cx \'th | |
764 | .Cx | |
fd315f2c | 765 | regular subexpression |
b5dc1377 CL |
766 | enclosed between |
767 | .Cx ` | |
768 | .Ic \&\e\&( | |
769 | .Cx \'. | |
770 | .Cx | |
771 | and | |
772 | .Cx ` | |
773 | .Ic \&\e\&) | |
774 | .Cx \'. | |
775 | .Cx | |
fd315f2c KM |
776 | When |
777 | nested, parenthesized subexpressions | |
778 | are present, | |
b5dc1377 CL |
779 | .Ar n |
780 | is determined by counting occurrences of | |
781 | .Cx ` | |
782 | .Ic \&\e\&( | |
783 | .Cx \'. | |
784 | .Cx | |
785 | starting from the left. | |
fd315f2c KM |
786 | Lines may be split by substituting new-line characters into them. |
787 | The new-line in the | |
788 | replacement string | |
b5dc1377 CL |
789 | must be escaped by preceding it by |
790 | .Cx ` | |
791 | .Ic \&\e | |
792 | .Cx \'. | |
793 | .Cx | |
fd315f2c | 794 | One or two trailing delimiters may be omitted, |
b5dc1377 CL |
795 | implying the |
796 | .Ic p | |
797 | suffix. | |
798 | The special form | |
799 | .Ic s | |
800 | followed by | |
801 | .Ar no | |
fd315f2c KM |
802 | delimiters |
803 | repeats the most recent substitute command | |
804 | on the addressed lines. | |
b5dc1377 CL |
805 | The |
806 | .Ic s | |
807 | may be followed by the letters | |
808 | .Ic r | |
fd315f2c KM |
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), | |
b5dc1377 | 812 | .Ic p |
fd315f2c | 813 | (complement the setting of the |
b5dc1377 | 814 | .Ic p |
fd315f2c | 815 | suffix from the previous substitution), or |
b5dc1377 | 816 | .Ic g |
fd315f2c | 817 | (complement the setting of the |
b5dc1377 | 818 | .Ic g |
fd315f2c KM |
819 | suffix). |
820 | These letters may be combined in any order. | |
b5dc1377 CL |
821 | .Tp Cx \&( |
822 | .Ic \&. | |
823 | .Cx \&, | |
824 | .Ic \&. | |
825 | .Cx \&) | |
826 | .Ic \&t | |
827 | .Ar a | |
828 | .Cx | |
fd315f2c | 829 | This command acts just like the |
b5dc1377 | 830 | .Ic m |
fd315f2c KM |
831 | command, except that a copy of the addressed lines is placed |
832 | after address | |
b5dc1377 | 833 | .Ad a |
fd315f2c | 834 | (which may be 0). |
b5dc1377 CL |
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 | |
fd315f2c KM |
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 | |
b5dc1377 | 851 | .Ic a , c , d , g , i , k , m , r , s , t , |
fd315f2c | 852 | and |
b5dc1377 | 853 | .Ic v . |
fd315f2c | 854 | For purposes of undo, |
b5dc1377 | 855 | .Ic g |
fd315f2c | 856 | and |
b5dc1377 | 857 | .Ic v |
fd315f2c KM |
858 | are considered to be a single buffer modifying command. |
859 | Undo is its own inverse. | |
fd315f2c | 860 | When |
b5dc1377 | 861 | .Nm ed |
fd315f2c KM |
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 | |
b5dc1377 | 866 | .Ic u |
fd315f2c KM |
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 | |
b5dc1377 | 871 | .Nm ed |
fd315f2c | 872 | is invoked with the |
b5dc1377 | 873 | .Fl |
fd315f2c | 874 | option. |
b5dc1377 CL |
875 | .Tp Cx \&( |
876 | .Ic \&1 | |
877 | .Cx \&, | |
878 | .Ic \&$ | |
879 | .Cx \&) | |
880 | .Ic \&v | |
881 | .Ar/regular expression/command list | |
882 | .Cx | |
fd315f2c | 883 | This command is the same as the global command |
b5dc1377 | 884 | .Ic g |
fd315f2c | 885 | except that the command list is executed |
b5dc1377 CL |
886 | .Ic g |
887 | with | |
888 | .Cx ` | |
889 | .Ic \&. | |
890 | .Cx \' | |
891 | .Cx | |
892 | initially set to every line | |
893 | .Em except | |
fd315f2c KM |
894 | those |
895 | matching the regular expression. | |
b5dc1377 CL |
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 | |
fd315f2c KM |
906 | The write command writes the addressed lines onto |
907 | the given file. | |
908 | If the file does not exist, | |
909 | it is created. | |
b5dc1377 | 910 | The file name is remembered if there was no |
fd315f2c KM |
911 | remembered file name already. |
912 | If no file name is given, | |
913 | the remembered file name, if any, is used | |
914 | (see | |
b5dc1377 | 915 | .Ic e |
fd315f2c | 916 | and |
b5dc1377 CL |
917 | .Ic f |
918 | commands). | |
919 | .Cx ` | |
920 | .Ic \&. | |
921 | .Cx \' | |
922 | .Cx | |
923 | is unchanged. | |
fd315f2c KM |
924 | If the command is successful, the number of characters written is |
925 | printed. | |
b5dc1377 CL |
926 | .Tp Cx \&( |
927 | .Ic \&1 | |
928 | .Cx \&, | |
929 | .Ic \&$ | |
930 | .Cx \&) | |
931 | .Ic \&W | |
932 | .Cx \&\ \& | |
933 | .Ar filename | |
934 | .Cx | |
fd315f2c | 935 | This command is the same as |
b5dc1377 | 936 | .Ic w , |
fd315f2c | 937 | except that the addressed lines are appended to the file. |
b5dc1377 CL |
938 | .Tp Cx \&( |
939 | .Ic \&1 | |
940 | .Cx \&, | |
941 | .Ic \&$ | |
942 | .Cx \&) | |
943 | .Ic \&wq | |
944 | .Cx \&\ \& | |
945 | .Ar filename | |
946 | .Cx | |
fd315f2c | 947 | This command is the same as |
b5dc1377 | 948 | .Ic w |
fd315f2c | 949 | except that afterwards a |
b5dc1377 | 950 | .Ic q |
fd315f2c KM |
951 | command is done, |
952 | exiting the editor | |
953 | after the file is written. | |
b5dc1377 CL |
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 | |
fd315f2c KM |
967 | This command scrolls through the buffer starting at the addressed line. |
968 | 22 (or | |
b5dc1377 | 969 | .Ar n , |
fd315f2c KM |
970 | if given) |
971 | lines are printed. | |
972 | The last line printed becomes the current line. | |
973 | The value | |
b5dc1377 | 974 | .Ar n |
fd315f2c KM |
975 | is sticky, in that it becomes the default for |
976 | future | |
b5dc1377 | 977 | .Ic z |
fd315f2c | 978 | commands. |
b5dc1377 CL |
979 | .Tp Cx \&( |
980 | .Ic \&$ | |
981 | .Cx \&) | |
982 | .Ic \&= | |
983 | .Cx | |
fd315f2c | 984 | The line number of the addressed line is typed. |
b5dc1377 CL |
985 | .Cx ` |
986 | .Ic \&. | |
987 | .Cx \' | |
988 | .Cx | |
989 | is unchanged by this command. | |
990 | .Tp Cx Ic \&! | |
991 | .Cx <shell\ command> | |
992 | .Cx | |
fd315f2c KM |
993 | The remainder of the line after the `!' is sent |
994 | to | |
b5dc1377 | 995 | .Xr sh 1 |
fd315f2c | 996 | to be interpreted as a command. |
b5dc1377 CL |
997 | .Cx ` |
998 | .Ic \&. | |
999 | .Cx \' | |
1000 | .Cx | |
fd315f2c | 1001 | is unchanged. |
b5dc1377 CL |
1002 | .Tp Cx \&( |
1003 | .Ic \&.+1 | |
1004 | .Cx \&, | |
1005 | .Ic \&.+1 | |
1006 | .Cx \&) | |
1007 | .Cx <newline> | |
1008 | .Cx | |
fd315f2c | 1009 | An address alone on a line causes the addressed line to be printed. |
b5dc1377 CL |
1010 | A blank line alone is equivalent to |
1011 | .Ic .+1 | |
1012 | it is useful | |
fd315f2c KM |
1013 | for stepping through text. |
1014 | If two addresses are present with no | |
1015 | intervening semicolon, | |
b5dc1377 | 1016 | .Nm ed |
fd315f2c KM |
1017 | prints the range of lines. |
1018 | If they are separated by a semicolon, | |
1019 | the second line is printed. | |
b5dc1377 CL |
1020 | .Tp |
1021 | .Pp | |
1022 | If an interrupt signal (ASCII DEL) is sent, | |
1023 | .Nm ed | |
1024 | prints | |
1025 | .Sq Li ?interrupted | |
fd315f2c | 1026 | and returns to its command level. |
b5dc1377 | 1027 | .Pp |
fd315f2c KM |
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. | |
b5dc1377 | 1036 | .Pp |
fd315f2c | 1037 | When reading a file, |
b5dc1377 | 1038 | .Nm ed |
fd315f2c KM |
1039 | discards ASCII NUL characters |
1040 | and all characters after the last newline. | |
1041 | It refuses to read files containing non-ASCII characters. | |
b5dc1377 CL |
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 | |
fd315f2c | 1053 | .br |
fd315f2c | 1054 | B. W. Kernighan, |
b5dc1377 | 1055 | .Em A Tutorial Introduction to the ED Text Editor |
fd315f2c KM |
1056 | .br |
1057 | B. W. Kernighan, | |
b5dc1377 CL |
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 | |
fd315f2c | 1067 | for other errors. |
b5dc1377 | 1068 | .Pp |
fd315f2c KM |
1069 | To protect against throwing away valuable work, |
1070 | a | |
b5dc1377 | 1071 | .Ic q |
fd315f2c | 1072 | or |
b5dc1377 | 1073 | .Ic e |
fd315f2c | 1074 | command is considered to be in error, unless a |
b5dc1377 | 1075 | .Ic w |
fd315f2c KM |
1076 | has occurred since the last buffer change. |
1077 | A second | |
b5dc1377 | 1078 | .Ic q |
fd315f2c | 1079 | or |
b5dc1377 | 1080 | .Ic e |
fd315f2c | 1081 | will be obeyed regardless. |
b5dc1377 CL |
1082 | .Sh BUGS |
1083 | The | |
1084 | .Ic l | |
1085 | command mishandles | |
1086 | .Li DEL . | |
fd315f2c KM |
1087 | .br |
1088 | The | |
b5dc1377 | 1089 | .Ic undo |
fd315f2c | 1090 | command causes marks to be lost on affected lines. |