Unix Emacs Text Editor: Part One

The Emacs editor is a full-screen editor which is not part of the standard Unix distribution. It is distributed free by the GNU Project. Some people find Emacs more convenient to use than vi, as it does not toggle between an insert and a command mode. Users can also extend the Emacs editor by using its built-in LISP facilities. Emacs uses CTRL and the ESC key (also called META in Emacs documentation) as shift keys in giving commands.

A skeleton Emacs session

% emacs fname Enter the Emacs editor and edit fname (even if it doesn't yet exist).
CTR-x CTRL-s Save the file, do not leave Emacs.
CTR-x CTRL-c Leave Emacs.

Using the Emacs online tutorial

% emacs Enter the Emacs editor.
CTRL-H t Pull a copy of the tutorial file into that editor. If you save the file after you are done, you will have your own copy, which you can easily print off.

Handling files

CTRL-x CTRL-f Find the file, bring in a copy if it exists, make a new buffer for it if it does not exist yet.
CTRL-x CTRL-s Save the file. This is not automatic when you exit; you must actually do it. Any previous version is renamed to the original name with a ~ appended, so it won't be lost. Save frequently -- there isn't a journal file to recover an edit session.
CTRL-x s Allows you to save file buffers you have changed, whether or not they are your current editing buffer.

Cancelling a command

CTRL-g Cancel the request before hitting (RETURN), and delete the command buffer window; will also interrupt a long search, etc. Useful to delete an extra ESC.
CTRL-x u Undo the last command; repeating CTRL-x u will undo the previous command.
ESC-x top-level Get out of a recursive edit mode (shown by [] around the mode name on the status line).

Leaving Emacs

CTRL-x CTRL-c Leave Emacs completely.
CTRL-x CTRL-z Leave Emacs temporarily to do something else.

Buffer (window) management

If you CTRL-x CTRL-f and find another file while editing, all files you have found are in Emacs in different buffers. Use CTRL-x CTRL-f fname to switch from one buffer to another.

Cursor movement

CTRL-x CTRL-b List all buffers in use.
CTRL-x CTRL-p Previous buffer.
CTRL-x CTRL-n Next buffer.
CTRL-g Cancel mini-buffer used for commands, and the command itself.
CTRL-x 1 Remove all but one buffer (main text).
CTRL-x 2 Split current buffer into two windows.
CTRL-x s Save one or more buffers. Emacs will ask if you want to. Save each buffer that you have changed.
CTRL-v Move forward one screen.
ESC-v Move backward one screen.
CTRL-l Refresh the screen. (This is the letter l, not the number 1)
CTRL-b Move backward or left.
CTRL-f Move forward or left.
CTRL-n Move to next line.
CTRL-p Move to previous line.
ESC-b Move backward one word.
ESC-f Move forward one word.
CTRL-a Move to beginning of line.
CTRL-e Move to end of line.
ESC-a Move to beginning of sentence.
ESC-e Move to end of sentence.
ESC-< Move to beginning of file.
ESC-> Move to end if file.
CTRL-u 12 CTRL-b Give a repeat count for the following command; in this case, move backward 14 chracters.


Previous Page
Index
Next Page