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