BSD 2 release
[unix-history] / man / edit.u
CommitLineData
1d69d2db
BJ
1.TH EDIT UCB 4/8/79 UCB
2.SH NAME
3edit \- text editor (variant of the ex editor for new or casual users)
4.SH SYNOPSIS
5.B edit
6[
7.B \-r
8]
9name ...
10.SH DESCRIPTION
11.I Edit
12is a variant of the text editor
13.I ex
14recommended for new or casual users who wish to use a command oriented editor.
15The following brief introduction should help you get started with
16.I edit.
17A more complete basic introduction is provided by
18.I "Edit: A tutorial".
19A
20.I "Ex/edit command summary (version 2.0)"
21is also very useful.
22See
23.IR ex (UCB)
24for other useful documents;
25in particular, if you are using a \s-2CRT\s0 terminal you will want
26to learn about the display editor
27.I vi.
28.SH "BRIEF INTRODUCTION"
29To edit the contents of an existing file you begin with the command
30``edit name'' to the shell.
31.I Edit
32makes a copy of the file which you can then edit, and tells you how
33many lines and characters are in the file.
34To create a new file, just make up a name for the file and try to run
35.I edit
36on it; you will cause an error diagnostic, but don't worry.
37.PP
38.I Edit
39prompts for commands with the character `:', which you should see after
40starting the editor.
41If you are editing an existing file, then you will have some lines in
42.I edit's
43buffer (its name for the copy of the file you are editing).
44Most commands to
45.I edit
46use its ``current line'' if you don't tell them which line to use.
47Thus if you say
48.B print
49(which can be abbreviated \fBp\fR)
50and hit carriage return (as you should after all
51.I edit
52commands) this current line will be printed.
53If you
54.B delete
55(\fBd\fR) the current line,
56.I edit
57will print the new current line.
58When you start editing,
59.I edit
60makes the last line of the file the current line.
61If you
62.B delete
63this last line, then the new last line becomes the current one.
64In general, after a
65.B delete,
66the next line in the file becomes the current line.
67(Deleting the last line is a special case.)
68.PP
69If you start with an empty file, or wish to add some new lines, then the
70.B append
71(\fBa\fR)
72command can be used.
73After you give this command (typing a carriage return after the
74word \fBappend\fR)
75.I edit
76will read lines from your terminal until you give a line consisting
77of just a ``\fB.\fR'', placing these lines after the current line.
78The last line you type then becomes the current line.
79The command
80.B insert
81(\fBi\fR)
82is like
83.B append
84but places the lines you give before, rather than after, the current line.
85.PP
86.I Edit
87numbers the lines in the buffer, with the first line having number 1.
88If you give the command
89``1''
90then
91.I edit
92will type this first line.
93If you then give the command
94.B delete
95.I edit
96will delete the first line, and line 2 will become line 1, and
97.I edit
98will print the current line (the new line 1) so you can see where you are.
99In general, the current line will always be the last line affected by a command.
100.PP
101You can make a change to some text within the current line by using the
102.B substitute
103(\fBs\fR)
104command.
105You say ``s/\fIold\fR\|/\fInew\fR/'' where
106.I old
107is replaced by the old characters you want
108to get rid of and
109.I new
110is the new characters you want to replace it with.
111.PP
112The command
113.B file
114(\fBf\fR) will tell you how many lines there are in the buffer you are editing
115and will say ``[Modified]'' if you have changed it.
116After modifying a file you can put the buffer text back to replace the file
117by giving a
118.B write
119(\fBw\fR)
120command.
121You can then leave the editor by issuing a
122.B quit
123(\fBq\fR)
124command.
125If you run
126.I edit
127on a file, but don't change it, it is not necessary
128(but does no harm)
129to
130.B write
131the file back.
132If you try to
133.B quit
134from
135.I edit
136after modifying the buffer without writing it out, you will be warned that
137there has been ``No \fBwrite\fR since last change'' and
138.I edit
139will await another command.
140If you wish not to
141.B write
142the buffer out then you can issue another
143.B quit
144command.
145The buffer is then irretrievably discarded, and you return to the shell.
146.PP
147By using the
148.B delete
149and
150.B append
151commands,
152and giving line numbers to see lines in the file you can make any
153changes you desire.
154You should learn at least a few more things, however, if you are to use
155.I edit
156more than a few times.
157.PP
158The
159.B change
160(\fBc\fR)
161command will change the current line to a sequence of lines you supply
162(as in
163.B append
164you give lines up to a line consisting of only a ``.'').
165You can tell
166.B change
167to change more than one line by giving the line numbers of the
168lines you want to change, i.e. ``3,5change''.
169You can print lines this way too.
170Thus ``1,23p'' prints the first 23 lines of the file.
171.PP
172The
173.B undo
174(\fBu\fR)
175command will reverse the effect of the last command you gave which changed
176the buffer.
177Thus if give a
178.B substitute
179command which doesn't do what you want, you can say
180.B undo
181and the old contents of the line will be restored.
182You can also
183.B undo
184an
185.B undo
186command so that you can continue to change your mind.
187.I Edit
188will give you a warning message when commands you do affect more than
189one line of the buffer.
190If the amount of change seems unreasonable, you should consider doing
191an
192.I undo
193and looking to see what happened.
194If you decide that the change is ok, then you can
195.I undo
196again to get it back.
197Note that commands such as
198.I write
199and
200.I quit
201cannot be undone.
202.PP
203To look at the next line in the buffer you can just hit carriage return.
204To look at a number of lines hit ^D (control key and, while it is
205held down D key, then let up both) rather than carriage return.
206This will show you a half screen of lines on a CRT or 12 lines on a hardcopy
207terminal.
208You can look at the text around where you are by giving the command ``z.''.
209The current line will then be the last line printed; you can get back
210to the line where you were before the ``z.'' command by saying ``\'\'''.
211The
212.B z
213command can also be given other following characters ``z\-'' prints
214a screen of text (or 24 lines) ending where you are;
215``z+'' prints the next screenful.
216If you want less than a screenful of lines do, e.g., ``z.12'' to get
21712 lines total.
218This method of giving counts works in general;
219thus you can delete 5 lines starting with the current line with the command
220``delete 5''.
221.PP
222To find things in the file you can use line numbers if you happen to know
223them; since the line numbers change when you insert and delete lines
224this is somewhat unreliable.
225You can search backwards and forwards in the file for strings by giving
226commands of the form
227\fB/text/\fR
228to search forward for
229.I text
230or
231\fB?text?\fR
232to search backward for
233.I text.
234If a search reaches the end of the file without finding the text it
235wraps, end around, and continues to search back to the line where you are.
236A useful feature here is a search of the form
237\fB/^text/\fR
238which searches for
239.I text
240at the beginning of a line.
241Similarly
242\fB/text$/\fR
243searches for
244.I text
245at the end of a line.
246You can leave off the trailing / or ? in these commands.
247.PP
248The current line has a symbolic name ``\fB.\fR''; this is most
249useful in a range of lines as in ``.,$print'' which prints the rest of
250the lines in the file.
251To get to the last line in the file you can refer to it by its symbolic
252name ``$''.
253Thus the command ``$ delete'' or ``$d'' deletes the last line in the
254file, no matter which line was the current line before.
255Arithmetic with line references is also possible.
256Thus the line ``$\-5'' is the fifth before the last, and
257``.+20'' is 20 lines after the present.
258.PP
259You can find out which line you are at by doing
260``.=''.
261This is useful if you wish to move or copy a section of text within a file or
262between files.
263Find out the first and last line numbers you wish to copy or move (say 10 to 20).
264For a move you can then say
265``10,20move "a''
266which deletes these lines from the file and places them in a buffer named
267.I a.
268.I Edit
269has 26 such buffers named
270.I a
271through
272.I z.
273You can later get these lines back by doing
274``"a move \fB.\fR''
275to put the contents of buffer
276.I a
277after the current line.
278If you want to move or copy these lines between files you can give an
279.B edit
280(\fBe\fR)
281command after copying the lines, following it with the name of the other
282file you wish to edit, i.e. ``edit chapter2''.
283By changing
284.I move
285to
286.I copy
287above you can get a pattern for copying lines.
288If the text you wish to move or copy is all within one file
289then you can just say
290``10,20move $''
291for example.
292It is not necessary to use named buffers in this case (but you can if you wish).
293.SH SEE\ ALSO
294ex (UCB), vi (UCB),
295`Edit: A tutorial', by Ricki Blau and James Joyce
296.SH AUTHOR
297William Joy
298.SH BUGS
299See
300.IR ex (UCB).