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