These are only some very basic facts about emacs. To learn more, the
on-line tutorial within emacs itself is very good. To get to it type
To execute Control commands, written as
CTRL-letter, hold down the Control key
while typing the letter indicated.
To execute Escape commands, written as
letter, press the Escape key (once) and then type
the letter indicated.
To start emacs, type
and hit the
To exit emacs, type
You will be asked whether you want to save the file.
You can also save your work without exiting, by typing
It is a good idea to do this regularly while editing your files,
although emacs is pretty good at making backup copies (the names of
those files end in ~) and saving your files if the system crashes (the
names of those files begin with #).
Emacs displays a certain number of characters per line until it
gets to the right margin of the display. Longer lines will wrap
to the next physical line; this is indicated by a \ at the end of each
wrapped line. To avoid wrapping lines, either hit the Return key
before you reach the right margin of the display, type
q to re-format a paragraph after finishing it (careful - if
you don't have blank lines around the paragraph you might end up
messing up your whole document - in that case do
CTRL-x u (for 'undo')), or choose the
auto-fill option (either as a default, in your
.emacs file, or by typing
ESC x auto-fill-mode
(a toggle, i.e. doing the same thing again will turn it off.
You can invoke the general
emacs help files by typing
CTRL-h and following the instructions at the bottom of the screen.
CTRL-h a FUNCTION
- lists commands related to
CTRL-h F FUNCTION
- get help about the specified function
- get rid of Help window
- scroll Help window forward
- fancy emacs information browser
- cancel partially typed or accidental command
- redraw garbaged screen
- undo the last change
ESC x recover-file
- recover lost file
ESC x revert-buffer
- restore buffer to original contents
- scroll to next screen
- scroll to previous screen
- go backwards one character without deleting (usually you can also
use the cursor key for this)
- go forward one character without deleting (usually you can also
use the cursor key for this)
- go backwards one word
- go forward one word
- go up one line (usually you can also use the cursor key for this)
- go down one line (usually you can also use the cursor key for this)
- go to beginning of the line
- go to end of the line
- go to end of the sentence
- go to end of the sentence
- go to the beginning of the file
- go to the end of the file
ESC x goto-line
- go to the line specified
The buffer is the basic editing unit. One buffer corresponds to one piece of
text being edited. You can have several buffers open at once, but can
edit only one at a time. Several buffers can be visible at the same
time when you're splitting your window.
- select another buffer
- list all buffers
- get rid of buffer list
- kill a buffer
- dismiss this window
- dismiss all other windows
- split window in two horizontally
- switch cursor to other window
- save the file
- save a file with a new name
- read a different file into emacs, replacing the current buffer
- read a different file into emacs and put it into another buffer
- insert contents of another file into this buffer
Cutting and Pasting Text
In emacs, to "kill" means to delete something in a
way that lets you recover it if you change your mind. DEL refers to
the key on your keyboard that deletes backward one character--this may
be the Backspace, Delete, or Rubout key depending on your particular
To move or copy a region of text in emacs, you must first "mark" it,
then kill or copy the marked text, move the cursor to the desired
location, and restore the killed or copied text. A region of text is
defined by marking one end of it, then moving the cursor to the other
- delete previous character
- delete next character
- kill previous word
- kill next word
ESC 0 CTRL-k
- kill line to beginning
- kill line to end
- kill sentence to beginning
- kill sentence to end
- set mark here
- exchange cursor and mark
(used to verify you have marked the
- mark current paragraph
- mark entire buffer
- kill the marked region
- copy the marked region
All killed text (except single characters deleted with DEL or CTRL-d) can be
restored to the buffer. The most recently killed text is the first to be
restored, then previously killed text blocks are restored in reverse order.
- re-insert ('yank') the last text that was killed
- replace that restored text with previously killed text.
Repeated use will cycle through killed text blocks in reverse order.
Searching and Replacing
In both forward and backward incremental searching, you can repeat the
same command for next occurrences. The right cursor key exits the
current search without moving the cursor.
aborts the current search and moves the cursor back to the initial
- incremental search forward.
Note: On some terminals and serial connections,
CTRL-s causes the display to freeze. If this
CTRL-q to fix the problem, and use
ESC x search-forward (
Esc for further occurrences).
- incremental search backward
- (query-replace) - ask before replacing each OLD STRING with NEW
y to replace this one and go to the
next one, and type
n to skip to next without replacing.
ESC x replace-string
- replace all occurrences of OLD STRING with NEW STRING.
If you need to replace a
Return character (^J),
type CTRL-j instead (because typing
interpreted directly in the minibuffer).
- lists all the lines matching your pattern in a separate buffer,
along with their numbers. Use
ESC-x goto-line to
go to the occurrence you're interested in.
Not everyone will agree these are 'basic', but they're extremely
useful if you tend to do repetitive things and want to avoid getting
Carpal Tunnel Syndrome...
lets you start define a keyboard macro - basically records what you
do, so do exactly what you want your macro to do (with some slight
differences - e.g.\ in the new version of emacs on turing i-searches
have to be terminated by
Return in a macro, but
end the definition of the keyboard macro
executes the keyboard macro. You can also tell it how many times to
execute the macro, for example if you want it executed 15 times, type
CTRL-u 15 CTRL-x e. If you want your macro to be
executed indefinitely, i.e until it runs out of things to
CTRL-u 0 CTRL-x e.
Here is a Reference Card from DCG, another Reference Card, and a comprehensive
Back up to the Main Computing Page