Research V4 development
[unix-history] / man / man1 / ed.1
CommitLineData
b0a60d57
KT
1.th ED I 1/15/73
2.if t .ds q \(aa
3.if n .ds q '
4.sh NAME
5ed \*- editor
6.sh SYNOPSIS
7.bd ed
8[
9.bd \*-
10] [ name ]
11.sh DESCRIPTION
12.it Ed
13is the standard text editor.
14.s3
15If a
16.it name
17argument is given,
18.it ed
19simulates an
20.it e
21command (see below)\| on the named file; that is to say,
22the file is read into
23.it ed's
24buffer so that it can be edited.
25The optional
26.bd \*-
27simulates an
28.bd os
29command (see below)\|
30which suppresses the printing
31of characters counts by
32.it e,
33.it r,
34and
35.it w
36commands.
37.s is suppressed.
38.s3
39.it Ed
40operates on a copy of any file it is editing; changes made
41in the copy have no effect on the file until a \fIw\fR (write)\|
42command is given.
43The copy of the text being edited resides
44in a temporary file called the
45.it buffer.
46There is only
47one buffer.
48.s3
49Commands to
50.it ed
51have a simple and regular structure: zero or
52more
53.it addresses
54followed by a single character
55.it command,
56possibly
57followed by parameters to the command.
58These addresses specify one or more lines in the buffer.
59Every command which requires addresses has default addresses,
60so that the addresses can often be omitted.
61.s3
62In general, only one command may appear on a line.
63Certain commands allow the input of text.
64This text is placed in the appropriate place in the buffer.
65While
66.it ed
67is accepting text, it is said
68to be in
69\fIinput mode.\fR
70In this mode, no commands are recognized;
71all input is merely collected.
72Input mode is left by typing a period `\fB.\fR' alone at the
73beginning of a line.
74.s3
75.it Ed
76supports a limited form of
77.it "regular expression"
78notation.
79A regular expression is an expression which specifies
80a set of strings of characters.
81A member of this set of strings is said to be
82.it matched
83by the regular expression.
84The regular expressions allowed by
85.it ed
86are constructed as follows:
87.s3
88.lp +6 3
891. An ordinary character (not one of those discussed below)\|
90is a regular expression and matches that character.
91.s3
92.lp +6 3
932. A circumflex `^' at the beginning of a regular expression
94matches the null character at the beginning of a line.
95.s3
96.lp +6 3
973. A currency symbol `$' at the end of a regular expression
98matches the null character at the end of a line.
99.s3
100.lp +6 3
1014. A period `\fB.\fR' matches any character but a new-line character.
102.s3
103.lp +6 3
1045. A regular expression followed by an asterisk `*'
105matches any number of adjacent occurrences (including zero)\|
106of the regular expression it follows.
107.s3
108.lp +6 3
1096. A string of characters enclosed in square brackets
110`[ ]' matches any character in the string but no others.
111If, however, the first character of the string is a circumflex
112`^' the regular expression matches any character but new-line
113and the characters in the string.
114.s3
115.lp +6 3
1167. The concatenation of regular expressions is a regular
117expression which matches the concatenation of the strings
118matched by the components of the regular expression.
119.s3
120.lp +6 3
1218. The null regular expression standing alone
122is equivalent to the last regular expression encountered.
123.s3
124.i0
125Regular expressions are used in addresses to specify
126lines and in one command
127(see
128.it s
129below)\|
130to specify a portion of a line which is to be replaced.
131.s3
132If it is desired to use one of
133the regular expression metacharacters as an ordinary
134character, that character may be preceded by `\\'.
135This also applies to the character bounding the regular
136expression (often `/')\| and to `\\' itself.
137.s3
138Addresses are constructed as follows.
139To understand addressing in
140.it ed
141it is necessary to know that at any time there is a
142\fIcurrent line.\fR
143Generally speaking, the current line is
144the last line affected by a command; however,
145the exact effect on the current line
146by each command is discussed under the description of
147the command.
148.s3
149.lp +6 3
1501. The character `\fB.\fR' addresses the current line.
151.s3
152.lp +6 3
1532. The character `^' addresses the line immediately before the current line.
154.s3
155.lp +6 3
1563. The character `$' addresses the last line of the buffer.
157.s3
158.lp +6 3
1594. A decimal number
160.it n
161addresses the
162\fIn\fR-th
163line of the buffer.
164.s3
165.lp +6 3
1665. `\*q\fIx\fR' addresses the line associated (marked)\| with the
167mark name character \fIx\fR
168which must be a printable character.
169Lines are marked with the
170.it k
171command described below.
172.s3
173.lp +6 3
1746. A regular expression enclosed in slashes `/' addresses
175the first line found by searching toward the end of the
176buffer and stopping at the first line containing a
177string matching the regular expression.
178If necessary the search wraps around to the beginning of the
179buffer.
180.s3
181.lp +6 3
1827. A regular expression enclosed in queries `?' addresses
183the first line found by searching toward the beginning of
184the buffer and stopping at the first line found containing
185a string matching the regular expression.
186If necessary
187the search wraps around to the end of the buffer.
188.s3
189.lp +6 3
1908. An address followed by a plus sign `+'
191or a minus sign `\*-' followed by a decimal number specifies that address plus
192(resp. minus)\| the indicated number of lines.
193The plus sign may be omitted.
194.s3
195.i0
196Commands may require zero, one, or two addresses.
197Commands which require no addresses regard the presence
198of an address as an error.
199Commands which accept one or two addresses
200assume default addresses when insufficient are given.
201If more addresses are given than such a command requires,
202the last one or two (depending on what is accepted)\| are used.
203.s3
204Addresses are separated from each other typically by a comma
205`\fB,\fR'.
206They may also be separated by a semicolon
207`\fB;\fR'.
208In this case the current line `\fB.\fR' is set to
209the previous address before the next address is interpreted.
210This feature can be used to determine the starting
211line for forward and backward searches (`/', `?')\|.
212The second address of any two-address sequence
213must correspond to a line following the line corresponding to the first address.
214.s3
215In the following list of
216.it ed
217commands, the default addresses
218are shown in parentheses.
219The parentheses are not part of
220the address, but are used to show that the given addresses are
221the default.
222.s3
223As mentioned, it is generally illegal for more than one
224command to appear on a line.
225However, any command may be suffixed by `p' (for `print')\|.
226In that case, the current line is printed after the command
227is complete.
228.ne 6
229.s3
230.lp +10 5
231( \fB. \fR)\|a
232.lp +10 5
233<text>
234.lp +10 5
235.li
236\fB.\fR
237.lp +10 5
238 The append command reads the given text
239and appends it after the addressed line.
240`\fB.\fR' is left
241on the last line input, if there
242were any, otherwise at the addressed line.
243Address `0' is legal for this command; text is placed
244at the beginning of the buffer.
245.s3
246.lp +10 5
247( \fB. \fR, \fB. \fR)\|c
248.lp +10 5
249<text>
250.lp +10 5
251.li
252\fB.\fR
253.lp +10 5
254 The change
255command deletes the addressed lines, then accepts input
256text which replaces these lines.
257`\fB.\fR' is left at the last line input; if there were none,
258it is left at the first line not changed.
259.s3
260.lp +10 5
261( \fB. \fR, \fB. \fR)\| d
262.br
263The delete command deletes the addressed lines from the buffer.
264The line originally after the last line deleted becomes the current line;
265if the lines deleted were originally at the end,
266the new last line becomes the current line.
267.s3
268.lp +10 5
269e filename
270.br
271The edit
272command causes the entire contents of the buffer to be deleted,
273and then the named file to be read in.
274`\fB.\fR' is set to the last line of the buffer.
275The number of characters read is typed.
276`filename' is remembered for possible use as a default file name
277in a subsequent
278.it r
279or
280.it w
281command.
282.s3
283.lp +10 5
284f filename
285.br
286The filename command prints the currently remembered file name.
287If `filename' is given,
288the currently remembered file name is changed to `filename'.
289.s3
290.lp +10 5
291(1,$)\|g/regular expression/command list
292.br
293In the global
294command, the first step is to mark every line which matches
295the given regular expression.
296Then for every such line, the
297given command list is executed with `\fB.\fR' initially set to that line.
298A single command or the first of multiple commands
299appears on the same line with the global command.
300All lines of a multi-line list except the last line must be ended with `\\'.
301.it A,
302.it i,
303and
304.it c
305commands and associated input are permitted;
306the `\fB.\fR' terminating input mode may be omitted if it would be on the
307last line of the command list.
308The (global)\| commands,
309.it g,
310and
311.it v,
312are not permitted in the command list.
313.s3
314.lp +10 5
315( \fB. \fR)\|i
316.lp +10 5
317<text>
318.lp +10 5
319.li
320\1f.
321.br
322This command inserts the given text before the addressed line.
323`\fB.\fR' is left at the last line input; if there were none,
324at the addressed line.
325This command differs from the
326.it a
327command only in the placement of the
328text.
329.s3
330.lp +10 5
331( \fB. \fR)\|k\fIx\fR
332.br
333The mark command associates or marks the addressed line with
334the single character mark name
335.it x.
336The ten most recent mark names are remembered.
337The current mark names may be printed with the
338.it n
339command.
340.s3
341.lp +10 5
342( \fB. \fR, \fB. \fR)\|m\fIa\fR
343.br
344The move command will reposition the addressed lines after the line
345addressed by
346.it a.
347The last of the moved lines becomes the current line.
348.s3
349.lp +10 5
350n
351.br
352The \fIn\fR command will print the current mark names.
353.s3
354.lp +10 5
355os
356.lp +10 5
357ov
358.br
359After
360.it os
361character counts printed by
362.it "e, r,"
363and
364.it w
365are suppressed.
366.it Ov
367turns them back on.
368.s3
369.lp +10 5
370( \fB. \fR, \fB. \fR)\|p
371.br
372The print command prints the addressed lines.
373`\fB.\fR'
374is left at the last line printed.
375The
376.it p
377command
378.it may
379be placed on the same line after any command.
380.s3
381.lp +10 5
382q
383.br
384The quit command causes
385.it ed
386to exit.
387No automatic write
388of a file is done.
389.s3
390.lp +10 5
391($)\|r filename
392.br
393The read command
394reads in the given file after the addressed line.
395If no file name is given,
396the remembered file name, if any, is used
397(see
398.it e
399and
400.it f
401commands)\|.
402The remembered file name is not changed unless
403`filename' is the very first file name
404mentioned.
405Address `0' is legal for
406.it r
407and causes the
408file to be read at the beginning of the buffer.
409If the read is successful, the number of characters
410read is typed.
411`\fB.\fR' is left at the last line read in from the file.
412.s3
413.lp +10 5
414( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/ or,
415.lp +10 5
416( \fB. \fR, \fB. \fR)\|s/regular expression/replacement/g
417.br
418The substitute command searches each addressed
419line for an occurrence of the specified regular expression.
420On each line in which a match is found,
421all matched strings are replaced by the replacement specified,
422if the global replacement indicator `g' appears after the command.
423If the global indicator does not appear, only the first occurrence
424of the matched string is replaced.
425It is an error for the substitution to fail on all addressed lines.
426Any character other than space or new-line
427may be used instead of `/' to delimit the regular expression
428and the replacement.
429`\fB.\fR' is left at the last line substituted.
430.s3
431An ampersand `&' appearing in the replacement
432is replaced by the regular expression that was matched.
433The special meaning of `&' in this context may be
434suppressed by preceding it by `\\'.
435.s3
436.lp +10 5
437(1,$)\|v/regular expression/command list
438.br
439This command is the same as the global command
440except that the command list is executed
441with `\fB.\fR' initially set to every line
442.it except
443those
444matching the regular expression.
445.s3
446.lp +10 5
447(1,$)\|w filename
448.br
449The write command writes the addressed lines onto
450the given file.
451If the file does not exist,
452it is created mode 666 (readable and writeable by everyone)\|.
453The remembered file name is
454.it not
455changed unless
456`filename' is the very first file name mentioned.
457If no file name is given,
458the remembered file name, if any, is used
459(see
460.it e
461and
462.it f
463commands)\|.
464`\fB.\fR' is unchanged.
465If the command is successful, the number of characters written is
466typed.
467.s3
468.lp +10 5
469($)\|=
470.br
471The line number of the addressed line is typed.
472`\fB.\fR' is unchanged by this command.
473.s3
474.lp +10 5
475!UNIX command
476.br
477The remainder of the line after the `!' is sent
478to UNIX to be interpreted as a command.
479`\fB.\fR' is unchanged.
480The entire shell syntax is not
481recognized.
482See msh(VII) for the restrictions.
483.s3
484.lp +10 5
485( \fB.\fR+1 )\|<newline>
486.br
487An address alone on a line causes the addressed line to be printed.
488A blank line alone is equivalent to `.+1p'; it is useful
489for stepping through text.
490.s3
491.i0
492If an interrupt signal (ASCII DEL)\| is sent,
493.it ed
494will print a `?' and return to its command level.
495.s3
496If invoked with the command name `\*-',
497(see init(VII)\|)\|
498.it ed
499will sign on with the message `Editing system'
500and print `*' as the command level prompt character.
501.s3
502.it Ed
503has size limitations on the maximum number of lines that can be edited,
504on the maximum number of characters in a line,
505in a global's command list,
506in a remembered file name,
507and in the size of the temporary file.
508The current sizes are:
5094000 lines per file,
510512 characters per line,
511256 characters per global command list,
51264 characters per file name,
513and 64K characters in the temporary file (see BUGS)\|.
514.sh FILES
515/tmp/etm?, temporary
516.br
517/etc/msh, to implement the `!' command.
518.sh DIAGNOSTICS
519`?' for
520errors in commands;
521`TMP' for temporary file overflow.
522.sh BUGS
523The temporary file can grow to no more than 64K bytes.