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