Next: Text files and editors:
Up: Introduction to the Linux
Previous: Text files and editors:
The emacs editor, and its cousin xemacs, are
powerful text editors which have many extensions to help users edit
specific types of file. Unlike vi they do not have different
command and edit modes, and anything you type will appear in the
document.
In order to enter commands, you will need to use one of two special
keys. The first is the `control key', usually found on the bottom left
and right of your keyboard and marked with the letters `Ctrl'. We will
use the `CTRL' to refer to this key, so for example `CTRL-x' will mean
hold down the control key and press x. Linux sometimes uses `' to
refer to the CTRL key, and Emacs itself uses `C' to refer
to the control key (though this can get confusing since `C' is quite a
common letter!).
The second special key is called the meta-key, and on PCs this is
usually the alternate key, marked `Alt' on most keyboards and found
next to the spacebar. On some computers they use the escape key as the
meta-key instead (marked `Esc' and found on the top-left of the
keyboard). Emacs denotes this key `M', we will simply use `ALT',
though remember that this might be the escape key instead.
You can have several files open in emacs at once, and
emacs refers to these as `buffers'. A buffer is an area of
memory the computer sets aside to store something for easy access.
Probably the most important things you need to know to use emacs
are:
- Moving the cursor one space
You can also move the cursor with the arrow keys.
- Moving the cursor one word
You can move the cursor one word right or left by holding down the
control key as you press the right or left arrow key.
- Moving the cursor one paragraph
You can move the cursor one paragraph up or down by holding down the
control key as you press the up or down arrow key.
- Deleting a character
The delete key usually deletes the character under the
cursor, whereas the backspace key usually deletes the
character to the left of the cursor and moves the cursor one space to
the left.
- Deleting a word
Holding down the control key and pressing delete deletes from
the cursor to the right end of the word, whereas backspace key usually deletes the
character to the left of the cursor and moves the cursor one space to
the left.
- Deleting a line
CTRL-k kills (deletes) the text of a line without removing the line itself, CTRL-k
again will remove the line. In fact the line is not gone forever, it
is stored in a `kill buffer'.
- Pasting text
CTRL-y brings back (`yanks') whatever was last stored in the kill buffer.
- Defining a region
CTRL-SPACE tells emacs to remember the current cursor
position and use it to define the start of a region of text.
- Cutting a region
Once you have marked the start of a region of text (see above) you can
move the cursor somewhere else and then use CTRL-w to cut everything
between the current cursor position and the start of the region. The
text is placed into the kill buffer.
- Copying a region
As for cutting, but use ALT-w instead of the control key. The text
is placed into the kill buffer, but not removed from its current location.
- Searching for a string
Type CTRL-s, and you will see the text `I-search:' appear at the
bottom of the window. Type the text you want to search for - the
search is carried out as you type. CTRL-s again will take you to
the next occurence.
- Undo a change
To undo the last change use CTRL-_ where `_' is the underscore
character usually found by holding down the shift key and pressing the
`-' button. Repeating this will undo the change before that, and so on.
- Saving a file
CTRL-x CTRL-s saves the current file, i.e. you hold down the
control key and press x, then hold down the control key again and
press s (in fact you could just keep the control key pressed down the
whole time).
- Saving a file under a different name
CTRL-x CTRL-w will prompt you for a new path and filename to save
the current buffer to. Simply type what you want and press the enter key.
- Quitting emacs
CTRL-x CTRL-c quits emacs. If you haven't written the file to disk since your last
changes it will warn you and ask what you want to do. Press `y' to
save the changes, 'n' not to, or 'q' to forget about quitting
altogether. If you have chosen not to save changes emacs will
warn you once more and ask whether you really want to quit. This time
you must type either `yes' or `no'.
There are many more emacs commands, and in fact it will do
far more than just text editing. The easiest way to get into
emacs is to use xemacs which has a set of handy
menus at the top and tells you what the equivalent keystrokes
are. There are many good resources on the internet for learning emacs.
Next: Text files and editors:
Up: Introduction to the Linux
Previous: Text files and editors:
Phil Hasnip
2007-08-23