1 @comment node-name, next, previous, up
2 @node Edit, Customization Basics, Windows and Menus, Top
3 @chapter Basic Editing Commands
6 @findex help-with-tutorial
7 This chapter will introduce you to some basic editing commands. You
8 can also learn the basic editing commands by typing @kbd{Control-h t}
9 (@code{help-with-tutorial} OR by selecting @b{Emacs Tutorial} from the
10 @b{Help} menu on the menu bar. Most of the Emacs commands will use the
11 @key{CONTROL} key or the @key{META} key. The following abbreviations
12 will be used for the @key{CONTROL} and @key{META} key in this manual:
16 This means that you should hold down the @key{CONTROL} key while typing
17 @kbd{<chr>}. For example, if the command is @kbd{C-g}, you should hold
18 the @key{CONTROL} key and type @key{g}.
20 This means that you should hold down the @kbd{META} key while typing
21 @kbd{<chr>}. If there is no @kbd{META} key on your keyboard, use the
22 @kbd{ESC} key instead. For example, if the command is @kbd{M-x}, then
23 type @kbd{ESC}, release it and type @kbd{x}.
26 The following abbreviations will be used for some other keys:
43 @comment node-name, next, previous, up
45 * Insert:: Insert text in Emacs by simply typing at
47 * Cursor Position:: Moving Around the cursor in the buffer,
48 * Erase:: Different commands for erasing text
49 * Numeric Argument:: Giving Numeric Arguments to commands
50 * Undo:: Undoing Changes made by mistake
53 @node Insert, Cursor Position, Edit, Edit
54 @section Inserting Text
58 To insert printing characters into the text you are editing, just
59 type them. Emacs will automatically insert the characters that you type
60 into the buffer at the cursor. The cursor moves forward, but if you
61 prefer to have text characters replace (overwrite) existing text
62 characters, you can enable the @b{Overstrike} option from the
63 @b{Options} menu in the menu bar.
67 To @dfn{delete} text you have just inserted, use @key{DEL}.
68 @key{DEL} deletes the character @var{before} the cursor (not the one
69 that the cursor is on top of or under; that is the character @var{after}
70 the cursor). The cursor and all characters after it move backwards.
71 Therefore, if you type a printing character and then type @key{DEL},
74 Unfortunately, computer and keyboard manufacturers differ over the
75 name of the @key{DEL} key. This is the key at the far right of the row
76 of keys containing the digits, usually immediately above the @kbd{RET}
77 key. It is usually labelled ``Backspace'' or ``Delete'' or some
78 abbreviation. Modern keyboards will often have another key labelled
79 ``Del'' in the @emph{edit keypad} (along with an ``Ins'' key and perhaps
80 some others). This is not the @kbd{DEL} key referred to here. It
81 usually deletes @emph{forward} in Emacs.
85 @findex auto-fill-mode
86 To end a line and start typing a new one, type @key{RET}. On some
87 keyboards, this key is labelled ``Enter''. This
88 inserts a newline character in the buffer. If point is in the middle of
89 a line, @key{RET} splits the line. Typing @key{DEL} when the cursor is
90 at the beginning of a line rubs out the newline before the line, thus
91 joining the line with the preceding line.
93 Emacs automatically splits lines when they become too long, if you
94 turn on a special mode called @dfn{Auto Fill} mode.
95 @xref{Filling,,,xemacs,XEmacs User's Manual}, for information on using Auto Fill
99 @comment node-name, next, previous, up
100 @node Cursor Position, Erase, Insert, Edit
101 @section Moving Around
102 @cindex cursor control
103 @cindex cursor position
105 The following commands will allow you to move the cursor around the
106 screen. The actual function names corresponding to these commands are
107 given in parenthesis. You can also invoke these commands by typing
108 @kbd{M-x <function name>}. You can do this for any command in XEmacs.
121 @findex beginning-of-line
124 @findex backward-char
126 @findex previous-line
127 @findex transpose-chars
128 @findex beginning-of-buffer
129 @findex end-of-buffer
134 Move the cursor backward one character (@code{backward-char}).
136 Move the cursor forward one character (@code{forward-char}).
138 Move the cursor up one line vertically (@code{previous-line}).
140 Move the cursor down one line vertically (@code{next-line}).
142 Move the cursor to the beginning of the line (@code{beginning-of-line}).
144 Move the cursor to the end of the line (@code{end-of-line}).
147 Move the cursor forward one word (@code{forward-word}).
149 @findex backward-word
150 Move the cursor backward one word (@code{backward-word}).
152 Move the cursor to the top of the buffer (@code{beginning-of-buffer}).
154 Move the cursor to the end of the buffer (@code{end-of-buffer}).
155 @item M-x goto-char RET <number> RET
156 To enable this command type @kbd{M-x goto-char}, and hit @key{RETURN}
157 key. In the @dfn{echo area} you will see:
164 You should then type in a number right after the colon
165 and hit the @kbd{RETURN} key again. After reading a number @var{n} this
166 command will move the cursor to character number @var{n}.
167 Position 1 is the beginning of the buffer. For example, if you type
168 @kbd{M-x goto-char RET 200 RET}, then the cursor will move to the 200th
169 character starting from the beginning of the buffer.
171 @item M-x goto-line RET <number> RET
173 To enable this command type @kbd{M-x goto-line}, and hit the
174 @key{RETURN} key. After you see @kbd{Goto line:} in the @dfn{echo area},
175 type in a number @var{n} and hit @key{RETURN} key again. This command will
176 position the cursor on the nth line starting from the beginning of the
178 @item M-x what-line RET
179 This command will display the current line number in the echo area.
184 @comment node-name, next, previous, up
185 @node Erase, Numeric Argument, Cursor Position, Edit
186 @section Erasing Text
196 @findex delete-backward-char
200 @findex backward-kill-word
201 @findex kill-sentence
206 If you press @key{DEL} i.e. the @dfn{delete} key, it will delete the
207 character before the cursor (@code{delete-backward-char}).
209 This will delete the character after the cursor (@code{delete-char}).
211 Kill to the end of the line (@code{kill-line}). If you kill the line by
212 mistake you can @dfn{yank} or @samp{paste} it back by typing
213 @kbd{C-y}. @xref{Moving Text}, for more information on yanking.
215 Kill forward to the end of the next word (@code{kill-word}).
217 Kill back to the beginning of the previous word
218 (@code{backward-kill-word}).
220 Kill to the end of current sentence (@code{kill-sentence}).
222 Kill up to next occurrence of @var{char} (@code{zap-to-char}). To use
223 this command type @kbd{M-z}. You will see the following statement in the
230 Type any char and press the @key{RET} key. For example, if you type
231 @samp{p} then the entire text starting from the position of the cursor
232 until the first occurrence of @samp{p} is killed.
236 @comment node-name, next, previous, up
237 @node Numeric Argument, Undo, Erase, Edit
238 @section Giving Numeric Arguments
239 @cindex numeric argument
240 @cindex digit argument
241 @cindex negative argument
245 Any Emacs command can be given a @dfn{numeric argument}. Some commands
246 interpret the argument as a repetition count. For example, if you want
247 to move forward ten characters, you could type @kbd{C-f} ten
248 times. However, a more efficient way to do this would be to give an
249 argument of ten to the key @kbd{C-f} (the command @code{forward-char}, move
250 forward one character). Negative arguments are also allowed. Often they tell
251 a command to move or act backwards. For example, if you want to move
252 down ten lines, type the following:
257 After you press the @kbd{C-n} key, the cursor will move ten lines
258 downward. You can also type:
263 Both @kbd{C-u} and @kbd{M-} allow you to give numeric arguments. If you
264 want to move ten lines backward, you can also give negative arguments, like:
269 OR you could also type:
274 You can obviously use @kbd{C-b} to move backward rather than giving
275 negative arguments to @kbd{C-n}. @xref{Numeric Arguments,,,xemacs,XEmacs
276 User's Manual}, for more information on numeric arguments.
278 @comment node-name, next, previous, up
279 @node Undo, , Numeric Argument, Edit
280 @section Undoing Changes
282 @cindex mistakes, correcting
284 When you are editing a buffer, you might type something by
285 mistake. Emacs allows you to undo all changes you make to a buffer (but
286 not more than 8000 characters). Each buffer in Emacs keeps a record of
287 the changes made to it individually, so the undo command applies to the
288 current buffer. There are two undo commands:
293 Undo one batch of changes (usually, one command's worth).
296 The same as above, but this command might not be obvious to type on some
297 keyboards so it might be better to use the above command.
300 @xref{Undoing Changes,,,xemacs,XEmacs User's Manual}, for more information on