0
|
1 Copyright (c) 1985, 1994 Free Software Foundation, Inc.
|
|
2 See end for conditions.
|
|
3
|
|
4 You are looking at the Emacs tutorial.
|
|
5
|
|
6 Emacs commands generally involve the CONTROL key (sometimes labelled
|
|
7 CTRL or CTL) or the META key. On some keyboards, the META key is
|
|
8 labelled ALT or EDIT or something else (for example, on Sun keyboards,
|
|
9 the diamond key to the left of the spacebar is META). If you have no
|
|
10 META key, you can use ESC instead. Rather than write out META or
|
|
11 CONTROL each time we want you to prefix a character, we'll use the
|
|
12 following abbreviations:
|
|
13
|
|
14 C-<chr> means hold the CONTROL key while typing the character <chr>
|
|
15 Thus, C-f would be: hold the CONTROL key and type f.
|
|
16 M-<chr> means hold the META key down while typing <chr>. If there
|
|
17 is no META key, type <ESC>, release it, then type the
|
|
18 character <chr>.
|
|
19
|
|
20 Important note: to end the Emacs session, type C-x C-c. (Two characters.)
|
|
21 The characters ">>" at the left margin indicate directions for you to
|
|
22 try using a command. For instance:
|
|
23 <<Blank lines inserted here by startup of help-with-tutorial>>
|
|
24 >> Now type C-v (View next screen) to move to the next screen.
|
|
25 (go ahead, do it by depressing the control key and v together).
|
|
26 From now on, you'll be expected to do this whenever you finish
|
|
27 reading the screen.
|
|
28
|
|
29 Note that there is an overlap when going from screen to screen; this
|
|
30 provides some continuity when moving through the file.
|
|
31
|
|
32 The first thing that you need to know is how to move around from
|
|
33 place to place in the file. You already know how to move forward a
|
|
34 screen, with C-v. To move backwards a screen, type M-v (depress the
|
|
35 META key and type v, or type <ESC>v if you don't have a META or EDIT
|
|
36 key).
|
|
37
|
|
38 >> Try typing M-v and then C-v to move back and forth a few times.
|
|
39
|
|
40
|
|
41 SUMMARY
|
|
42 -------
|
|
43
|
|
44 The following commands are useful for viewing screenfuls:
|
|
45
|
|
46 C-v Move forward one screenful
|
|
47 M-v Move backward one screenful
|
|
48 C-l Clear screen and redisplay everything
|
|
49 putting the text near the cursor at the center.
|
|
50 (That's control-L, not control-1. control-1
|
|
51 has a completely different meaning, as
|
|
52 described below.)
|
|
53
|
|
54 >> Find the cursor and remember what text is near it.
|
|
55 Then type a C-l.
|
|
56 Find the cursor again and see what text is near it now.
|
|
57
|
|
58
|
|
59 BASIC CURSOR CONTROL
|
|
60 --------------------
|
|
61
|
|
62 Getting from screenful to screenful is useful, but how do you
|
|
63 reposition yourself within a given screen to a specific place?
|
|
64 There are several ways you can do this. One way (not the best, but
|
|
65 the most basic) is to use the commands previous, backward, forward
|
|
66 and next. As you can imagine these commands (which are given to
|
|
67 Emacs as C-p, C-b, C-f, and C-n respectively) move the cursor from
|
|
68 where it currently is to a new place in the given direction. Here,
|
|
69 in a more graphical form are the commands:
|
|
70
|
|
71 Previous line, C-p
|
|
72 :
|
|
73 :
|
|
74 Backward, C-b .... Current cursor position .... Forward, C-f
|
|
75 :
|
|
76 :
|
|
77 Next line, C-n
|
|
78
|
|
79 >> Move the cursor to the line in the middle of that diagram
|
|
80 and type C-l to see the whole diagram centered in the screen.
|
|
81
|
|
82 You'll probably find it easy to think of these by letter. P for
|
|
83 previous, N for next, B for backward and F for forward. These are
|
|
84 the basic cursor positioning commands and you'll be using them ALL
|
|
85 the time so it would be of great benefit if you learn them now.
|
|
86
|
|
87 >> Do a few C-n's to bring the cursor down to this line.
|
|
88
|
|
89 >> Move into the line with C-f's and then up with C-p's.
|
|
90 See what C-p does when the cursor is in the middle of the line.
|
|
91
|
|
92 Lines are separated by Newline characters. For most applications
|
|
93 there should normally be a Newline character at the end of the text,
|
|
94 as well, but it is up to you to make sure of this. A file can
|
|
95 validly exist without a Newline at the end.
|
|
96
|
|
97 >> Try to C-b at the beginning of a line. Do a few more C-b's.
|
|
98 Then do C-f's back to the end of the line and beyond.
|
|
99
|
|
100 When you go off the top or bottom of the screen, the text beyond
|
|
101 the edge is shifted onto the screen so that your instructions can
|
|
102 be carried out while keeping the cursor on the screen.
|
|
103
|
|
104 >> Try to move the cursor off the bottom of the screen with C-n and
|
|
105 see what happens.
|
|
106
|
|
107 If moving by characters is too slow, you can move by words. M-f
|
|
108 (Meta-f) moves forward a word and M-b moves back a word.
|
|
109
|
|
110 >> Type a few M-f's and M-b's. Intersperse them with C-f's and C-b's.
|
|
111
|
|
112 Notice the parallel between C-f and C-b on the one hand, and M-f and
|
|
113 M-b on the other hand. Very often Meta characters are used for
|
|
114 operations related to English text whereas Control characters operate
|
|
115 on the basic textual units that are independent of what you are
|
|
116 editing (characters, lines, etc). There is a similar parallel between
|
|
117 lines and sentences: C-a and C-e move to the beginning or end of a
|
|
118 line, and M-a and M-e move to the beginning or end of a sentence.
|
|
119
|
|
120 >> Try a couple of C-a's, and then a couple of C-e's.
|
|
121 Try a couple of M-a's, and then a couple of M-e's.
|
|
122
|
|
123 See how repeated C-a's do nothing, but repeated M-a's keep moving
|
|
124 farther. Do you think that this is right?
|
|
125
|
|
126 Two other simple cursor motion commands are M-< (Meta Less-than),
|
|
127 which moves to the beginning of the file, and M-> (Meta Greater-than),
|
|
128 which moves to the end of the file. You probably don't need to try
|
|
129 them, since finding this spot again will be boring. On most terminals
|
|
130 the "<" is above the comma and you must use the shift key to type it.
|
|
131 On these terminals you must use the shift key to type M-< also;
|
|
132 without the shift key, you would be typing M-comma.
|
|
133
|
|
134 The location of the cursor in the text is also called "point". To
|
|
135 paraphrase, the cursor shows on the screen where point is located in
|
|
136 the text.
|
|
137
|
|
138 Here is a summary of simple moving operations including the word and
|
|
139 sentence moving commands:
|
|
140
|
|
141 C-f Move forward a character
|
|
142 C-b Move backward a character
|
|
143
|
|
144 M-f Move forward a word
|
|
145 M-b Move backward a word
|
|
146
|
|
147 C-n Move to next line
|
|
148 C-p Move to previous line
|
|
149
|
|
150 C-a Move to beginning of line
|
|
151 C-e Move to end of line
|
|
152
|
|
153 M-a Move back to beginning of sentence
|
|
154 M-e Move forward to end of sentence
|
|
155
|
|
156 M-< Go to beginning of file
|
|
157 M-> Go to end of file
|
|
158
|
|
159 >> Try all of these commands now a few times for practice.
|
|
160 Since the last two will take you away from this screen,
|
|
161 you can come back here with M-v's and C-v's. These are
|
|
162 the most often used commands.
|
|
163
|
|
164 Like all other commands in Emacs, these commands can be given
|
|
165 arguments which cause them to be executed repeatedly. The way you
|
|
166 give a command a repeat count is by typing C-u and then the digits
|
|
167 before you type the command. If you have a META or EDIT key, you can
|
|
168 omit the C-u if you hold down the META or EDIT key while you type the
|
|
169 digits. This is easier, but we recommend the C-u method because it
|
|
170 works on any terminal.
|
|
171
|
|
172 For instance, C-u 8 C-f moves forward eight characters.
|
|
173
|
|
174 >> Try giving a suitable argument to C-n or C-p to come as close
|
|
175 as you can to this line in one jump.
|
|
176
|
|
177 The only apparent exception to this is the screen moving commands,
|
|
178 C-v and M-v. When given an argument, they scroll the screen up or
|
|
179 down by that many lines, rather than screenfuls. This proves to be
|
|
180 much more useful.
|
|
181
|
|
182 >> Try typing C-u 8 C-v now.
|
|
183
|
|
184 Did it scroll the screen up by 8 lines? If you would like to
|
|
185 scroll it down you can give an argument to M-v.
|
|
186
|
|
187
|
|
188 CURSOR CONTROL WITH AN X TERMINAL
|
|
189 ---------------------------------
|
|
190
|
|
191 If you have an X terminal, you will probably find it easier to use
|
|
192 the keys on the keypad to control the cursor. The left, right, up,
|
|
193 and down arrow keys move in the expected direction; they function
|
|
194 exactly like C-b, C-f, C-p, and C-n, but are easier to type and to
|
|
195 remember. You can also use C-left and C-right to move by words, and
|
|
196 C-up and C-down to move by blocks (e.g. paragraphs, if you're
|
|
197 editing text). If you have keys labelled HOME (or BEGIN) and END,
|
|
198 they will take you to the beginning and end of a line, respectively,
|
|
199 and C-home and C-end will move to the beginning and end of the file.
|
|
200 If your keyboard has PgUp and PgDn keys, you can use them to move up
|
|
201 and down a screenful at a time, like M-v and C-v.
|
|
202
|
|
203 All of these commands can take numeric arguments, as described above.
|
|
204 You can use a shortcut to enter these arguments: just hold down the
|
|
205 CONTROL or META key and type the number. For example, to move 12
|
|
206 words to the right, type C-1 C-2 C-right. Note that it is very easy
|
|
207 to type this because you do not have to release the CONTROL key
|
|
208 between keystrokes.
|
|
209
|
|
210
|
|
211 WHEN EMACS IS HUNG
|
|
212 ------------------
|
|
213
|
|
214 If Emacs gets into an infinite (or simply very long) computation which
|
|
215 you don't want to finish, you can stop it safely by typing C-g.
|
|
216 You can also use C-g to discard a numeric argument or the beginning of
|
|
217 a command that you don't want to finish.
|
|
218
|
|
219 >> Type C-u 100 to make a numeric arg of 100, then type C-g.
|
|
220 Now type C-f. How many characters does it move?
|
|
221 If you have typed an <ESC> by mistake, you can get rid of it
|
|
222 with a C-g.
|
|
223
|
|
224 If you type <ESC> <ESC>, you get a new window appearing on
|
|
225 the screen, telling you that M-ESC is a "disabled command"
|
|
226 and asking whether you really want to execute it. The command
|
|
227 M-ESC is marked as disabled because you probably don't want to
|
|
228 use it until you know more about Emacs, and we expect it would
|
|
229 confuse you if it were allowed to go ahead and run. If you really
|
|
230 want to try the M-ESC command, you could type a Space in answer
|
|
231 to the question and M-ESC would go ahead. Normally, if you do
|
|
232 not want to execute M-ESC, you would type "n" to answer the question.
|
|
233
|
|
234 >> Type <ESC> <ESC>, then type n.
|
|
235
|
|
236
|
|
237 WINDOWS
|
|
238 -------
|
|
239
|
|
240 Emacs can have several windows, each displaying its own text.
|
|
241 Note that "window" as used by Emacs does not refer to separate
|
|
242 overlapping windows in the window system, but to separate panes
|
|
243 within a single X window. (Emacs can also have multiple X
|
|
244 windows, or "screens" in Emacs terminology. This is described
|
|
245 later.)
|
|
246
|
|
247 At this stage it is better not to go into the techniques of
|
|
248 using multiple windows. But you do need to know how to get
|
|
249 rid of extra windows that may appear to display help or
|
|
250 output from certain commands. It is simple:
|
|
251
|
|
252 C-x 1 One window (i.e., kill all other windows).
|
|
253
|
|
254 That is Control-x followed by the digit 1.
|
|
255 C-x 1 makes the window which the cursor is in become
|
|
256 the full screen, by getting rid of any other windows.
|
|
257
|
|
258 >> Move the cursor to this line and type C-u 0 C-l.
|
|
259
|
|
260 (Remember that C-l redraws the screen. If you give a
|
|
261 numeric argument to this command, it means "redraw the
|
|
262 screen and put the current line that many lines from the
|
|
263 top of the screen." So C-u 0 C-l means "redraw the
|
|
264 screen, putting the current line at the top.")
|
|
265
|
|
266 >> Type Control-h k Control-f.
|
|
267 See how this window shrinks, while a new one appears
|
|
268 to display documentation on the Control-f command.
|
|
269
|
|
270 >> Type C-x 1 and see the documentation listing window disappear.
|
|
271
|
|
272
|
|
273 INSERTING AND DELETING
|
|
274 ----------------------
|
|
275
|
|
276 If you want to insert text, just type it. Characters which you can
|
|
277 see, such as A, 7, *, etc. are taken by Emacs as text and inserted
|
|
278 immediately. Type <Return> (the carriage-return key) to insert a
|
|
279 Newline character.
|
|
280
|
|
281 You can delete the last character you typed by typing <Rubout>.
|
|
282 On X terminals, <Rubout> is normally the key labelled BACK SPACE.
|
|
283
|
|
284 >> Do this now, type a few characters and then delete them
|
|
285 by typing <Rubout> a few times. Don't worry about this file
|
|
286 being changed; you won't affect the master tutorial. This is just
|
|
287 a copy of it.
|
|
288
|
|
289 >> Now start typing text until you reach the right margin, and keep
|
|
290 typing. When a line of text gets too big for one line on the
|
|
291 screen, the line of text is "continued" onto a second screen line.
|
|
292 The backslash at the right margin indicates a line which has
|
|
293 been continued.
|
|
294 >> Use <Rubout>s to delete the text until the line fits on one screen
|
|
295 line again. The continuation line goes away.
|
|
296
|
|
297 >> Move the cursor to the beginning of a line and type <Rubout>. This
|
|
298 deletes the newline before the line and merges the line onto
|
|
299 the previous line. The resulting line may be too long to fit, in
|
|
300 which case it has a continuation line.
|
|
301 >> Type <Return> to reinsert the Newline you deleted.
|
|
302
|
|
303 Remember that most Emacs commands can be given a repeat count;
|
|
304 this includes characters which insert themselves.
|
|
305
|
|
306 >> Try that now -- type C-u 8 * and see what happens.
|
|
307
|
|
308 You've now learned the most basic way of typing something in
|
|
309 Emacs and correcting errors. You can delete by words or lines
|
|
310 as well. Here is a summary of the delete operations:
|
|
311
|
|
312 <Rubout> delete the character just before the cursor
|
|
313 C-d delete the next character after the cursor
|
|
314
|
|
315 M-<Rubout> kill the word immediately before the cursor
|
|
316 M-d kill the next word after the cursor
|
|
317
|
|
318 C-k kill from the cursor position to end of line
|
|
319 M-k kill to the end of the current sentence
|
|
320
|
|
321 Notice that <Rubout> and C-d vs M-<Rubout> and M-d extend the parallel
|
|
322 started by C-f and M-f (well, <Rubout> isn't really a control
|
|
323 character, but let's not worry about that). C-k and M-k are like C-e
|
|
324 and M-e, sort of, in that lines are opposite sentences.
|
|
325
|
|
326 Now suppose you kill something, and then you decide that you want to
|
|
327 get it back? Well, whenever you kill something bigger than a
|
|
328 character, Emacs saves it for you. To yank it back, use C-y. You
|
|
329 can kill text in one place, move elsewhere, and then do C-y; this is
|
|
330 a good way to move text around. Note that the difference
|
|
331 between "Killing" and "Deleting" something is that "Killed" things
|
|
332 can be yanked back, and "Deleted" things cannot. Generally, the
|
|
333 commands that can destroy a lot of text save it, while the ones that
|
|
334 attack only one character, or nothing but blank lines and spaces, do
|
|
335 not save.
|
|
336
|
|
337 For instance, type C-n a couple times to postion the cursor
|
|
338 at some line on this screen.
|
|
339
|
|
340 >> Do this now, move the cursor and kill that line with C-k.
|
|
341
|
|
342 Note that a single C-k kills the contents of the line, and a second
|
|
343 C-k kills the line itself, and make all the other lines move up. If
|
|
344 you give C-k a repeat count, it kills that many lines AND their
|
|
345 contents.
|
|
346
|
|
347 The text that has just disappeared is saved so that you can
|
|
348 retrieve it. To retrieve the last killed text and put it where
|
|
349 the cursor currently is, type C-y.
|
|
350
|
|
351 >> Try it; type C-y to yank the text back.
|
|
352
|
|
353 Think of C-y as if you were yanking something back that someone
|
|
354 took away from you. Notice that if you do several C-k's in a row
|
|
355 the text that is killed is all saved together so that one C-y will
|
|
356 yank all of the lines.
|
|
357
|
|
358 >> Do this now, type C-k several times.
|
|
359
|
|
360 Now to retrieve that killed text:
|
|
361
|
|
362 >> Type C-y. Then move the cursor down a few lines and type C-y
|
|
363 again. You now see how to copy some text.
|
|
364
|
|
365 What do you do if you have some text you want to yank back, and then
|
|
366 you kill something else? C-y would yank the more recent kill. But
|
|
367 the previous text is not lost. You can get back to it using the M-y
|
|
368 command. After you have done C-y to get the most recent kill, typing
|
|
369 M-Y replaces that yanked text with the previous kill. Typing M-y
|
|
370 again and again brings in earlier and earlier kills. When you
|
|
371 have reached the text you are looking for, you can just go away and
|
|
372 leave it there. If you M-y enough times, you come back to the
|
|
373 starting point (the most recent kill).
|
|
374
|
|
375 >> Kill a line, move around, kill another line.
|
|
376 Then do C-y to get back the second killed line.
|
|
377 Then do M-y and it will be replaced by the first killed line.
|
|
378 Do more M-y's and see what you get. Keep doing them until
|
|
379 the second kill line comes back, and then a few more.
|
|
380 If you like, you can try giving M-y positive and negative
|
|
381 arguments.
|
|
382
|
|
383
|
|
384 UNDO
|
|
385 ----
|
|
386
|
|
387 Any time you make a change to the text and wish you had not done so,
|
|
388 you can undo the change (return the text to its previous state)
|
|
389 with the undo command, C-x u. Normally, C-x u undoes one command's
|
|
390 worth of changes; if you repeat the C-x u several times in a row,
|
|
391 each time undoes one more command. There are two exceptions:
|
|
392 commands that made no change (just moved the cursor) do not count,
|
|
393 and self-inserting characters are often lumped together in groups
|
|
394 of up to 20. This is to reduce the number of C-x u's you have to type.
|
|
395
|
|
396 >> Kill this line with C-k, then type C-x u and it should reappear.
|
|
397
|
|
398 C-_ is another command for undoing; it is just the same as C-x u
|
|
399 but easier to type several times in a row. The problem with C-_ is
|
|
400 that on some keyboards it is not obvious how to type it. That is
|
|
401 why C-x u is provided as well. On some DEC terminals, you can type
|
|
402 C-_ by typing / while holding down CTRL. Illogical, but what can
|
|
403 you expect from DEC?
|
|
404
|
|
405 Giving a numeric argument to C-_ or C-x u is equivalent to repeating
|
|
406 it as many times as the argument says.
|
|
407
|
|
408
|
|
409 FILES
|
|
410 -----
|
|
411
|
|
412 In order to make the text you edit permanent, you must put it in a
|
|
413 file. Otherwise, it will go away when your invocation of Emacs goes
|
|
414 away. You put your editing in a file by "finding" the file. What
|
|
415 finding means is that you see the contents of the file in your Emacs;
|
|
416 and, loosely speaking, what you are editing is the file itself.
|
|
417 However, the changes still don't become permanent until you "save" the
|
|
418 file. This is so you can have control to avoid leaving a half-changed
|
|
419 file around when you don't want to. Even then, Emacs leaves the
|
|
420 original file under a changed name in case your changes turn out
|
|
421 to be a mistake.
|
|
422
|
|
423 If you look near the bottom of the screen you will see a line that
|
|
424 begins and ends with dashes, and contains the string "Emacs: TUTORIAL".
|
|
425 Your copy of the Emacs tutorial is called "TUTORIAL". Whatever
|
|
426 file you find, that file's name will appear in that precise
|
|
427 spot.
|
|
428
|
|
429 The commands for finding and saving files are unlike the other
|
|
430 commands you have learned in that they consist of two characters.
|
|
431 They both start with the character Control-x. There is a whole series
|
|
432 of commands that start with Control-x; many of them have to do with
|
|
433 files, buffers, and related things, and all of them consist of
|
|
434 Control-x followed by some other character.
|
|
435
|
|
436 Another thing about the command for finding a file is that you have
|
|
437 to say what file name you want. We say the command "reads an argument
|
|
438 from the terminal" (in this case, the argument is the name of the
|
|
439 file). After you type the command
|
|
440
|
|
441 C-x C-f Find a file
|
|
442
|
|
443 Emacs asks you to type the file name. It echoes on the bottom
|
|
444 line of the screen. You are using the minibuffer now! this is
|
|
445 what the minibuffer is for. When you type <Return> to end the
|
|
446 file name, the minibuffer is no longer needed, so it disappears.
|
|
447
|
|
448 >> Type C-x C-f, then type C-g. This cancels the minibuffer,
|
|
449 and also cancels the C-x C-f command that was using the
|
|
450 minibuffer. So you do not find any file.
|
|
451
|
|
452 In a little while the file contents appear on the screen. You can
|
|
453 edit the contents. When you wish to make the changes permanent,
|
|
454 issue the command
|
|
455
|
|
456 C-x C-s Save the file
|
|
457
|
|
458 The contents of Emacs are written into the file. The first time you
|
|
459 do this, the original file is renamed to a new name so that it
|
|
460 is not lost. The new name is made by appending "~" to the end
|
|
461 of the original file's name.
|
|
462
|
|
463 When saving is finished, Emacs prints the name of the file written.
|
|
464 You should save fairly often, so that you will not lose very much
|
|
465 work if the system should crash.
|
|
466
|
|
467 >> Type C-x C-s, saving your copy of the tutorial.
|
|
468 This should print "Wrote .../TUTORIAL" at the bottom of the screen.
|
|
469 On VMS it will print "Wrote ...[...]TUTORIAL."
|
|
470
|
|
471 To make a new file, just find it "as if" it already existed. Then
|
|
472 start typing in the text. When you ask to "save" the file, Emacs
|
|
473 will really create the file with the text that you have inserted.
|
|
474 From then on, you can consider yourself to be editing an already
|
|
475 existing file.
|
|
476
|
|
477
|
|
478 BUFFERS
|
|
479 -------
|
|
480
|
|
481 If you find a second file with C-x C-f, the first file remains
|
|
482 inside Emacs. You can switch back to it by finding it again with
|
|
483 C-x C-f. This way you can get quite a number of files inside Emacs.
|
|
484
|
|
485 The object inside Emacs which holds the text read from one file
|
|
486 is called a "buffer." Finding a file makes a new buffer inside Emacs.
|
|
487 To see a list of the buffers that exist in Emacs, type
|
|
488
|
|
489 C-x C-b List buffers
|
|
490
|
|
491 >> Try C-x C-b now.
|
|
492
|
|
493 See how each buffer has a name, and it may also have a file name
|
|
494 for the file whose contents it holds. Some buffers do not correspond
|
|
495 to files. For example, the buffer named "*Buffer List*" does
|
|
496 not have any file. It is the buffer which contains the buffer
|
|
497 list that was made by C-x C-b. ANY text you see in an Emacs window
|
|
498 has to be in some buffer.
|
|
499
|
|
500 >> Type C-x 1 to get rid of the buffer list.
|
|
501
|
|
502 If you make changes to the text of one file, then find another file,
|
|
503 this does not save the first file. Its changes remain inside Emacs,
|
|
504 in that file's buffer. The creation or editing of the second file's
|
|
505 buffer has no effect on the first file's buffer. This is very useful,
|
|
506 but it also means that you need a convenient way to save the first
|
|
507 file's buffer. It would be a nuisance to have to switch back to
|
|
508 it with C-x C-f in order to save it with C-x C-s. So we have
|
|
509
|
|
510 C-x s Save some buffers
|
|
511
|
|
512 C-x s goes through the list of all the buffers you have
|
|
513 and finds the ones that contain files you have changed.
|
|
514 For each such buffer, C-x s asks you whether to save it.
|
|
515
|
|
516
|
|
517 USING THE MENU
|
|
518 --------------
|
|
519
|
|
520 If you are on an X terminal, you will notice a menubar at the
|
|
521 top of the Emacs screen. You can use this menubar to access all
|
|
522 the most common Emacs commands, such as "find file". You will
|
|
523 find this easier at first, because you don't need to remember
|
|
524 the keystrokes necessary to access any particular command. Once
|
|
525 you are comfortable with Emacs, it will be easy to begin using
|
|
526 the keyboard commands because each menu item with a
|
|
527 corresponding keyboard command has the command listed next to
|
|
528 it.
|
|
529
|
|
530 Note that there are many items in the menubar that have no exact
|
|
531 keyboard equivalents. For example, the Buffers menu lists all
|
|
532 of the available buffers in most-recently used order. You can
|
|
533 switch to any buffer by simply findings its name in the Buffers
|
|
534 menu and selecting it.
|
|
535
|
|
536
|
|
537 USING THE MOUSE
|
|
538 ---------------
|
|
539
|
|
540 When running under X, Emacs is fully integrated with the mouse.
|
|
541 You can position the text cursor by clicking the left button at
|
|
542 the desired location, and you can select text by dragging the
|
|
543 left mouse button across the text you want to select. (Or
|
|
544 alternatively, click the left mouse button at one end of the
|
|
545 text, then move to the other end and use Shift-click to select
|
|
546 the text.)
|
|
547
|
|
548 To kill some selected text, you can use C-w or choose the Cut
|
|
549 item from the Edit menu. Note that these are *not* equivalent:
|
|
550 C-w only saves the text internally within Emacs (similar to C-k
|
|
551 as described above), whereas Cut does this and also puts the
|
|
552 text into the X clipboard, where it can be accessed by other
|
|
553 applications.
|
|
554
|
|
555 To retrieve text from the X clipboard, use the Paste item from
|
|
556 the Edit menu.
|
|
557
|
|
558 The middle mouse button is commonly used to choose items that
|
|
559 are visible on the screen. For example, if you enter Info (the
|
|
560 on-line Emacs documentation) using C-h i or the Help menu, you
|
|
561 can follow a highlighted link by clicking the middle mouse
|
|
562 button on it. Similarly, if you are typing a file name in
|
|
563 (e.g. when prompted by "Find File") and you hit TAB to show the
|
|
564 possible completions, you can click the middle mouse button on
|
|
565 one of the completions to select it.
|
|
566
|
|
567 The right mouse button brings up a popup menu. The contents of
|
|
568 this menu vary depending on what mode you're in, and usually
|
|
569 contain a few commonly used commands, so they're easier to
|
|
570 access.
|
|
571
|
|
572 >> Press the right mouse button now.
|
|
573
|
|
574 You will have to hold the button down in order to keep the
|
|
575 menu up.
|
|
576
|
|
577
|
|
578 EXTENDING THE COMMAND SET
|
|
579 -------------------------
|
|
580
|
|
581 There are many, many more Emacs commands than could possibly be put
|
|
582 on all the control and meta characters. Emacs gets around this with
|
|
583 the X (eXtend) command. This comes in two flavors:
|
|
584
|
|
585 C-x Character eXtend. Followed by one character.
|
|
586 M-x Named command eXtend. Followed by a long name.
|
|
587
|
|
588 These are commands that are generally useful but used less than the
|
|
589 commands you have already learned about. You have already seen two
|
|
590 of them: the file commands C-x C-f to Find and C-x C-s to Save.
|
|
591 Another example is the command to tell Emacs that you'd like to stop
|
|
592 editing and get rid of Emacs. The command to do this is C-x C-c.
|
|
593 (Don't worry; it offers to save each changed file before it kills the
|
|
594 Emacs.)
|
|
595
|
|
596 C-z is the usual way to exit Emacs, because it is always better not to
|
|
597 kill the Emacs if you are going to do any more editing. On systems
|
|
598 which allow it, C-z exits from Emacs to the shell but does not destroy
|
|
599 the Emacs; if you use the C shell, you can resume Emacs with the `fg'
|
|
600 command (or, more generally, with `%emacs', which works even if your
|
|
601 most recent job was some other). On systems where suspending is not
|
|
602 possible, C-z creates a subshell running under Emacs to give you the
|
|
603 chance to run other programs and return to Emacs afterward, but it
|
|
604 does not truly "exit" from Emacs. In this case, the shell command
|
|
605 `exit' is the usual way to get back to Emacs from the subshell.
|
|
606
|
|
607 You would use C-x C-c if you were about to log out. You would
|
|
608 also use it to exit an Emacs invoked under mail handling programs
|
|
609 and other random utilities, since they may not believe you have
|
|
610 really finished using the Emacs if it continues to exist.
|
|
611
|
|
612 There are many C-x commands. The ones you know are:
|
|
613
|
|
614 C-x C-f Find file.
|
|
615 C-x C-s Save file.
|
|
616 C-x C-b List buffers.
|
|
617 C-x C-c Quit Emacs.
|
|
618 C-x u Undo.
|
|
619
|
|
620 Named eXtended commands are commands which are used even less
|
|
621 frequently, or commands which are used only in certain modes. These
|
|
622 commands are usually called "functions". An example is the function
|
|
623 replace-string, which globally replaces one string with another. When
|
|
624 you type M-x, Emacs prompts you at the bottom of the screen with
|
|
625 M-x and you should type the name of the function you wish to call; in
|
|
626 this case, "replace-string". Just type "repl s<TAB>" and Emacs will
|
|
627 complete the name. End the command name with <Return>.
|
|
628 Then type the two "arguments"--the string to be replaced, and the string
|
|
629 to replace it with--each one ended with a Return.
|
|
630
|
|
631 >> Move the cursor to the blank line two lines below this one.
|
|
632 Then type M-x repl s<Return>changed<Return>altered<Return>.
|
|
633
|
|
634 Notice how this line has changed: you've replaced
|
|
635 the word c-h-a-n-g-e-d with "altered" wherever it occured
|
|
636 after the cursor.
|
|
637
|
|
638
|
|
639 MODE LINE
|
|
640 ---------
|
|
641
|
|
642 If Emacs sees that you are typing commands slowly it shows them to you
|
|
643 at the bottom of the screen in an area called the "echo area." The echo
|
|
644 area contains the bottom line of the screen. The line immediately above
|
|
645 it is called the MODE LINE. The mode line says something like
|
|
646
|
|
647 --**--Emacs: TUTORIAL (Fundamental)----58%-------------
|
|
648
|
|
649 This is a very useful "information" line.
|
|
650
|
|
651 You already know what the filename means--it is the file you have
|
|
652 found. What the --NN%-- means is that NN percent of the file is
|
|
653 above the top of the screen. If the top of the file is on the screen,
|
|
654 it will say --TOP-- instead of --00%--. If the bottom of the file is
|
|
655 on the screen, it will say --BOT--. If you are looking at a file so
|
|
656 small it all fits on the screen, it says --ALL--.
|
|
657
|
|
658 The stars near the front mean that you have made changes to the text.
|
|
659 Right after you visit or save a file, there are no stars, just dashes.
|
|
660
|
|
661 The part of the mode line inside the parentheses is to tell you what
|
|
662 modes you are in. The default mode is Fundamental which is what you
|
|
663 are in now. It is an example of a "major mode". There are several
|
|
664 major modes in Emacs for editing different languages and text, such as
|
|
665 Lisp mode, Text mode, etc. At any time one and only one major mode is
|
|
666 active, and its name can always be found in the mode line just where
|
|
667 "Fundamental" is now. Each major mode makes a few commands behave
|
|
668 differently. For example, there are commands for creating comments in
|
|
669 a program, and since each programming language has a different idea of
|
|
670 what a comment should look like, each major mode has to insert
|
|
671 comments differently. Each major mode is the name of an extended
|
|
672 command, which is how you get into the mode. For example,
|
|
673 M-X fundamental-mode is how to get into Fundamental mode.
|
|
674
|
|
675 If you are going to be editing English text, such as this file, you
|
|
676 should probably use Text Mode.
|
|
677 >> Type M-x text-mode<Return>.
|
|
678
|
|
679 Don't worry, none of the commands you have learned changes Emacs in
|
|
680 any great way. But you can now observe that periods are no longer
|
|
681 part of words when you do M-f or M-b! Major modes are usually like
|
|
682 that: commands don't change into completely unrelated things, but they
|
|
683 work a little bit differently.
|
|
684
|
|
685 To get documentation on your current major mode, type C-h m.
|
|
686
|
|
687 >> Use C-u C-v once or more to bring this line near the top of screen.
|
|
688 >> Type C-h m, to see how Text mode differs from Fundamental mode.
|
|
689 >> Type C-x 1 to remove the documentation from the screen.
|
|
690
|
|
691 Major modes are called major because there are also minor modes.
|
|
692 They are called minor because they aren't alternatives to the major
|
|
693 modes, just minor modifications of them. Each minor mode can be
|
|
694 turned on or off by itself, regardless of what major mode you are in,
|
|
695 and regardless of the other minor modes. So you can use no minor
|
|
696 modes, or one minor mode, or any combination of several minor modes.
|
|
697
|
|
698 One minor mode which is very useful, especially for editing English
|
|
699 text, is Auto Fill mode. When this mode is on, Emacs breaks the line
|
|
700 in between words automatically whenever the line gets too long. You
|
|
701 can turn this mode on by doing M-x auto-fill-mode<Return>. When the
|
|
702 mode is on, you can turn it off by doing M-x auto-fill-mode<Return>.
|
|
703 If the mode is off, this function turns it on, and if the mode is on,
|
|
704 this function turns it off. This is called "toggling".
|
|
705
|
|
706 >> Type M-x auto-fill-mode<Return> now. Then insert a line of "asdf "
|
|
707 over again until you see it divide into two lines. You must put in
|
|
708 spaces between them because Auto Fill breaks lines only at spaces.
|
|
709
|
|
710 The margin is usually set at 70 characters, but you can change it
|
|
711 with the C-x f command. You should give the margin setting you want
|
|
712 as a numeric argument.
|
|
713
|
|
714 >> Type C-x f with an argument of 20. (C-u 2 0 C-x f).
|
|
715 Then type in some text and see Emacs fill lines of 20
|
|
716 characters with it. Then set the margin back to 70 using
|
|
717 C-x f again.
|
|
718
|
|
719 If you makes changes in the middle of a paragraph, Auto Fill mode
|
|
720 does not re-fill it for you.
|
|
721 To re-fill the paragraph, type M-q (Meta-q) with the cursor inside
|
|
722 that paragraph.
|
|
723
|
|
724 >> Move the cursor into the previous paragraph and type M-q.
|
|
725
|
|
726
|
|
727 SEARCHING
|
|
728 ---------
|
|
729
|
|
730 Emacs can do searches for strings (these are groups of contiguous
|
|
731 characters or words) either forward through the file or backward
|
|
732 through it. To search for the string means that you are trying to
|
|
733 locate it somewhere in the file and have Emacs show you where the
|
|
734 occurrences of the string exist. This type of search is somewhat
|
|
735 different from what you may be familiar with. It is a search that is
|
|
736 performed as you type in the thing to search for. The command to
|
|
737 initiate a search is C-s for forward search, and C-r for reverse
|
|
738 search. BUT WAIT! Don't do them now. When you type C-s you'll
|
|
739 notice that the string "I-search" appears as a prompt in the echo
|
|
740 area. This tells you that Emacs is in what is called an incremental
|
|
741 search waiting for you to type the thing that you want to search for.
|
|
742 <ESC> terminates a search.
|
|
743
|
|
744 >> Now type C-s to start a search. SLOWLY, one letter at a time,
|
|
745 type the word 'cursor', pausing after you type each
|
|
746 character to notice what happens to the cursor.
|
|
747 >> Type C-s to find the next occurrence of "cursor".
|
|
748 >> Now type <Rubout> four times and see how the cursor moves.
|
|
749 >> Type <ESC> to terminate the search.
|
|
750
|
|
751 Did you see what happened? Emacs, in an incremental search, tries to
|
|
752 go to the occurrence of the string that you've typed out so far. To go
|
|
753 to the next occurrence of 'cursor' just type C-s again. If no such
|
|
754 occurrence exists Emacs beeps and tells you that it is a failing
|
|
755 search. C-g would also terminate the search.
|
|
756
|
|
757 If you are in the middle of an incremental search and type <Rubout>,
|
|
758 you'll notice that the last character in the search string is erased
|
|
759 and the search backs up to the last place of the search. For
|
|
760 instance, suppose you currently have typed 'cu' and you see that your
|
|
761 cursor is at the first occurrence of 'cu'. If you now type <Rubout>,
|
|
762 the 'u' on the search line is erased and you'll be repositioned in the
|
|
763 text to the occurrence of 'c' where the search took you before you
|
|
764 typed the 'u'. This provides a useful means for backing up while you
|
|
765 are searching.
|
|
766
|
|
767 If you are in the middle of a search and happen to type a control
|
|
768 character (other than a C-s or C-r, which tell Emacs to search for the
|
|
769 next occurrence of the string), the search is terminated.
|
|
770
|
|
771 The C-s starts a search that looks for any occurrence of the search
|
|
772 string AFTER the current cursor position. But what if you want to
|
|
773 search for something earlier in the text? To do this, type C-r for
|
|
774 Reverse search. Everything that applies to C-s applies to C-r except
|
|
775 that the direction of the search is reversed.
|
|
776
|
|
777
|
|
778 RECURSIVE EDITING LEVELS
|
|
779 ------------------------
|
|
780
|
|
781 Sometimes you will get into what is called a "recursive editing
|
|
782 level". This is indicated by square brackets in the mode line,
|
|
783 surrounding the parentheses around the major mode name. For
|
|
784 example, you might see [(Fundamental)] instead of (Fundamental).
|
|
785
|
|
786 To get out of the recursive editing level, type
|
|
787 M-x top-level<Return>.
|
|
788
|
|
789 >> Try that now; it should display "Back to top level"
|
|
790 at the bottom of the screen.
|
|
791
|
|
792 In fact, you were ALREADY at top level (not inside a recursive editing
|
|
793 level) if you have obeyed instructions. M-x top-level does not care;
|
|
794 it gets out of any number of recursive editing levels, perhaps zero,
|
|
795 to get back to top level.
|
|
796
|
|
797 You can't use C-g to get out of a recursive editing level because C-g
|
|
798 is used for discarding numeric arguments and partially typed commands
|
|
799 WITHIN the recursive editing level.
|
|
800
|
|
801
|
|
802 GETTING MORE HELP
|
|
803 -----------------
|
|
804
|
|
805 In this tutorial we have tried to supply just enough information to
|
|
806 get you started using Emacs. There is so much available in Emacs that
|
|
807 it would be impossible to explain it all here. However, you may want
|
|
808 to learn more about Emacs since it has numerous desirable features
|
|
809 that you don't know about yet. Emacs has a great deal of internal
|
|
810 documentation. All of these commands can be accessed through
|
|
811 the character Control-h, which we call "the Help character"
|
|
812 because of the function it serves.
|
|
813
|
|
814 To use the HELP features, type the C-h character, and then a
|
|
815 character saying what kind of help you want. If you are REALLY lost,
|
|
816 type C-h ? and Emacs will tell you what kinds of help it can give.
|
|
817 If you have typed C-h and decide you don't want any help, just
|
|
818 type C-G to cancel it.
|
|
819
|
|
820 The most basic HELP feature is C-h c. Type C-h, a c, and a
|
|
821 command character or sequence, and Emacs displays a very brief
|
|
822 description of the command.
|
|
823
|
|
824 >> Type C-h c Control-p.
|
|
825 The message should be something like
|
|
826
|
|
827 C-p runs the command previous-line
|
|
828
|
|
829 This tells you the "name of the function". That is important in
|
|
830 writing Lisp code to extend Emacs; it also is enough to remind
|
|
831 you of what the command does if you have seen it before but did
|
|
832 not remember.
|
|
833
|
|
834 Multi-character commands such as C-x C-s and (if you have no META or
|
|
835 EDIT key) <ESC>v are also allowed after C-h c.
|
|
836
|
|
837 To get more information on the command, use C-h k instead of C-h c.
|
|
838
|
|
839 >> Type C-h k Control-p.
|
|
840
|
|
841 This displays the documentation of the function, as well as its name,
|
|
842 in an Emacs window. When you are finished reading the output, type
|
|
843 C-x 1 to get rid of the help text. You do not have to do this right
|
|
844 away. You can do some editing based on the help text before you type
|
|
845 C-x 1.
|
|
846
|
|
847 Here are some other useful C-h options:
|
|
848
|
|
849 C-h f Describe a function. You type in the name of the
|
|
850 function.
|
|
851
|
|
852 >> Try typing C-h f previous-line<Return>.
|
|
853 This prints all the information Emacs has about the
|
|
854 function which implements the C-P command.
|
|
855
|
|
856 C-h a Command Apropos. Type in a keyword and Emacs will list
|
|
857 all the commands whose names contain that keyword.
|
|
858 These commands can all be invoked with Meta-x.
|
|
859 For some commands, Command Apropos will also list a one
|
|
860 or two character sequence which has the same effect.
|
|
861
|
|
862 >> Type C-h a file<Return>. You will see a list of all M-x commands
|
|
863 with "file" in their names. You will also see commands
|
|
864 like C-x C-f and C-x C-w, listed beside the command names
|
|
865 find-file and write-file.
|
|
866
|
|
867
|
|
868 CONCLUSION
|
|
869 ----------
|
|
870
|
|
871 Remember, to exit Emacs permanently use C-x C-c. To exit to a shell
|
|
872 temporarily, so that you can come back in, use C-z. (This does not
|
|
873 work under X windows, because there is no real concept of exiting
|
|
874 temporarily to the shell. Instead, C-z iconifies the Emacs screen.)
|
|
875
|
|
876 This tutorial is meant to be understandable to all new users, so if
|
|
877 you found something unclear, don't sit and blame yourself - complain!
|
|
878
|
|
879
|
|
880 COPYING
|
|
881 -------
|
|
882
|
|
883 This tutorial descends from a long line of Emacs tutorials
|
|
884 starting with the one written by Stuart Cracraft for the original Emacs.
|
|
885 It was last modified September 1994 by Ben Wing, who updated the
|
|
886 tutorial for X.
|
|
887
|
|
888 This version of the tutorial, like GNU Emacs, is copyrighted, and
|
|
889 comes with permission to distribute copies on certain conditions:
|
|
890
|
|
891 Copyright (c) 1985, 1994 Free Software Foundation
|
|
892
|
|
893 Permission is granted to anyone to make or distribute verbatim copies
|
|
894 of this document as received, in any medium, provided that the
|
|
895 copyright notice and permission notice are preserved,
|
|
896 and that the distributor grants the recipient permission
|
|
897 for further redistribution as permitted by this notice.
|
|
898
|
|
899 Permission is granted to distribute modified versions
|
|
900 of this document, or of portions of it,
|
|
901 under the above conditions, provided also that they
|
|
902 carry prominent notices stating who last altered them.
|
|
903
|
|
904 The conditions for copying Emacs itself are slightly different
|
|
905 but in the same spirit. Please read the file COPYING and then
|
|
906 do give copies of GNU Emacs to your friends.
|
|
907 Help stamp out software obstructionism ("ownership") by using,
|
|
908 writing, and sharing free software!
|