Josh Hodas's Guide to Emacs

emacs is the most commonly used editor in the HMC UNIX environment. There are other editors based on it, such as jove.

To use emacs to edit a file, simply type

: emacs filename

Emacs Commands

There are two ways of entering commands into emacs. The most commonly used commands are bound to keyboard sequences using the Esc or Ctrl key. For example, ^V moves forward one page and Esc V moves back one page.

The second method of command entry is called the command line. Typing Esc X (also known as Meta-X, M-x, or Alt-X ) will cause a M-x prompt to appear at the bottom of the screen. You then type in a command and emacs will execute it. The commands here include all of the commands bound to keys as well as many others. For example, with the default set up M-x scroll-up is the same function as ^V but M-x apropos can only be invoked at the command line.

Customizing emacs

emacs can be customized. If you don't like the command that is attached to a key you can "bind" a different command. You can have emacs expand abbreviations automatically. Also there are many features you can turn on and off. Customizing is best done with your .emacs file (emacs run command file). Put any changes you make after the lines that are already in there, or alter the defaults as suggested by the comments.

Recovering Files

emacs by default does an auto-save every so often. The amount of time is user-configurable. The auto-save filename will be the filename sandwiched between two # symbols. If the system crashes or you accidently exit without saving your changes, you can get some of them back by using the recover-file command. Edit the file again, and type M-x recover-file.

Getting Help

If you wish more information about how to use emacs try typing M-x and then as much of a command as you want followed by a ? and emacs will list all the commands that start that way. You can even simply type M-x ? to get a list of all commands. emacs has command completion so that at any time you may type a space to have emacs try to determine the rest of the command. It will type as much as it can and if the command is not yet complete continue the input process for the remainder.

You can also find out what command any keystroke or sequence of keystrokes will execute by using M-x describe-key and then hitting the key or key sequence you are curious about. The command M-x apropos will list all the commands in which the word or character string "keyword" appears. You can then use M-x describe-command to get a brief description of what the commands do.

Emacs Commands

Action

Command

invoke emacs emacs filename
save file ^X ^S
exit emacs (with or withour saving) ^X ^C
command line mode Esc X
abort command ^G
refresh screen ^L
suspend emacs ^Z
Search and Replace
incremental search forward (may not work on some terminals) ^S
search forward ^S RETURN
incremental search backward ^R
search backward ^R RETURN
find and replace Esc X replace-string
query find and replace Esc X query-replace or Esc %
Movement Commands
up one line up arrow or ^P
down one line down arrow or ^N
right one character right arrow or ^F
left one character left arrow or ^B
next word Esc F
previous word Esc B
beginning of line ^A
end of line ^E
page forward ^V
page backward Esc V
Delete Commands
previous character ^H or Delete
current character ^D
to end of line ^K
Cut and Paste
mark beginning of region ^<space> or ^@ or ^2
copy region Esc W
delete region ^W
yank (paste) ^Y
yank previous Esc Y
File and Buffer Commands
find file ^X ^F
insert file ^X I
view buffers ^X ^B
change buffers ^X B
delete buffer ^X K