[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3. Basic Editing Commands

This chapter will introduce you to some basic editing commands. You can also learn the basic editing commands by typing Control-h t (help-with-tutorial OR by selecting Emacs Tutorial from the Help menu on the menu bar. Most of the Emacs commands will use the CONTROL key or the META key. The following abbreviations will be used for the CONTROL and META key in this manual:

C-<chr>
This means that you should hold down the CONTROL key while typing <chr>. For example, if the command is C-g, you should hold the CONTROL key and type g.
M-<chr>
This means that you should hold down the META key while typing <chr>. If there is no META key on your keyboard, use the ESC key instead. For example, if the command is M-x, then type ESC, release it and type x.

The following abbreviations will be used for some other keys:

SPC
Space bar.
RET
Return key.
LFD
Linefeed key.
TAB
Tab.
ESC
Escape.
SFT
Shift.

3.1 Inserting Text  Insert text in Emacs by simply typing at the cursor position.
3.2 Moving Around  Moving Around the cursor in the buffer,
3.3 Erasing Text  Different commands for erasing text
3.4 Giving Numeric Arguments  Giving Numeric Arguments to commands
3.5 Undoing Changes  Undoing Changes made by mistake


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.1 Inserting Text

To insert printing characters into the text you are editing, just type them. Emacs will automatically insert the characters that you type into the buffer at the cursor. The cursor moves forward, but if you prefer to have text characters replace (overwrite) existing text characters, you can enable the Overstrike option from the Options menu in the menu bar.

To delete text you have just inserted, use DEL. DEL deletes the character before the cursor (not the one that the cursor is on top of or under; that is the character after the cursor). The cursor and all characters after it move backwards. Therefore, if you type a printing character and then type DEL, they cancel out.

Unfortunately, computer and keyboard manufacturers differ over the name of the DEL key. This is the key at the far right of the row of keys containing the digits, usually immediately above the RET key. It is usually labelled "Backspace" or "Delete" or some abbreviation. Modern keyboards will often have another key labelled "Del" in the edit keypad (along with an "Ins" key and perhaps some others). This is not the DEL key referred to here. It usually deletes forward in Emacs.

To end a line and start typing a new one, type RET. On some keyboards, this key is labelled "Enter". This inserts a newline character in the buffer. If point is in the middle of a line, RET splits the line. Typing DEL when the cursor is at the beginning of a line rubs out the newline before the line, thus joining the line with the preceding line.

Emacs automatically splits lines when they become too long, if you turn on a special mode called Auto Fill mode. See section `Filling' in XEmacs User's Manual, for information on using Auto Fill mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.2 Moving Around

The following commands will allow you to move the cursor around the screen. The actual function names corresponding to these commands are given in parenthesis. You can also invoke these commands by typing M-x <function name>. You can do this for any command in XEmacs.

C-b
Move the cursor backward one character (backward-char).
C-f
Move the cursor forward one character (forward-char).
C-p
Move the cursor up one line vertically (previous-line).
C-n
Move the cursor down one line vertically (next-line).
C-a
Move the cursor to the beginning of the line (beginning-of-line).
C-e
Move the cursor to the end of the line (end-of-line).
M-f
Move the cursor forward one word (forward-word).
M-b
Move the cursor backward one word (backward-word).
M-<
Move the cursor to the top of the buffer (beginning-of-buffer).
M->
Move the cursor to the end of the buffer (end-of-buffer).
M-x goto-char RET <number> RET
To enable this command type M-x goto-char, and hit RETURN key. In the echo area you will see:

 
Goto char:

You should then type in a number right after the colon and hit the RETURN key again. After reading a number n this command will move the cursor to character number n. Position 1 is the beginning of the buffer. For example, if you type M-x goto-char RET 200 RET, then the cursor will move to the 200th character starting from the beginning of the buffer.

M-x goto-line RET <number> RET
To enable this command type M-x goto-line, and hit the RETURN key. After you see Goto line: in the echo area, type in a number n and hit RETURN key again. This command will position the cursor on the nth line starting from the beginning of the buffer.
M-x what-line RET
This command will display the current line number in the echo area.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Erasing Text

DEL
If you press DEL i.e. the delete key, it will delete the character before the cursor (delete-backward-char).
C-d
This will delete the character after the cursor (delete-char).
C-k
Kill to the end of the line (kill-line). If you kill the line by mistake you can yank or `paste' it back by typing C-y. See section 9.4 Moving Text, for more information on yanking.
M-d
Kill forward to the end of the next word (kill-word).
M-DEL
Kill back to the beginning of the previous word (backward-kill-word).
M-k
Kill to the end of current sentence (kill-sentence).
M-z char
Kill up to next occurrence of char (zap-to-char). To use this command type M-z. You will see the following statement in the echo area :

 
Zap to char:

Type any char and press the RET key. For example, if you type `p' then the entire text starting from the position of the cursor until the first occurrence of `p' is killed.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Giving Numeric Arguments

Any Emacs command can be given a numeric argument. Some commands interpret the argument as a repetition count. For example, if you want to move forward ten characters, you could type C-f ten times. However, a more efficient way to do this would be to give an argument of ten to the key C-f (the command forward-char, move forward one character). Negative arguments are also allowed. Often they tell a command to move or act backwards. For example, if you want to move down ten lines, type the following:

 
C-u 10 C-n
After you press the C-n key, the cursor will move ten lines downward. You can also type:
 
M-10 C-n
Both C-u and M- allow you to give numeric arguments. If you want to move ten lines backward, you can also give negative arguments, like:
 
C-u -10 C-n
OR you could also type:
 
M--10 C-n
You can obviously use C-b to move backward rather than giving negative arguments to C-n. See section `Numeric Arguments' in XEmacs User's Manual, for more information on numeric arguments.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.5 Undoing Changes

When you are editing a buffer, you might type something by mistake. Emacs allows you to undo all changes you make to a buffer (but not more than 8000 characters). Each buffer in Emacs keeps a record of the changes made to it individually, so the undo command applies to the current buffer. There are two undo commands:

C-x u
Undo one batch of changes (usually, one command's worth). (undo).
C-_
The same as above, but this command might not be obvious to type on some keyboards so it might be better to use the above command.

See section `Undoing Changes' in XEmacs User's Manual, for more information on undoing changes.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on August, 3 2012 using texi2html