1 |
Copyright (c) 1985 Free Software Foundation, Inc; See end for conditions. |
You are looking at the Emacs tutorial. See end for copying conditions. |
2 |
You are looking at the Emacs tutorial. |
Copyright (c) 1985, 1996, 1998, 2001, 2002 Free Software Foundation. |
3 |
|
|
4 |
Emacs commands generally involve the CONTROL key (sometimes labeled |
Emacs commands generally involve the CONTROL key (sometimes labeled |
5 |
CTRL or CTL) or the META key (sometimes labeled EDIT or ALT). Rather than |
CTRL or CTL) or the META key (sometimes labeled EDIT or ALT). Rather than |
14 |
Important note: to end the Emacs session, type C-x C-c. (Two characters.) |
Important note: to end the Emacs session, type C-x C-c. (Two characters.) |
15 |
The characters ">>" at the left margin indicate directions for you to |
The characters ">>" at the left margin indicate directions for you to |
16 |
try using a command. For instance: |
try using a command. For instance: |
17 |
<<Blank lines inserted here by startup of help-with-tutorial>> |
<<Blank lines inserted around following line by help-with-tutorial>> |
18 |
|
[Middle of page left blank for didactic purposes. Text continues below] |
19 |
>> Now type C-v (View next screen) to move to the next screen. |
>> Now type C-v (View next screen) to move to the next screen. |
20 |
(go ahead, do it by holding down the CONTROL key while typing v). |
(go ahead, do it by holding down the CONTROL key while typing v). |
21 |
From now on, you should do this again whenever you finish |
From now on, you should do this again whenever you finish |
50 |
Find the cursor again and notice that the same text |
Find the cursor again and notice that the same text |
51 |
is near the cursor now. |
is near the cursor now. |
52 |
|
|
53 |
|
You can also use the PageUp and PageDn keys to move by screenfuls, if |
54 |
|
your terminal has them, but you can edit more efficiently if you use |
55 |
|
C-v and M-v. |
56 |
|
|
57 |
|
|
58 |
* BASIC CURSOR CONTROL |
* BASIC CURSOR CONTROL |
59 |
---------------------- |
---------------------- |
61 |
Moving from screenful to screenful is useful, but how do you |
Moving from screenful to screenful is useful, but how do you |
62 |
move to a specific place within the text on the screen? |
move to a specific place within the text on the screen? |
63 |
|
|
64 |
There are several ways you can do this. The most basic way is to use |
There are several ways you can do this. You can use the arrow keys, |
65 |
the commands C-p, C-b, C-f, and C-n. Each of these commands moves the |
but it's more efficient to keep your hands in the standard position |
66 |
cursor one row or column in a particular direction on the screen. |
and use the commands C-p, C-b, C-f, and C-n. These characters |
67 |
Here is a table showing these four commands and the directions they |
are equivalent to the four arrow keys, like this: |
|
move: |
|
68 |
|
|
69 |
Previous line, C-p |
Previous line, C-p |
70 |
: |
: |
78 |
using C-n or C-p. Then type C-l to see the whole diagram |
using C-n or C-p. Then type C-l to see the whole diagram |
79 |
centered in the screen. |
centered in the screen. |
80 |
|
|
81 |
You'll probably find it easy to think of these by letter: P for |
You'll find it easy to remember these letters by words they stand for: |
82 |
previous, N for next, B for backward and F for forward. These are the |
P for previous, N for next, B for backward and F for forward. You |
83 |
basic cursor positioning commands, and you'll be using them ALL the |
will be using these basic cursor positioning commands all the time. |
|
time, so it would be of great benefit if you learn them now. |
|
84 |
|
|
85 |
>> Do a few C-n's to bring the cursor down to this line. |
>> Do a few C-n's to bring the cursor down to this line. |
86 |
|
|
303 |
immediately. Type <Return> (the carriage-return key) to insert a |
immediately. Type <Return> (the carriage-return key) to insert a |
304 |
Newline character. |
Newline character. |
305 |
|
|
306 |
You can delete the last character you typed by typing <Delete>. |
You can delete the last character you typed by typing <Delback>. |
307 |
<Delete> is a key on the keyboard, which may be labeled "Del". In |
<Delback> is a key on the keyboard--the same one you normally use, |
308 |
some cases, the "Backspace" key serves as <Delete>, but not always! |
outside Emacs, for deleting the last character you typed. It is |
309 |
|
normally a large key a couple of lines up from the <Return> key, and |
310 |
|
it is usually labeled "Delete", "Del" or "Backspace". |
311 |
|
|
312 |
|
If the large key there is labeled "Backspace", then that's the one you |
313 |
|
use for <Delback>. There may also be another key labeled "Delete" |
314 |
|
somewhere else, but that's not <Delback>. |
315 |
|
|
316 |
More generally, <Delete> deletes the character immediately before the |
More generally, <Delback> deletes the character immediately before the |
317 |
current cursor position. |
current cursor position. |
318 |
|
|
319 |
>> Do this now--type a few characters, then delete them |
>> Do this now--type a few characters, then delete them |
320 |
by typing <Delete> a few times. Don't worry about this file |
by typing <Delback> a few times. Don't worry about this file |
321 |
being changed; you will not alter the master tutorial. This is |
being changed; you will not alter the master tutorial. This is |
322 |
your personal copy of it. |
your personal copy of it. |
323 |
|
|
329 |
>> Insert text until you reach the right margin, and keep on inserting. |
>> Insert text until you reach the right margin, and keep on inserting. |
330 |
You'll see a continuation line appear. |
You'll see a continuation line appear. |
331 |
|
|
332 |
>> Use <Delete>s to delete the text until the line fits on one screen |
>> Use <Delback>s to delete the text until the line fits on one screen |
333 |
line again. The continuation line goes away. |
line again. The continuation line goes away. |
334 |
|
|
335 |
You can delete a Newline character just like any other character. |
You can delete a Newline character just like any other character. |
337 |
one line. If the resulting combined line is too long to fit in the |
one line. If the resulting combined line is too long to fit in the |
338 |
screen width, it will be displayed with a continuation line. |
screen width, it will be displayed with a continuation line. |
339 |
|
|
340 |
>> Move the cursor to the beginning of a line and type <Delete>. This |
>> Move the cursor to the beginning of a line and type <Delback>. This |
341 |
merges that line with the previous line. |
merges that line with the previous line. |
342 |
|
|
343 |
>> Type <Return> to reinsert the Newline you deleted. |
>> Type <Return> to reinsert the Newline you deleted. |
352 |
Emacs and correcting errors. You can delete by words or lines |
Emacs and correcting errors. You can delete by words or lines |
353 |
as well. Here is a summary of the delete operations: |
as well. Here is a summary of the delete operations: |
354 |
|
|
355 |
<Delete> delete the character just before the cursor |
<Delback> delete the character just before the cursor |
356 |
C-d delete the next character after the cursor |
C-d delete the next character after the cursor |
357 |
|
|
358 |
M-<Delete> kill the word immediately before the cursor |
M-<Delback> kill the word immediately before the cursor |
359 |
M-d kill the next word after the cursor |
M-d kill the next word after the cursor |
360 |
|
|
361 |
C-k kill from the cursor position to end of line |
C-k kill from the cursor position to end of line |
362 |
M-k kill to the end of the current sentence |
M-k kill to the end of the current sentence |
363 |
|
|
364 |
Notice that <Delete> and C-d vs M-<Delete> and M-d extend the parallel |
Notice that <Delback> and C-d vs M-<Delback> and M-d extend the parallel |
365 |
started by C-f and M-f (well, <Delete> is not really a control |
started by C-f and M-f (well, <Delback> is not really a control |
366 |
character, but let's not worry about that). C-k and M-k are like C-e |
character, but let's not worry about that). C-k and M-k are like C-e |
367 |
and M-e, sort of, in that lines are opposite sentences. |
and M-e, sort of, in that lines are opposite sentences. |
368 |
|
|
384 |
Reinsertion of killed text is called "yanking". Generally, the |
Reinsertion of killed text is called "yanking". Generally, the |
385 |
commands that can remove a lot of text kill the text (they set up so |
commands that can remove a lot of text kill the text (they set up so |
386 |
that you can yank the text), while the commands that remove just one |
that you can yank the text), while the commands that remove just one |
387 |
character, or just blank lines and spaces, do deletion (so you cannot |
character, or only remove blank lines and spaces, do deletion (so you |
388 |
yank that text). |
cannot yank that text). |
389 |
|
|
390 |
>> Move the cursor to the beginning of a line which is not empty. |
>> Move the cursor to the beginning of a line which is not empty. |
391 |
Then type C-k to kill the text on that line. |
Then type C-k to kill the text on that line. |
402 |
yanking back, or pulling back, some text that was taken away.) You |
yanking back, or pulling back, some text that was taken away.) You |
403 |
can yank the killed text either at the same place where it was killed, |
can yank the killed text either at the same place where it was killed, |
404 |
or at some other place in the buffer, or even in a different file. |
or at some other place in the buffer, or even in a different file. |
405 |
You can yank the text several times, which makes multiple copies of |
You can yank the same text several times; that makes multiple copies |
406 |
it. |
of it. |
407 |
|
|
408 |
The command for yanking is C-y. It reinserts the last killed text, |
The command for yanking is C-y. It reinserts the last killed text, |
409 |
at the current cursor position. |
at the current cursor position. |
575 |
|
|
576 |
>> Try C-x C-b now. |
>> Try C-x C-b now. |
577 |
|
|
578 |
See how each buffer has a name, and it may also have a file name |
See how each buffer has a name, and it may also have a file name for |
579 |
for the file whose contents it holds. Some buffers do not correspond |
the file whose contents it holds. ANY text you see in an Emacs window |
|
to files. For example, the buffer named "*Buffer List*" does |
|
|
not have any file. It is the buffer which contains the buffer |
|
|
list that was made by C-x C-b. ANY text you see in an Emacs window |
|
580 |
is always part of some buffer. |
is always part of some buffer. |
581 |
|
|
582 |
>> Type C-x 1 to get rid of the buffer list. |
>> Type C-x 1 to get rid of the buffer list. |
583 |
|
|
584 |
|
When you have several buffers, only one of them is "current" at any |
585 |
|
time. That buffer is the one you edit. If you want to edit another |
586 |
|
buffer, you need to "switch" to it. If you want to switch to a buffer |
587 |
|
that corresponds to a file, you can do it by visiting the file again |
588 |
|
with C-x C-f. But there is an easier way: use the C-x b command. |
589 |
|
In that command, you have to type the buffer's name. |
590 |
|
|
591 |
|
>> Type C-x b foo <Return> to go back to the buffer "foo" which holds |
592 |
|
the text of the file "foo". Then type C-x b TUTORIAL <Return> |
593 |
|
to come back to this tutorial. |
594 |
|
|
595 |
|
Most of the time, the buffer's name is the same as the file name |
596 |
|
(without the file directory part). However, this is not always true. |
597 |
|
The buffer list you make with C-x C-b always shows you the name of |
598 |
|
every buffer. |
599 |
|
|
600 |
|
ANY text you see in an Emacs window is always part of some buffer. |
601 |
|
Some buffers do not correspond to files. For example, the buffer |
602 |
|
named "*Buffer List*" does not have any file. It is the buffer which |
603 |
|
contains the buffer list that you made with C-x C-b. The buffer named |
604 |
|
"*Messages*" also does not correspond to any file; it contains the |
605 |
|
messages that have appeared on the bottom line during your Emacs |
606 |
|
session. |
607 |
|
|
608 |
|
>> Type C-x b *Messages* <Return> to look at the buffer of messages. |
609 |
|
Then type C-b TUTORIAL <Return> to come back to this tutorial. |
610 |
|
|
611 |
If you make changes to the text of one file, then find another file, |
If you make changes to the text of one file, then find another file, |
612 |
this does not save the first file. Its changes remain inside Emacs, |
this does not save the first file. Its changes remain inside Emacs, |
613 |
in that file's buffer. The creation or editing of the second file's |
in that file's buffer. The creation or editing of the second file's |
765 |
switch to that mode. For example, M-x fundamental-mode is a command to |
switch to that mode. For example, M-x fundamental-mode is a command to |
766 |
switch to Fundamental mode. |
switch to Fundamental mode. |
767 |
|
|
768 |
If you are going to be editing English text, such as this file, you |
If you are going to be editing human-language text, such as this file, you |
769 |
should probably use Text Mode. |
should probably use Text Mode. |
770 |
>> Type M-x text mode<Return>. |
>> Type M-x text mode<Return>. |
771 |
|
|
791 |
major mode. So you can use no minor modes, or one minor mode, or any |
major mode. So you can use no minor modes, or one minor mode, or any |
792 |
combination of several minor modes. |
combination of several minor modes. |
793 |
|
|
794 |
One minor mode which is very useful, especially for editing English |
One minor mode which is very useful, especially for editing |
795 |
text, is Auto Fill mode. When this mode is on, Emacs breaks the line |
human-language text, is Auto Fill mode. When this mode is on, Emacs |
796 |
in between words automatically whenever you insert text and make a |
breaks the line in between words automatically whenever you insert |
797 |
line that is too wide. |
text and make a line that is too wide. |
798 |
|
|
799 |
You can turn Auto Fill mode on by doing M-x auto fill mode<Return>. |
You can turn Auto Fill mode on by doing M-x auto fill mode<Return>. |
800 |
When the mode is on, you can turn it off again by doing M-x |
When the mode is on, you can turn it off again by doing M-x |
848 |
character to notice what happens to the cursor. |
character to notice what happens to the cursor. |
849 |
Now you have searched for "cursor", once. |
Now you have searched for "cursor", once. |
850 |
>> Type C-s again, to search for the next occurrence of "cursor". |
>> Type C-s again, to search for the next occurrence of "cursor". |
851 |
>> Now type <Delete> four times and see how the cursor moves. |
>> Now type <Delback> four times and see how the cursor moves. |
852 |
>> Type <Return> to terminate the search. |
>> Type <Return> to terminate the search. |
853 |
|
|
854 |
Did you see what happened? Emacs, in an incremental search, tries to |
Did you see what happened? Emacs, in an incremental search, tries to |
864 |
Then see the section "Spontaneous Entry to Incremental Search" in the |
Then see the section "Spontaneous Entry to Incremental Search" in the |
865 |
Emacs manual for advice on dealing with this "feature". |
Emacs manual for advice on dealing with this "feature". |
866 |
|
|
867 |
If you are in the middle of an incremental search and type <Delete>, |
If you are in the middle of an incremental search and type <Delback>, |
868 |
you'll notice that the last character in the search string is erased |
you'll notice that the last character in the search string is erased |
869 |
and the search backs up to the last place of the search. For |
and the search backs up to the last place of the search. For |
870 |
instance, suppose you have typed "c", to search for the first |
instance, suppose you have typed "c", to search for the first |
871 |
occurrence of "c". Now if you type "u", the cursor will move |
occurrence of "c". Now if you type "u", the cursor will move |
872 |
to the first occurrence of "cu". Now type <Delete>. This erases |
to the first occurrence of "cu". Now type <Delback>. This erases |
873 |
the "u" from the search string, and the cursor moves back to |
the "u" from the search string, and the cursor moves back to |
874 |
the first occurrence of "c". |
the first occurrence of "c". |
875 |
|
|
1057 |
primary documentation. |
primary documentation. |
1058 |
|
|
1059 |
|
|
1060 |
|
* MORE FEATURES |
1061 |
|
--------------- |
1062 |
|
|
1063 |
|
You can learn more about Emacs by reading its manual, either as a book |
1064 |
|
or on-line in Info (use the Help menu or type F10 h r). Two features |
1065 |
|
that you may like especially are completion, which saves typing, and |
1066 |
|
dired, which simplifies file handling. |
1067 |
|
|
1068 |
|
Completion is a way to avoid unnecessary typing. For instance, if you |
1069 |
|
want to switch to the *Messages* buffer, you can type C-x b *M<Tab> |
1070 |
|
and Emacs will fill in the rest of the buffer name as far as it can |
1071 |
|
determine from what you have already typed. Completion is described |
1072 |
|
in Info in the Emacs manual in the node called "Completion". |
1073 |
|
|
1074 |
|
Dired enables you to list files in a directory (and optionally its |
1075 |
|
subdirectories), move around that list, visit, rename, delete and |
1076 |
|
otherwise operate on the files. Dired is described in Info in the |
1077 |
|
Emacs manual in the node called "Dired". |
1078 |
|
|
1079 |
|
The manual also describes many other Emacs features. |
1080 |
|
|
1081 |
|
|
1082 |
* CONCLUSION |
* CONCLUSION |
1083 |
------------ |
------------ |
1084 |
|
|
1098 |
This version of the tutorial, like GNU Emacs, is copyrighted, and |
This version of the tutorial, like GNU Emacs, is copyrighted, and |
1099 |
comes with permission to distribute copies on certain conditions: |
comes with permission to distribute copies on certain conditions: |
1100 |
|
|
1101 |
Copyright (c) 1985, 1996 Free Software Foundation |
Copyright (c) 1985, 1996, 1998, 2001, 2002 Free Software Foundation |
1102 |
|
|
1103 |
Permission is granted to anyone to make or distribute verbatim copies |
Permission is granted to anyone to make or distribute verbatim copies |
1104 |
of this document as received, in any medium, provided that the |
of this document as received, in any medium, provided that the |