BSD 4_4 development
[unix-history] / usr / share / man / cat1 / ed.0
CommitLineData
16469013
C
1ED(1) BSD Reference Manual ED(1)
2
3N\bNA\bAM\bME\bE
4 e\bed\bd - text editor
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 e\bed\bd [-\b-] [-\b-x\bx] [_\bf_\bi_\bl_\be]
8
9D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
10 E\bEd\bd once was the standard text editor in the early days of UNIX. While its
11 life as a line editor is dated, e\bed\bd still resides on systems produced by a
12 variety of vendors for good reason. Because of its small size and sim-
13 plicity, e\bed\bd,\b, is found on the root partition (_\b/_\bb_\bi_\bn_\b/_\be_\bd) for emergency edit-
14 ing when normal system reboots fail or single user tasks are performed
15 and _\b/_\bu_\bs_\br is not mounted. E\bEd\bd is also useful for script editing tasks, and
16 although there is nothing which can be done by e\bed\bd that cannot be per-
17 formed by sed(1), ex(1) or _\bG_\bn_\bu _\bE_\bm_\ba_\bc_\bs, e\bed\bd remains the simplest and easi-
18 est to use.
19
20 If a _\bf_\bi_\bl_\be argument is given, e\bed\bd simulates an e\be command (see below) on the
21 named file; that is to say, the file is read into e\bed\bd's buffer so that it
22 can be edited.
23
24 Available options:
25
26 -\b-x\bx An x\bx command is simulated first to handle an encrypted file.
27
28 -\b- Suppresses the printing of explanatory output and should be used
29 when the standard input is an editor script.
30
31 E\bEd\bd operates on a copy of any file it is editing; changes made in the copy
32 have no effect on the file until a w\bw (write) command is given. The copy
33 of the text being edited resides in a temporary file called the _\bb_\bu_\bf_\bf_\be_\br.
34
35 Commands to e\bed\bd have a simple and regular structure: zero or more
36 _\ba_\bd_\bd_\br_\be_\bs_\bs_\be_\bs followed by a single character c\bco\bom\bmm\bma\ban\bnd\bd, possibly followed by
37 parameters to the command. These addresses specify one or more lines in
38 the buffer. Missing addresses are supplied by default.
39
40 In general, only one command may appear on a line. Certain commands al-
41 low the addition of text to the buffer. While e\bed\bd is accepting text, it
42 is said to be in _\bi_\bn_\bp_\bu_\bt _\bm_\bo_\bd_\be. In this mode, no commands are recognized;
43 all input is merely collected. Input mode is left by typing a period `_\b.'
44 alone at the beginning of a line.
45
46 E\bEd\bd supports a limited form of _\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn notation. A regular ex-
47 pression specifies a set of strings of characters. A member of this set
48 of strings is said to be _\bm_\ba_\bt_\bc_\bh_\be_\bd by the regular expression. In the fol-
49 lowing specification for regular expressions the word `character' means
50 any character but newline.
51
52 1. Any character except a special character matches itself. Special
53 characters are the regular expression delimiter plus `\[.' and some-
54 times `^*$'.
55
56 2. A ``.'' matches any character.
57
58 3. A `\' followed by any character except a digit or ( matches that
59 character.
60
61 4. A nonempty string _\bs bracketed [_\bs] (or [_\b^_\bs]) matches any character in
62 (or not in) _\bs_\b. In _\bs_\b, `\' has no special meaning, and may only appear
63 as the first letter. A substring _\ba_\b-_\bb, with _\ba and _\bb in ascending
64
65
66 ASCII order, stands for the inclusive range of ASCII characters.
67
68 5. A regular expression of form 1-4 followed by `*' matches a sequence
69 of 0 or more matches of the regular expression.
70
71 6. A regular expression, _\bx, of form 1-8, bracketed \( _\bx\) matches what
72 _\bx matches.
73
74 7. A \ followed by a digit _\bn matches a copy of the string that the
75 bracketed regular expression beginning with the _\bnth \( matched.
76
77 8. A regular expression of form 1-8, _\bx, followed by a regular expres-
78 sion of form 1-7, _\by matches a match for _\bx followed by a match for _\by,
79 with the _\bx match being as long as possible while still permitting a
80 _\by match.
81
82 9. A regular expression of form 1-8 preceded by `^' (or followed by
83 `$'), is constrained to matches that begin at the left (or end at
84 the right) end of a line.
85
86 10. A regular expression of form 1-9 picks out the longest among the
87 leftmost matches in a line.
88
89 11. An empty regular expression stands for a copy of the last regular
90 expression encountered.
91
92 Regular expressions are used in addresses to specify lines and in one
93 command (see _\bs below) to specify a portion of a line which is to be re-
94 placed. If it is desired to use one of the regular expression metachar-
95 acters as an ordinary character, that character may be preceded by `\'.
96 This also applies to the character bounding the regular expression (often
97 `/') and to `\' itself.
98
99 To understand addressing in e\bed\bd it is necessary to know that at any time
100 there is a _\bc_\bu_\br_\br_\be_\bn_\bt _\bl_\bi_\bn_\be_\b. Generally speaking, the current line is the last
101 line affected by a command; however, the exact effect on the current line
102 is discussed under the description of the command. Addresses are con-
103 structed as follows.
104
105 1. The character `_\b.' addresses the current line.
106
107 2. The character `_\b$' addresses the last line of the buffer.
108
109 3. A decimal number _\bn addresses the _\bnth line of the buffer.
110
111 4. `'_\bx' addresses the line marked with the name _\bx, which must be a low-
112 er-case letter. Lines are marked with the _\bk command described be-
113 low.
114
115 5. A regular expression enclosed in slashes `/' addresses the line
116 found by searching forward from the current line and stopping at the
117 first line containing a string that matches the regular expression.
118 If necessary the search wraps around to the beginning of the buffer.
119
120 6. A regular expression enclosed in queries `?' addresses the line
121 found by searching backward from the current line and stopping at
122 the first line containing a string that matches the regular expres-
123 sion. If necessary the search wraps around to the end of the
124 buffer.
125
126 7. An address followed by a plus sign `+' or a minus sign `-' followed
127 by a decimal number specifies that address plus (resp. minus) the
128 indicated number of lines. The plus sign may be omitted.
129
130 8. If an address begins with `+' or `-' the addition or subtraction is
131 taken with respect to the current line; e.g. `-5' is understood to
132
133 mean `.-5'.
134
135 9. If an address ends with `+' or `-' then 1 is added (resp. subtract-
136 ed). As a consequence of this rule and rule 8, the address `-'
137 refers to the line before the current line. Moreover, trailing `+'
138 and `-' characters have cumulative effect, so `--' refers to the
139 current line less 2.
140
141 10. To maintain compatibility with earlier versions of the editor, the
142 character `^' in addresses is equivalent to `-'
143
144 Commands may require zero, one, or two addresses. Commands which require
145 no addresses regard the presence of an address as an error. Commands
146 which accept one or two addresses assume default addresses when insuffi-
147 cient are given. If more addresses are given than such a command re-
148 quires, the last one or two (depending on what is accepted) are used.
149
150 Addresses are separated from each other typically by a comma `,' They may
151 also be separated by a semicolon `;' In this case the current line `.' is
152 set to the previous address before the next address is interpreted. This
153 feature can be used to determine the starting line for forward and back-
154 ward searches (`/', `?') The second address of any two-address sequence
155 must correspond to a line following the line corresponding to the first
156 address. The special form `%' is an abbreviation for the address pair
157 `1,$'.
158
159 In the following list of e\bed\bd commands, the default addresses are shown in
160 parentheses. The parentheses are not part of the address, but are used
161 to show that the given addresses are the default.
162
163 As mentioned, it is generally illegal for more than one command to appear
164 on a line. However, most commands may be suffixed by `p' or by `l', in
165 which case the current line is either printed or listed respectively in
166 the way discussed below. Commands may also be suffixed by `n', meaning
167 the output of the command is to be line numbered. These suffixes may be
168 combined in any order.
169
170 (_\b.)a\ba
171 <text>
172 .\b.
173 The append command reads the given text and appends it after the
174 addressed line. `_\b.' is left on the last line input, if there were
175 any, otherwise at the addressed line. Address `0' is legal for
176 this command; text is placed at the beginning of the buffer.
177
178 (_\b.,_\b.)c\bc
179 <text>
180 .\b.
181 The change command deletes the addressed lines, then accepts input
182 text which replaces these lines. `_\b.' is left at the last line in-
183 put; if there were none, it is left at the line preceding the
184 deleted lines.
185
186 (_\b.,_\b.)d\bd
187 <text>
188 .\b.
189 The delete command deletes the addressed lines from the buffer.
190 The line originally after the last line deleted becomes the current
191 line; if the lines deleted were originally at the end, the new last
192 line becomes the current line.
193
194 e\be _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
195 The edit command causes the entire contents of the buffer to be
196 deleted, and then the named file to be read in. `_\b.' is set to the
197 last line of the buffer. The number of characters read is typed.
198 _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be is remembered for possible use as a default file name in a
199 subsequent r\br or w\bw command. If _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be is missing, the remembered
200 name is used.
201
202 E\bE _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
203 This command is the same as e\be, except that no diagnostic results
204 when no w\bw has been given since the last buffer alteration.
205
206 f\bf _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
207 The filename command prints the currently remembered file name. If
208 _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be is given, the currently remembered file name is changed to
209 _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be.
210
211 (_\b1,_\b$)g\bg_\b/_\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn_\b/c\bco\bom\bmm\bma\ban\bnd\bd l\bli\bis\bst\bt
212 In the global command, the first step is to mark every line which
213 matches the given regular expression. Then for every such line,
214 the given command list is executed with In the global command, the
215 first step is to mark every line which matches the given regular
216 expression. Then for every such line, the given command list is
217 executed with `_\b.' initially set to that line. A single command or
218 the first of multiple commands appears on the same line with the
219 global command. All lines of a multi-line list except the last
220 line must be ended with `\\b\' A\bA, i\bi, and c\bc commands and associated in-
221 put are permitted; the `_\b.' terminating input mode may be omitted if
222 it would be on the last line of the command list. The commands g\bg
223 and v\bv are not permitted in the command list.
224
225 (_\b.)i\bi
226 <text>
227 .\b.
228 This command inserts the given text before the addressed line. `_\b.'
229 is left at the last line input, or, if there were none, at the line
230 before the addressed line. This command differs from the a\ba command
231 only in the placement of the text.
232
233 (_\b.,_\b._\b+_\b1)j\bj
234 This command joins the addressed lines into a single line; interme-
235 diate newlines simply disappear. `_\b.' is left at the resulting
236 line.
237
238 (_\b.)k\bk_\bx
239 The mark command marks the addressed line with name _\bx, which must
240 be a lower-case letter. The address form _\b'_\bx then addresses this
241 line.
242
243 (_\b.,_\b.)l\bl
244 The list command prints the addressed lines in an unambiguous way:
245 non-graphic characters are printed in two-digit octal, and long
246 lines are folded. The _\bl command may be placed on the same line af-
247 ter any non-i/o command.
248
249 (_\b.,_\b.)m\bm_\ba
250 The move command repositions the addressed lines after the line ad-
251 dressed by `_\ba'. The last of the moved lines becomes the current
252 line.
253
254 (_\b.,_\b.)p\bp
255 The print command prints the addressed lines. `_\b.' is left at the
256 last line printed. The p\bp command may be placed on the same line
257 after any non-i/o command.
258
259 (_\b.,_\b.)P\bP
260 This command is a synonym for p\bp.
261
262
263
264 q\bq The quit command causes e\bed\bd to exit. No automatic write of a file
265 is done.
266
267 Q\bQ This command is the same as q\bq, except that no diagnostic results
268 when no w\bw has been given since the last buffer alteration.
269
270 (_\b$,_\b.)r\br _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
271 The read command reads in the given file after the addressed line.
272 If no file name is given, the remembered file name, if any, is used
273 (see e\be and f\bf commands). The file name is remembered if there was
274 no remembered file name already. Address `0' is legal for r\br and
275 causes the file to be read at the beginning of the buffer. If the
276 read is successful, the number of characters read is typed. `_\b.' is
277 left at the last line read in from the file.
278
279 (_\b1,_\b$)g\bg_\b/_\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn_\b/r\bre\bep\bpl\bla\bac\bce\bem\bme\ben\bnt\bt l\bli\bis\bst\bt or,
280 (_\b1,_\b$)g\bg_\b/_\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn_\b/r\bre\bep\bpl\bla\bac\bce\bem\bme\ben\bnt\bt l\bli\bis\bst\bt/\b/g\bg
281 The substitute command searches each addressed line for an occur-
282 rence of the specified regular expression. On each line in which a
283 match is found, all matched strings are replaced by the replacement
284 specified, if the global replacement indicator g\bg appears after the
285 command. If the global indicator does not appear, only the first
286 occurrence of the matched string is replaced. It is an error for
287 the substitution to fail on all addressed lines. Any punctuation
288 character may be used instead of `/\b/' to delimit the regular expres-
289 sion and the replacement. `_\b.' is left at the last line substitut-
290 ed. An ampersand `&\b&' appearing in the replacement is replaced by
291 the string matching the regular expression. The special meaning of
292 `&\b&' in this context may be suppressed by preceding it by `\\b\' The
293 characters `\\b\_\bn' where _\bn is a digit, are replaced by the text
294 matched by the regular subexpression enclosed between _\bn`' and `\\b\)\b)'
295 When nested, parenthesized subexpressions are present, _\bn is deter-
296 mined by counting occurrences of `\\b\(\b(' starting from the left.
297 Lines may be split by substituting new-line characters into them.
298 The new-line in the replacement string must be escaped by preceding
299 it by `\\b\' One or two trailing delimiters may be omitted, implying
300 the p\bp suffix. The special form s\bs followed by _\bn_\bo delimiters repeats
301 the most recent substitute command on the addressed lines. The s\bs
302 may be followed by the letters r\br (use the most recent regular ex-
303 pression for the left hand side, instead of the most recent left
304 hand side of a substitute command), p\bp (complement the setting of
305 the p\bp suffix from the previous substitution), or g\bg (complement the
306 setting of the g\bg suffix). These letters may be combined in any or-
307 der.
308
309 (_\b.,_\b.)t\bt_\ba
310 This command acts just like the m\bm command, except that a copy of
311 the addressed lines is placed after address _\ba (which may be 0).
312 `_\b.' is left on the last line of the copy.
313
314 (_\b.,_\b.)u\bu
315 The undo command restores the buffer to it's state before the most
316 recent buffer modifying command. The current line is also re-
317 stored. Buffer modifying commands are a\ba, c\bc, d\bd, g\bg, i\bi, k\bk, m\bm, r\br, s\bs,
318 t\bt, and v\bv. For purposes of undo, g\bg and v\bv are considered to be a sin-
319 gle buffer modifying command. Undo is its own inverse. When e\bed\bd
320 runs out of memory (at about 8000 lines on any 16 bit mini-computer
321 such as the PDP-11) This full undo is not possible, and u\bu can only
322 undo the effect of the most recent substitute on the current line.
323 This restricted undo also applies to editor scripts when e\bed\bd is in-
324 voked with the -\b- option.
325
326 (_\b1,_\b$)v\bv_\b/_\br_\be_\bg_\bu_\bl_\ba_\br _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn_\b/c\bco\bom\bmm\bma\ban\bnd\bd l\bli\bis\bst\bt
327 This command is the same as the global command g\bg except that the
328 command list is executed g\bg with `_\b.' initially set to every line
329 _\be_\bx_\bc_\be_\bp_\bt those matching the regular expression.
330
331 (_\b1,_\b$)w\bw _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
332 The write command writes the addressed lines onto the given file.
333 If the file does not exist, it is created. The file name is remem-
334 bered if there was no remembered file name already. If no file
335 name is given, the remembered file name, if any, is used (see e\be and
336 f\bf commands). `_\b.' is unchanged. If the command is successful, the
337 number of characters written is printed.
338
339 (_\b1,_\b$)W\bW _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
340 This command is the same as w\bw, except that the addressed lines are
341 appended to the file.
342
343 (_\b1,_\b$)w\bwq\bq _\bf_\bi_\bl_\be_\bn_\ba_\bm_\be
344 This command is the same as w\bw except that afterwards a q\bq command is
345 done, exiting the editor after the file is written.
346
347 x A key string is demanded from the standard input. Later r\br, e\be and w\bw
348 commands will encrypt and decrypt the text with this key by the al-
349 gorithm of crypt(1). An explicitly empty key turns off encryption.
350
351 (_\b._\b+_\b1)z\bz or,
352 (_\b._\b+_\b1)z\bz_\bn
353 This command scrolls through the buffer starting at the addressed
354 line. 22 (or _\bn, if given) lines are printed. The last line print-
355 ed becomes the current line. The value _\bn is sticky, in that it be-
356 comes the default for future z\bz commands.
357
358 (_\b$)=\b= The line number of the addressed line is typed. `_\b.' is unchanged
359 by this command.
360
361 _\b!<shell command>
362 The remainder of the line after the `!\b!' is sent to sh(1) to be in-
363 terpreted as a command. `_\b.' is unchanged.
364
365 (_\b._\b+_\b1,_\b._\b+_\b1)<newline>
366 An address alone on a line causes the addressed line to be printed.
367 A blank line alone is equivalent to _\b._\b+_\b1 it is useful for stepping
368 through text. If two addresses are present with no intervening
369 semicolon, e\bed\bd prints the range of lines. If they are separated by
370 a semicolon, the second line is printed.
371
372 If an interrupt signal (ASCII DEL) is sent, e\bed\bd prints `?interrupted' and
373 returns to its command level.
374
375 Some size limitations: 512 characters per line, 256 characters per global
376 command list, 64 characters per file name, and, on mini computers, 128K
377 characters in the temporary file. The limit on the number of lines de-
378 pends on the amount of core: each line takes 2 words.
379
380 When reading a file, e\bed\bd discards ASCII NUL characters and all characters
381 after the last newline. It refuses to read files containing non- ASCII
382 characters.
383
384F\bFI\bIL\bLE\bES\bS
385 /tmp/e*
386 edhup work is saved here if terminal hangs up
387
388S\bSE\bEE\bE A\bAL\bLS\bSO\bO
389 ex(1), sed(1), crypt(1)
390 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_\bt_\bo_\br
391 B. W. Kernighan, _\bA_\bd_\bv_\ba_\bn_\bc_\be_\bd _\be_\bd_\bi_\bt_\bi_\bn_\bg _\bo_\bn _\bU_\bN_\bI_\bX
392
393H\bHI\bIS\bST\bTO\bOR\bRY\bY
394 The e\bed\bd command appeared in
395
396D\bDI\bIA\bAG\bGN\bNO\bOS\bST\bTI\bIC\bCS\bS
397 `name' for inaccessible file; `?self-explanatory message' for other er-
398 rors.
399
400 To protect against throwing away valuable work, a q\bq or e\be command is con-
401 sidered to be in error, unless a w\bw has occurred since the last buffer
402 change. A second q\bq or e\be will be obeyed regardless.
403
404B\bBU\bUG\bGS\bS
405 The l\bl command mishandles DEL.
406 The u\bun\bnd\bdo\bo command causes marks to be lost on affected lines.
407 The x\bx command, -\b-x\bx option, and special treatment of hangups only work on
408 UNIX.
409
410AT&T 7th Edition December 5, 1992 7