Commit | Line | Data |
---|---|---|
362b077f C |
1 | |
2 | ||
3 | ||
4 | ED(1) UNIX Programmer's Manual ED(1) | |
5 | ||
6 | ||
7 | ||
8 | N\bNA\bAM\bME\bE | |
9 | ed - text editor | |
10 | ||
11 | S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS | |
12 | e\bed\bd [ -\b- ] [ -\b-x\bx ] [ name ] | |
13 | ||
14 | D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN | |
15 | _\bE_\bd is the standard text editor. | |
16 | ||
17 | If a _\bn_\ba_\bm_\be argument is given, _\be_\bd simulates an _\be command (see | |
18 | below) on the named file; that is to say, the file is read | |
19 | into _\be_\bd'_\bs buffer so that it can be edited. If -\b-x\bx is | |
20 | present, an _\bx command is simulated first to handle an | |
21 | encrypted file. The optional -\b- suppresses the printing of | |
22 | explanatory output and should be used when the standard | |
23 | input is an editor script. | |
24 | ||
25 | _\bE_\bd operates on a copy of any file it is editing; changes | |
26 | made in the copy have no effect on the file until a _\bw | |
27 | (write) command is given. The copy of the text being edited | |
28 | resides in a temporary file called the _\bb_\bu_\bf_\bf_\be_\br. | |
29 | ||
30 | Commands to _\be_\bd have a simple and regular structure: zero or | |
31 | more _\ba_\bd_\bd_\br_\be_\bs_\bs_\be_\bs followed by a single character _\bc_\bo_\bm_\bm_\ba_\bn_\bd, pos- | |
32 | sibly followed by parameters to the command. These | |
33 | addresses specify one or more lines in the buffer. Missing | |
34 | addresses are supplied by default. | |
35 | ||
36 | In general, only one command may appear on a line. Certain | |
37 | commands allow the addition of text to the buffer. While _\be_\bd | |
38 | is accepting text, it is said to be in _\bi_\bn_\bp_\bu_\bt _\bm_\bo_\bd_\be. In this | |
39 | mode, no commands are recognized; all input is merely col- | |
40 | lected. Input mode is left by typing a period `.\b.' alone at | |
41 | the beginning of a line. | |
42 | ||
43 | _\bE_\bd supports a limited form of _\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn notation. | |
44 | A regular expression specifies a set of strings of charac- | |
45 | ters. A member of this set of strings is said to be _\bm_\ba_\bt_\bc_\bh_\be_\bd | |
46 | by the regular expression. In the following specification | |
47 | for regular expressions the word `character' means any char- | |
48 | acter but newline. | |
49 | ||
50 | 1. Any character except a special character matches | |
51 | itself. Special characters are the regular expression | |
52 | delimiter plus \[.\b. and sometimes ^*$. | |
53 | ||
54 | 2. A .\b. matches any character. | |
55 | ||
56 | 3. A \ followed by any character except a digit or () | |
57 | matches that character. | |
58 | ||
59 | 4. A nonempty string _\bs bracketed [_\bs] (or [^_\bs]) matches any | |
60 | ||
61 | ||
62 | ||
63 | Printed 7/9/88 April 29, 1985 1 | |
64 | ||
65 | ||
66 | ||
67 | ||
68 | ||
69 | ||
70 | ED(1) UNIX Programmer's Manual ED(1) | |
71 | ||
72 | ||
73 | ||
74 | character in (or not in) _\bs. In _\bs, \ has no special | |
75 | meaning, and ] may only appear as the first letter. A | |
76 | substring _\ba-_\bb, with _\ba and _\bb in ascending ASCII order, | |
77 | stands for the inclusive range of ASCII characters. | |
78 | ||
79 | 5. A regular expression of form 1-4 followed by * matches | |
80 | a sequence of 0 or more matches of the regular expres- | |
81 | sion. | |
82 | ||
83 | 6. A regular expression, _\bx, of form 1-8, bracketed \(_\bx\) | |
84 | matches what _\bx matches. | |
85 | ||
86 | 7. A \ followed by a digit _\bn matches a copy of the string | |
87 | that the bracketed regular expression beginning with | |
88 | the _\bnth \( matched. | |
89 | ||
90 | 8. A regular expression of form 1-8, _\bx, followed by a reg- | |
91 | ular expression of form 1-7, _\by matches a match for _\bx | |
92 | followed by a match for _\by, with the _\bx match being as | |
93 | long as possible while still permitting a _\by match. | |
94 | ||
95 | 9. A regular expression of form 1-8 preceded by ^ (or fol- | |
96 | lowed by $), is constrained to matches that begin at | |
97 | the left (or end at the right) end of a line. | |
98 | ||
99 | 10. A regular expression of form 1-9 picks out the longest | |
100 | among the leftmost matches in a line. | |
101 | ||
102 | 11. An empty regular expression stands for a copy of the | |
103 | last regular expression encountered. | |
104 | ||
105 | Regular expressions are used in addresses to specify lines | |
106 | and in one command (see _\bs below) to specify a portion of a | |
107 | line which is to be replaced. If it is desired to use one | |
108 | of the regular expression metacharacters as an ordinary | |
109 | character, that character may be preceded by `\'. This also | |
110 | applies to the character bounding the regular expression | |
111 | (often `/') and to `\' itself. | |
112 | ||
113 | To understand addressing in _\be_\bd it is necessary to know that | |
114 | at any time there is a _\bc_\bu_\br_\br_\be_\bn_\bt _\bl_\bi_\bn_\be. Generally speaking, the | |
115 | current line is the last line affected by a command; how- | |
116 | ever, the exact effect on the current line is discussed | |
117 | under the description of the command. Addresses are con- | |
118 | structed as follows. | |
119 | ||
120 | 1. The character `.\b.' addresses the current line. | |
121 | ||
122 | 2. The character `$' addresses the last line of the | |
123 | buffer. | |
124 | ||
125 | 3. A decimal number _\bn addresses the _\bn-th line of the | |
126 | ||
127 | ||
128 | ||
129 | Printed 7/9/88 April 29, 1985 2 | |
130 | ||
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | ED(1) UNIX Programmer's Manual ED(1) | |
137 | ||
138 | ||
139 | ||
140 | buffer. | |
141 | ||
142 | 4. `'_\bx' addresses the line marked with the name _\bx, which | |
143 | must be a lower-case letter. Lines are marked with the | |
144 | _\bk command described below. | |
145 | ||
146 | 5. A regular expression enclosed in slashes `/' addresses | |
147 | the line found by searching forward from the current | |
148 | line and stopping at the first line containing a string | |
149 | that matches the regular expression. If necessary the | |
150 | search wraps around to the beginning of the buffer. | |
151 | ||
152 | 6. A regular expression enclosed in queries `?' addresses | |
153 | the line found by searching backward from the current | |
154 | line and stopping at the first line containing a string | |
155 | that matches the regular expression. If necessary the | |
156 | search wraps around to the end of the buffer. | |
157 | ||
158 | 7. An address followed by a plus sign `+' or a minus sign | |
159 | `-' followed by a decimal number specifies that address | |
160 | plus (resp. minus) the indicated number of lines. The | |
161 | plus sign may be omitted. | |
162 | ||
163 | 8. If an address begins with `+' or `-' the addition or | |
164 | subtraction is taken with respect to the current line; | |
165 | e.g. `-5' is understood to mean `.\b.-5'. | |
166 | ||
167 | 9. If an address ends with `+' or `-', then 1 is added | |
168 | (resp. subtracted). As a consequence of this rule and | |
169 | rule 8, the address `-' refers to the line before the | |
170 | current line. Moreover, trailing `+' and `-' charac- | |
171 | ters have cumulative effect, so `--' refers to the | |
172 | current line less 2. | |
173 | ||
174 | 10. To maintain compatibility with earlier versions of the | |
175 | editor, the character `^' in addresses is equivalent to | |
176 | `-'. | |
177 | ||
178 | Commands may require zero, one, or two addresses. Commands | |
179 | which require no addresses regard the presence of an address | |
180 | as an error. Commands which accept one or two addresses | |
181 | assume default addresses when insufficient are given. If | |
182 | more addresses are given than such a command requires, the | |
183 | last one or two (depending on what is accepted) are used. | |
184 | ||
185 | Addresses are separated from each other typically by a comma | |
186 | `,\b,'. They may also be separated by a semicolon `;\b;'. In | |
187 | this case the current line `.\b.' is set to the previous | |
188 | address before the next address is interpreted. This | |
189 | feature can be used to determine the starting line for for- | |
190 | ward and backward searches (`/', `?'). The second address | |
191 | of any two-address sequence must correspond to a line | |
192 | ||
193 | ||
194 | ||
195 | Printed 7/9/88 April 29, 1985 3 | |
196 | ||
197 | ||
198 | ||
199 | ||
200 | ||
201 | ||
202 | ED(1) UNIX Programmer's Manual ED(1) | |
203 | ||
204 | ||
205 | ||
206 | following the line corresponding to the first address. The | |
207 | special form `%' is an abbreviation for the address pair | |
208 | `1,$'. | |
209 | ||
210 | In the following list of _\be_\bd commands, the default addresses | |
211 | are shown in parentheses. The parentheses are not part of | |
212 | the address, but are used to show that the given addresses | |
213 | are the default. | |
214 | ||
215 | As mentioned, it is generally illegal for more than one com- | |
216 | mand to appear on a line. However, most commands may be | |
217 | suffixed by `p' or by `l', in which case the current line is | |
218 | either printed or listed respectively in the way discussed | |
219 | below. Commands may also be suffixed by `n', meaning the | |
220 | output of the command is to be line numbered. These suf- | |
221 | fixes may be combined in any order. | |
222 | ||
223 | (.\b.)a | |
224 | <text> | |
225 | .\b. | |
226 | The append command reads the given text and appends it | |
227 | after the addressed line. `.\b.' is left on the last line | |
228 | input, if there were any, otherwise at the addressed | |
229 | line. Address `0' is legal for this command; text is | |
230 | placed at the beginning of the buffer. | |
231 | ||
232 | (.\b., .\b.)c | |
233 | <text> | |
234 | .\b. | |
235 | The change command deletes the addressed lines, then | |
236 | accepts input text which replaces these lines. `.\b.' is | |
237 | left at the last line input; if there were none, it is | |
238 | left at the line preceding the deleted lines. | |
239 | ||
240 | (.\b., .\b.)d | |
241 | The delete command deletes the addressed lines from the | |
242 | buffer. The line originally after the last line | |
243 | deleted becomes the current line; if the lines deleted | |
244 | were originally at the end, the new last line becomes | |
245 | the current line. | |
246 | ||
247 | e filename | |
248 | The edit command causes the entire contents of the | |
249 | buffer to be deleted, and then the named file to be | |
250 | read in. `.\b.' is set to the last line of the buffer. | |
251 | The number of characters read is typed. `filename' is | |
252 | remembered for possible use as a default file name in a | |
253 | subsequent _\br or _\bw command. If `filename' is missing, | |
254 | the remembered name is used. | |
255 | ||
256 | E filename | |
257 | This command is the same as _\be, except that no | |
258 | ||
259 | ||
260 | ||
261 | Printed 7/9/88 April 29, 1985 4 | |
262 | ||
263 | ||
264 | ||
265 | ||
266 | ||
267 | ||
268 | ED(1) UNIX Programmer's Manual ED(1) | |
269 | ||
270 | ||
271 | ||
272 | diagnostic results when no _\bw has been given since the | |
273 | last buffer alteration. | |
274 | ||
275 | f filename | |
276 | The filename command prints the currently remembered | |
277 | file name. If `filename' is given, the currently | |
278 | remembered file name is changed to `filename'. | |
279 | ||
280 | (1,$)g/regular expression/command list | |
281 | In the global command, the first step is to mark every | |
282 | line which matches the given regular expression. Then | |
283 | for every such line, the given command list is executed | |
284 | with `.\b.' initially set to that line. A single command | |
285 | or the first of multiple commands appears on the same | |
286 | line with the global command. All lines of a multi- | |
287 | line list except the last line must be ended with `\'. | |
288 | _\bA, _\bi, and _\bc commands and associated input are permit- | |
289 | ted; the `.\b.' terminating input mode may be omitted if | |
290 | it would be on the last line of the command list. The | |
291 | commands _\bg and _\bv are not permitted in the command list. | |
292 | ||
293 | (.\b.)i | |
294 | ||
295 | <text> | |
296 | .\b. | |
297 | This command inserts the given text before the | |
298 | addressed line. `.\b.' is left at the last line input, | |
299 | or, if there were none, at the line before the | |
300 | addressed line. This command differs from the _\ba com- | |
301 | mand only in the placement of the text. | |
302 | ||
303 | (.\b., .\b.+1)j | |
304 | This command joins the addressed lines into a single | |
305 | line; intermediate newlines simply disappear. `.\b.' is | |
306 | left at the resulting line. | |
307 | ||
308 | ( .\b. )k_\bx | |
309 | The mark command marks the addressed line with name _\bx, | |
310 | which must be a lower-case letter. The address form | |
311 | `'_\bx' then addresses this line. | |
312 | ||
313 | (.\b., .\b.)l | |
314 | The list command prints the addressed lines in an unam- | |
315 | biguous way: non-graphic characters are printed in | |
316 | two-digit octal, and long lines are folded. The _\bl com- | |
317 | mand may be placed on the same line after any non-i/o | |
318 | command. | |
319 | ||
320 | (.\b., .\b.)m_\ba | |
321 | The move command repositions the addressed lines after | |
322 | the line addressed by _\ba. The last of the moved lines | |
323 | becomes the current line. | |
324 | ||
325 | ||
326 | ||
327 | Printed 7/9/88 April 29, 1985 5 | |
328 | ||
329 | ||
330 | ||
331 | ||
332 | ||
333 | ||
334 | ED(1) UNIX Programmer's Manual ED(1) | |
335 | ||
336 | ||
337 | ||
338 | (.\b., .\b.)p | |
339 | The print command prints the addressed lines. `.\b.' is | |
340 | left at the last line printed. The _\bp command may be | |
341 | placed on the same line after any non-i/o command. | |
342 | ||
343 | (.\b., .\b.)P | |
344 | This command is a synonym for _\bp. | |
345 | ||
346 | q The quit command causes _\be_\bd to exit. No automatic write | |
347 | of a file is done. | |
348 | ||
349 | Q This command is the same as _\bq, except that no diagnos- | |
350 | tic results when no _\bw has been given since the last | |
351 | buffer alteration. | |
352 | ||
353 | ($)r filename | |
354 | The read command reads in the given file after the | |
355 | addressed line. If no file name is given, the remem- | |
356 | bered file name, if any, is used (see _\be and _\bf com- | |
357 | mands). The file name is remembered if there was no | |
358 | remembered file name already. Address `0' is legal for | |
359 | _\br and causes the file to be read at the beginning of | |
360 | the buffer. If the read is successful, the number of | |
361 | characters read is typed. `.\b.' is left at the last line | |
362 | read in from the file. | |
363 | ||
364 | ( .\b., .\b.)s/regular expression/replacement/ or, | |
365 | ( .\b., .\b.)s/regular expression/replacement/g | |
366 | The substitute command searches each addressed line for | |
367 | an occurrence of the specified regular expression. On | |
368 | each line in which a match is found, all matched | |
369 | strings are replaced by the replacement specified, if | |
370 | the global replacement indicator `g' appears after the | |
371 | command. If the global indicator does not appear, only | |
372 | the first occurrence of the matched string is replaced. | |
373 | It is an error for the substitution to fail on all | |
374 | addressed lines. Any punctuation character may be used | |
375 | instead of `/' to delimit the regular expression and | |
376 | the replacement. `.\b.' is left at the last line substi- | |
377 | tuted. | |
378 | ||
379 | An ampersand `&' appearing in the replacement is | |
380 | replaced by the string matching the regular expression. | |
381 | The special meaning of `&' in this context may be | |
382 | suppressed by preceding it by `\'. The characters `_\b\_\bn' | |
383 | where _\bn is a digit, are replaced by the text matched by | |
384 | the _\bn-th regular subexpression enclosed between `\(' | |
385 | and `\)'. When nested, parenthesized subexpressions | |
386 | are present, _\bn is determined by counting occurrences of | |
387 | `\(' starting from the left. | |
388 | ||
389 | Lines may be split by substituting new-line characters | |
390 | ||
391 | ||
392 | ||
393 | Printed 7/9/88 April 29, 1985 6 | |
394 | ||
395 | ||
396 | ||
397 | ||
398 | ||
399 | ||
400 | ED(1) UNIX Programmer's Manual ED(1) | |
401 | ||
402 | ||
403 | ||
404 | into them. The new-line in the replacement string must | |
405 | be escaped by preceding it by `\'. | |
406 | ||
407 | One or two trailing delimiters may be omitted, implying | |
408 | the `p' suffix. The special form `s' followed by _\bn_\bo | |
409 | delimiters repeats the most recent substitute command | |
410 | on the addressed lines. The `s' may be followed by the | |
411 | letters r\br (use the most recent regular expression for | |
412 | the left hand side, instead of the most recent left | |
413 | hand side of a substitute command), p\bp (complement the | |
414 | setting of the _\bp suffix from the previous substitu- | |
415 | tion), or g\bg (complement the setting of the _\bg suffix). | |
416 | These letters may be combined in any order. | |
417 | ||
418 | (.\b., .\b.)t_\ba | |
419 | This command acts just like the _\bm command, except that | |
420 | a copy of the addressed lines is placed after address _\ba | |
421 | (which may be 0). `.\b.' is left on the last line of the | |
422 | copy. | |
423 | ||
424 | (.\b., .\b.)u | |
425 | The undo command restores the buffer to it's state | |
426 | before the most recent buffer modifying command. The | |
427 | current line is also restored. Buffer modifying com- | |
428 | mands are _\ba, _\bc, _\bd, _\bg, _\bi, _\bk, and _\bv. For purposes of | |
429 | undo, _\bg and _\bv are considered to be a single buffer | |
430 | modifying command. Undo is its own inverse. | |
431 | ||
432 | When _\be_\bd runs out of memory (at about 8000 lines on any | |
433 | 16 bit mini-computer such as the PDP-11) This full undo | |
434 | is not possible, and _\bu can only undo the effect of the | |
435 | most recent substitute on the current line. This res- | |
436 | tricted undo also applies to editor scripts when _\be_\bd is | |
437 | invoked with the -\b- option. | |
438 | ||
439 | (1, $)v/regular expression/command list | |
440 | This command is the same as the global command _\bg except | |
441 | that the command list is executed _\bg with `.\b.' initially | |
442 | set to every line _\be_\bx_\bc_\be_\bp_\bt those matching the regular | |
443 | expression. | |
444 | ||
445 | (1, $)w filename | |
446 | The write command writes the addressed lines onto the | |
447 | given file. If the file does not exist, it is created. | |
448 | The file name is remembered if there was no remembered | |
449 | file name already. If no file name is given, the | |
450 | remembered file name, if any, is used (see _\be and _\bf com- | |
451 | mands). `.\b.' is unchanged. If the command is success- | |
452 | ful, the number of characters written is printed. | |
453 | ||
454 | (1, $)W filename | |
455 | This command is the same as _\bw, except that the | |
456 | ||
457 | ||
458 | ||
459 | Printed 7/9/88 April 29, 1985 7 | |
460 | ||
461 | ||
462 | ||
463 | ||
464 | ||
465 | ||
466 | ED(1) UNIX Programmer's Manual ED(1) | |
467 | ||
468 | ||
469 | ||
470 | addressed lines are appended to the file. | |
471 | ||
472 | (1, $)wq filename | |
473 | This command is the same as _\bw except that afterwards a | |
474 | _\bq command is done, exiting the editor after the file is | |
475 | written. | |
476 | ||
477 | x A key string is demanded from the standard input. | |
478 | Later _\br, _\be and _\bw commands will encrypt and decrypt the | |
479 | text with this key by the algorithm of _\bc_\br_\by_\bp_\bt(1). An | |
480 | explicitly empty key turns off encryption. | |
481 | (.\b.+1)z or, | |
482 | (.\b.+1)z_\bn | |
483 | This command scrolls through the buffer starting at the | |
484 | addressed line. 22 (or _\bn, if given) lines are printed. | |
485 | The last line printed becomes the current line. The | |
486 | value _\bn is sticky, in that it becomes the default for | |
487 | future _\bz commands. | |
488 | ||
489 | ($)= The line number of the addressed line is typed. `.\b.' is | |
490 | unchanged by this command. | |
491 | ||
492 | !<shell command> | |
493 | The remainder of the line after the `!' is sent to | |
494 | _\bs_\bh(1) to be interpreted as a command. `.\b.' is | |
495 | unchanged. | |
496 | ||
497 | (.\b.+1,.\b.+1)<newline> | |
498 | An address alone on a line causes the addressed line to | |
499 | be printed. A blank line alone is equivalent to | |
500 | `.+1p'; it is useful for stepping through text. If two | |
501 | addresses are present with no intervening semicolon, _\be_\bd | |
502 | prints the range of lines. If they are separated by a | |
503 | semicolon, the second line is printed. | |
504 | ||
505 | If an interrupt signal (ASCII DEL) is sent, _\be_\bd prints | |
506 | `?interrupted' and returns to its command level. | |
507 | ||
508 | Some size limitations: 512 characters per line, 256 charac- | |
509 | ters per global command list, 64 characters per file name, | |
510 | and, on mini computers, 128K characters in the temporary | |
511 | file. The limit on the number of lines depends on the | |
512 | amount of core: each line takes 2 words. | |
513 | ||
514 | When reading a file, _\be_\bd discards ASCII NUL characters and | |
515 | all characters after the last newline. It refuses to read | |
516 | files containing non-ASCII characters. | |
517 | ||
518 | F\bFI\bIL\bLE\bES\bS | |
519 | /tmp/e* | |
520 | edhup: work is saved here if terminal hangs up | |
521 | ||
522 | ||
523 | ||
524 | ||
525 | Printed 7/9/88 April 29, 1985 8 | |
526 | ||
527 | ||
528 | ||
529 | ||
530 | ||
531 | ||
532 | ED(1) UNIX Programmer's Manual ED(1) | |
533 | ||
534 | ||
535 | ||
536 | S\bSE\bEE\bE A\bAL\bLS\bSO\bO | |
537 | B. W. Kernighan, _\bA _\bT_\bu_\bt_\bo_\br_\bi_\ba_\bl _\bI_\bn_\bt_\br_\bo_\bd_\bu_\bc_\bt_\bi_\bo_\bn _\bt_\bo _\bt_\bh_\be _\bE_\bD _\bT_\be_\bx_\bt _\bE_\bd_\bi_\b- | |
538 | _\bt_\bo_\br | |
539 | B. W. Kernighan, _\bA_\bd_\bv_\ba_\bn_\bc_\be_\bd _\be_\bd_\bi_\bt_\bi_\bn_\bg _\bo_\bn _\bU_\bN_\bI_\bX | |
540 | ex(1), sed(1), crypt(1) | |
541 | ||
542 | D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS | |
543 | `?name' for inaccessible file; `?self-explanatory message' | |
544 | for other errors. | |
545 | ||
546 | To protect against throwing away valuable work, a _\bq or _\be | |
547 | command is considered to be in error, unless a _\bw has | |
548 | occurred since the last buffer change. A second _\bq or _\be will | |
549 | be obeyed regardless. | |
550 | ||
551 | B\bBU\bUG\bGS\bS | |
552 | The _\bl command mishandles DEL. | |
553 | The _\bu_\bn_\bd_\bo command causes marks to be lost on affected lines. | |
554 | The _\bx command, -\b-x\bx option, and special treatment of hangups | |
555 | only work on UNIX. | |
556 | ||
557 | ||
558 | ||
559 | ||
560 | ||
561 | ||
562 | ||
563 | ||
564 | ||
565 | ||
566 | ||
567 | ||
568 | ||
569 | ||
570 | ||
571 | ||
572 | ||
573 | ||
574 | ||
575 | ||
576 | ||
577 | ||
578 | ||
579 | ||
580 | ||
581 | ||
582 | ||
583 | ||
584 | ||
585 | ||
586 | ||
587 | ||
588 | ||
589 | ||
590 | ||
591 | Printed 7/9/88 April 29, 1985 9 | |
592 | ||
593 | ||
594 |