Next: Undo Prev: Command Switches Up: Top
Basic Editing Commands
We now give the basics of how to enter text, make corrections, and
save the text in a file. If this material is new to you, you might
learn it more easily by running the Emacs learn-by-doing tutorial. To
do this, type `Control-h t' (`help-with-tutorial').
To insert printing characters into the text you are editing, just
type them. This inserts the characters into the buffer at the cursor
(that is, at "point"; Note: Point.). The cursor moves forward. Any
characters after the cursor move forward too. If the text in the buffer
is `FOOBAR', with the cursor before the `B', and you type `XX', the
result is `FOOXXBAR', with the cursor still before the `B'.
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.
To end a line and start typing a new one, type RET. 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. Note: Filling, for
information on using Auto Fill mode.
Customization information: DEL, in most modes, runs the command
`delete-backward-char'; RET runs the command `newline', and
self-inserting printing characters run the command `self-insert', which
inserts whatever character was typed to invoke it. Some major modes
rebind DEL to other commands.
Direct insertion works for printing characters and SPC, but other
characters act as editing commands and do not insert themselves. If
you need to insert a control character or a character whose code is
above 200 octal, you must "quote" it by typing the character
`control-q' (`quoted-insert') first. There are two ways to use `C-q':
* `Control-q' followed by any non-graphic character (even `C-g')
inserts that character.
* `Control-q' followed by three octal digits inserts the character
with the specified character code.
A numeric argument to `C-q' specifies how many copies of the quoted
character should be inserted (Note: Arguments.).
If you prefer to have text characters replace (overwrite) existing
text instead of moving it to the right, you can enable Overwrite mode, a
minor mode. Note: Minor Modes.
Changing the Location of Point
To do more than insert characters, you have to know how to move point
(Note: Point.). Here are a few of the available commands.
Move to the beginning of the line (`beginning-of-line').
Move to the end of the line (`end-of-line').
Move forward one character (`forward-char').
Move backward one character (`backward-char').
Move forward one word (`forward-word').
Move backward one word (`backward-word').
Move down one line, vertically (`next-line'). This command
attempts to keep the horizontal position unchanged, so if you
start in the middle of one line, you end in the middle of the
next. When on the last line of text, `C-n' creates a new line and
moves onto it.
Move up one line, vertically (`previous-line').
Clear the screen and reprint everything (`recenter'). Text moves
on the screen to bring point to the center of the window.
Move point to left margin on the line halfway down the screen or
window (`move-to-window-line'). Text does not move on the screen.
A numeric argument says how many screen lines down from the top
of the window (zero for the top). A negative argument counts from
the bottom (-1 for the bottom).
Transpose two characters, the ones before and after the cursor
Move to the top of the buffer (`beginning-of-buffer'). With
numeric argument N, move to N/10 of the way from the top. *Note
Arguments::, for more information on numeric arguments.
Move to the end of the buffer (`end-of-buffer').
Read a number N and move the cursor to character number N.
Position 1 is the beginning of the buffer.
Read a number N and move cursor to line number N. Line 1 is the
beginning of the buffer.
Use the current column of point as the "semi-permanent goal
column" for `C-n' and `C-p' (`set-goal-column'). Henceforth, those
commands always move to this column in each line moved into, or as
close as possible given the contents of the line. This goal
column remains in effect until canceled.
`C-u C-x C-n'
Cancel the goal column. Henceforth, `C-n' and `C-p' once again
try to avoid changing the horizontal position, as usual.
If you set the variable `track-eol' to a non-`nil' value, `C-n' and
`C-p' move to the end of the line when at the end of the starting line.
By default, `track-eol' is `nil'.
Delete the character before the cursor (`delete-backward-char').
Delete the character after the cursor (`delete-char').
Kill to the end of the line (`kill-line').
Kill forward to the end of the next word (`kill-word').
Kill back to the beginning of the previous word
In contrast to the DEL key, which deletes the character before the
cursor, `Control-d' deletes the character after the cursor, causing the
rest of the text on the line to shift left. If `Control-d' is typed at
the end of a line, that line and the next line are joined.
To erase a larger amount of text, use `Control-k', which kills a
line at a time. If you use `C-k' at the beginning or in the middle of
a line, it kills all the text up to the end of the line. If you use
`C-k' at the end of a line, it joins that line and the next line.
Note: Killing, for more flexible ways of killing text.
The commands above are sufficient for creating and altering text in
an Emacs buffer. More advanced Emacs commands just make things easier.
But to keep any text permanently you must put it in a "file". Files
are named units of text which are stored by the operating system and
which you can retrieve by name. To look at or use the contents of a
file in any way, including editing the file with Emacs, you must
specify the file name.
Consider a file named `/usr/rms/foo.c'. To begin editing this file
from Emacs, type:
C-x C-f /usr/rms/foo.c RET
The file name is given as an "argument" to the command `C-x C-f'
(`find-file'). The command uses the "minibuffer" to read the argument.
You have to type RET to terminate the argument (Note: Minibuffer.).
You can also use the Open File... menu item from the File menu, then
type the name of the file to the prompt.
Emacs obeys the command by "visiting" the file: it creates a buffer,
copies the contents of the file into the buffer, and then displays the
buffer for you to edit. You can make changes in the buffer, and then
"save" the file by typing `C-x C-s' (`save-buffer') or choosing Save
Buffer from the File menu. This makes the changes permanent by copying
the altered contents of the buffer back into the file `/usr/rms/foo.c'.
Until then, the changes are only inside your Emacs buffer, and the
file `foo.c' is not changed.
To create a file, visit the file with `C-x C-f' as if it already
existed or choose Open File from the File menu and provide the name for
the new file in the minibuffer. Emacs will create an empty buffer in
which you can insert the text you want to put in the file. When you
save the buffer with `C-x C-s', or by choosing Save Buffer from the
File menu, the file is created.
To learn more about using files, Note: Files..
If you forget what a key does, you can use the Help character
(`C-h') to find out: Type `C-h k' followed by the key you want to know
about. For example, `C-h k C-n' tells you what `C-n' does. `C-h' is a
prefix key; `C-h k' is just one of its subcommands (the command
`describe-key'). The other subcommands of `C-h' provide different
kinds of help. Type `C-h' three times to get a description of all the
help facilities. Note: Help.
- Blank Lines
- Commands to make or delete blank lines.
- Continuation Lines
- Lines too wide for the screen.
- Position Info
- What page, line, row, or column is point on?
- Numeric arguments for repeating a command.
automatically generated by info2www