GNU Emacs Reference Card
(for version 20)
Starting Emacs
To enter GNU Emacs 20, just type its name: emacs To read in a file to edit, see Files, below.
Motion
Multiple Windows
When two commands are shown, the second is for “other frame.”
Leaving Emacs
suspend Emacs (or iconify it under X) exit Emacs permanently
Files
read a file into Emacs
save a file back to disk
save all files
insert contents of another file into this buffer replace this file with the file you really want write buffer to a specified file
version control checkin/checkout
Getting Help
C-x ]
C-M-f
C-M-e
The help system is simple. Type C-h (or F1) and follow the di- rections. If you are a first-time user, type C-h t for a tutorial.
remove help window C-x 1 scroll help window C-M-v
apropos: show commands matching a string C-h a show the function a key runs C-h c describe a function C-h f get mode-specific information C-h m
Error Recovery
abort partially typed or executing command C-g
kill region
copy region to kill ring
kill through next occurrence of char
yank back last thing killed
replace last yank with previous kill
Marking
set mark here
exchange point and mark
set mark arg words away mark paragraph
mark page
mark sexp
mark function mark entire buffer
Query Replace
interactively replace a text string using regular expressions
C-w
M-w
M-z char
recover a file lost by a system crash undo an unwanted change
restore a buffer to its original contents redraw garbaged screen
Incremental Search
search forward
search backward
regular expression search
reverse regular expression search
select previous search string select next later search string exit incremental search
undo effect of last character abort current search
M-x recover-file C-x u or C-_
M-x revert-buffer
C-l
C-s
C-r
C-M-s
C-M-r
M-p
M-n
RET
DEL
C-g
M-@
M-h
C-x
C-M-@
C-M-h
C-x h
M-%
M-x query-replace-regexp
Use C-s or C-r again to repeat the search in either direction. If Emacs is still searching, C-g cancels only the part not done.
Valid responses in query-replace mode are replace this one, go on to next SPC
replace this one, don’t move , skip to next without replacing DEL replace all remaining matches ! back up to the previous match ^ exit query-replace RET enter recursive edit (C-M-c to exit) C-r
The following keys are defined in the minibuffer. complete as much as possible TAB
complete up to one word SPC complete and execute RET show possible completions ? fetch previous minibuffer input M-p fetch later minibuffer input or default M-n regexp search backward through history M-r regexp search forward through history M-s abort command C-g
Type C-x ESC ESC to edit and repeat the last command that used the minibuffer. Type F10 to activate the menu bar using the minibuffer.
C-z
C-x C-c
C-x C-f
C-x C-s
C-x s
C-x i
C-x C-v
C-x C-w
C-x C-q
C-v M-v C-x <
entity to move over
character
word
line
go to line beginning (or end) sentence
paragraph
page
sexp
function
go to buffer beginning (or end)
scroll to next screen
scroll to previous screen
scroll left
scroll right
scroll current line to center of screen
Killing and Deleting
entity to kill
character (delete, not kill) word
backward forward
line (to end sentence sexp
of )
DEL
M-DEL
M-0 C-k
C-x DEL
M-- C-M-k
C-d
M-d
C-k
M-k
C-M-k
⃝c 1997 Free Software Foundation, Inc. Permissions on back. v2.2 123
C-b
M-b M-f C-p C-n C-a C-e M-a M-e M-{ M-}
delete all other windows
split window, above and below delete this window
split window, side by side scroll other window
switch cursor to another window select buffer in other window display buffer in other window find file in other window
find file read-only in other window run Dired in other window
find tag in other window
grow window taller shrink window narrower grow window wider
Formatting
indent current line (mode-dependent) indent region (mode-dependent) indent sexp (mode-dependent)
indent region rigidly arg columns
insert newline after point
move rest of line vertically down
delete blank lines around point
join line with previous (with arg, next) delete all white space around point put exactly one space at point
fill paragraph
set fill column
set prefix each line starts with
set face
Case Change
uppercase word lowercase word capitalize word
uppercase region lowercase region
The Minibuffer
C-x 1
C-x 5 2 C-x 5 0
C-x 3 C-M-v
C-x 5 o b C-x 5 b
C-o C-x 5 C-o f C-x 5 f
r C-x 5 r
d C-x 5 d
. C-x 5 .
C-x ^
C-x {
C-x }
TAB
C-M-\
C-M-q
C-x TAB
C-o
C-M-o
C-x C-o
M-^
M-\
M-SPC
M-q C-x f C-x .
M-g
M-u M-l M-c
C-x C-u
C-x C-l
C-x [
C-M-b
C-M-a
M-< M->
C-x 2 C-x 0
C-x o
C-x 4
C-x 4
C-x 4
C-x 4
C-x 4
C-x 4
C-x C-u
> C-l
backward forward
C-y M-y
C-@ C-x
or C-SPC C-x
C-f
C-p
GNU Emacs Reference Card
Regular Expressions
Registers
Buffers
select another buffer list all buffers
kill a buffer
Transposing
transpose characters transpose words transpose lines transpose sexps
Spelling Check
check spelling of current word check spelling of all words in region check spelling of entire buffer
Tags
find a tag (a definition) find next occurrence of tag specify a new tags file
C-x b
C-x C-b
C-x k
C-t
M-t
C-x C-t
C-M-t
M-$
M-x ispell-region
M-x ispell-buffer
M-.
C-u M-.
M-x visit-tags-table
any single character except a newline zero or more repeats
one or more repeats
zero or one repeat
quote regular expression special character c alternative (“or”)
grouping
same text as n th group
. (dot) *
+
?
\c
\|
\( … \) \n
\b
\B
match end
$
\>
\’
match others [^ … ]
\W \Sc
save region in register
insert register contents into buffer
save value of point in register jump to point saved in register
Keyboard Macros
start defining a keyboard macro
end keyboard macro definition execute last-defined keyboard macro append to last keyboard macro
C-x r s C-x r i
C-x r SPC
C-x r j
C-x (
C-x )
C-x e
C-u C-x (
regexp search on all files in tags table
run query-replace on all the files M-x tags-query-replace
C-x RET c
M-x list-coding-systems
M-x prefer-coding-system
continue last tags search or query-replace
Shells
execute a shell command
run a shell command on the region filter region through a shell command start a shell in window *shell*
Rectangles
copy rectangle to register
kill rectangle
yank rectangle
open rectangle, shifting text right blank out rectangle
prefix each line with a string
Abbrevs
add global abbrev
add mode-local abbrev
add global expansion for this abbrev
add mode-local expansion for this abbrev explicitly expand abbrev
M-x tags-search
M-,
M-!
M-|
C-u M-|
M-x shell
C-x rr C-x rk C-x ry C-x ro C-x rc C-x rt
C-x ag C-x al C-x ai g C-x ai l C-x ae
C-h i C-h C-i
Making global key bindings in Emacs Lisp (examples):
(global-set-key “\C-cg” ’goto-line) (global-set-key “\M-#” ’query-replace-regexp)
Writing Commands
(defun command-name (args) “documentation” (interactive “template”) body )
An example:
(defun this-line-to-top-of-window (line) “Reposition line point is on to top of window.
With ARG, put point on line ARG.” (interactive “P”)
(recenter (if (null line)
0
(prefix-numeric-value line))))
The interactive spec says how to read arguments interac- tively. Type C-h f interactive for more details.
Copyright ⃝c 1997 Free Software Foundation, Inc. v2.2 for GNU Emacs version 20, June 1997 designed by Stephen Gildea
Permission is granted to make and distribute copies of this card pro- vided the copyright notice and this permission notice are preserved on all copies.
at word break
not at word break
entity
line
word
buffer
class of characters explicit set word-syntax character character with syntax c
match start
^
\<
\‘
match these [...]
\w \sc
name last keyboard macro insert Lisp definition in buffer
M-x name-last-kbd-macro
M-x insert-kbd-macro
International Character Sets
specify principal language M-x set-language-environment
C-M-x
M-x eval-region
show all input methods
enable or disable input method
set coding system for next command
show all coding systems
choose preferred coding system
Info
enter the Info documentation reader
find specified function or variable in Info
Moving within a node:
scroll forward scroll reverse beginning of node
Moving between nodes:
load from standard system directory
Simple Customization
customize variables and faces
next node n previous node p move up u select menu item by name m select nth menu item by number (1–9) n follow cross reference (return with l) f return to last node you saw l return to directory node d go to any node by name g
Other:
run Info tutorial
quit Info
search nodes for regexp
h
q M-s
expand previous word dynamically 456
M-/
For copies of the GNU Emacs manual, write to the Free Software Foun- dation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
M-x list-input-methods
C-\
SPC DEL .
(dot)
Commands Dealing with Emacs Lisp
eval sexp before point
eval current defun
eval region
read and eval minibuffer M-:
C-x C-e
M-x load-library
M-x customize