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