Emacs de base

next up previous

Emacs de base

   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').

Inserting Text

   To insert printing characters into the text you are editing, just
type them.  This inserts the character 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', then if you type
`XX', you get `FOOXXBAR', with the cursor still before the `B'.

   To "deletë 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 will split lines automatically when they become too long, if
you turn on a special mode called "Auto Fill" mode.  *Note Filling::,
for how to use Auto Fill mode.

   Customization information: DEL in most modes runs the command named
`delete-backward-char'; RET runs the command `newliné, 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 "quotë 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 rather than shove 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 commands for doing that.

     Move to the beginning of the line (`beginning-of-liné).

     Move to the end of the line (`end-of-liné).

     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-liné).  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-liné).

     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-liné).  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').

`M-x goto-char'
     Read a number N and move cursor to character number N.  Position
     1 is the beginning of the buffer.

`M-x goto-liné
     Read a number N and move cursor to line number N.  Line 1 is the
     beginning of the buffer.

`C-x C-n'
     Use the current column of point as the "semipermanent 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, then
`C-n' and `C-p' when at the end of the starting line move to the end
of the line.  Normally, `track-eol' is `nil'.

Erasing Text

     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-liné).

     Kill forward to the end of the next word (`kill-word').

     Kill back to the beginning of the previous word

   You already know about the DEL key which deletes the character
before the cursor.  Another key, `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 together.

   To erase a larger amount of text, use the `Control-k' key, which
kills a line at a time.  If `C-k' is done at the beginning or middle of
a line, it kills all the text up to the end of the line.  If `C-k' is
done 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; the more advanced Emacs commands just make things
easier.  But to keep any text permanently you must put it in a "filë.
 Files are named units of text which are stored by the operating
system for you to retrieve later 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'.  In Emacs, to begin editing
this file, type

     C-x C-f /usr/rms/foo.c RET

Here the file name is given as an "argument" to the command `C-x C-f'
(`find-filé).  That command uses the "minibuffer" to read the
argument, and you type RET to terminate the argument (*note

   Emacs obeys the command by "visiting" the file: creating a buffer,
copying the contents of the file into the buffer, and then displaying
the buffer for you to edit.  You can make changes in it, and then
"savë the file by typing `C-x C-s' (`save-buffer').  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, and the file `foo.c' is not changed.

   To create a file, just visit the file with `C-x C-f' as if it
already existed.  Emacs will make an empty buffer in which you can
insert the text you want to put in the file.  When you save your text
with `C-x C-s', the file will be created.

   Of course, there is a lot more to learn about using files.  *Note


   If you forget what a key does, you can find out with the Help
character, which is `C-h'.  Type `C-h k' followed by the key you want
to know about; for example, `C-h k C-n' tells you all about 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::.