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