Emacs Cheat Sheet


Starting emacs from the Unix prompt

% emacs [Enter]
to start emacs.
% emacs filename [Enter]
to start emacs and load a file
% emacs -nw filename [Enter]
to start emacs with no new window (load file)

Help

[Ctrl]H T
to see the tutorial
[Ctrl]H A topic [Enter]
to see help about topic
[Ctrl]X U
undo the last command

Cursor Positioning

[Ctrl]F or [>-]
forward (right) one character.
[Ctrl]B or [>-]
back (left) one character
[Ctrl]P or [^]
up one character
[Ctrl]N or [v]
down one character

[Esc]B
left one word
[Esc]F
right one word

[Ctrl]A
to beginning of line
[Ctrl]E
to end of line

[Esc]<
start of document
[Esc]>
end of document

[Esc]V
page up
[Ctrl]V
page down
[Ctrl]L
cursor in middle of screen
[Ctrl]U 20 [Ctrl]N
advance 20 lines

[Esc]X what-line [Enter]
display the line number where the cursor is located
[Esc]< [Ctrl]U 999 [Ctrl]N
go to line number 999

Search and Replace

[Ctrl]S patterntext [Enter]
search for patterntext; cursor moves as you type. Press [Enter] once at the correct location
[Ctrl]S [Enter] [Enter]
search for the next occurrence
[Ctrl]S [Esc]% oldstring [Enter] newstring [Enter]
Search for oldstring and replace it with newstring. The Y key confirms each replacement

Loading and Saving

[Ctrl]X [Ctrl]F filename
create new filename for editing (clears workspace)
[Ctrl]X [Ctrl]F filename
load in filename for editing
[Ctrl]X [Ctrl]W filename
write (save) as filename
[Ctrl]X [Ctrl]S
resave under the current filename (based on above or name given when starting emacs)

Quitting and Suspending

[Ctrl]Z
suspend current program (This is actually a Unix directive to any program; emacs does not understand [Ctrl]Z per se.)

[Ctrl]X [Ctrl]C
quit emacs (Can be used with impunity -- the system will prompt if the workspace has not yet been saved.)