2011-03-10

GNU Emacs Default Keybinding

Perm url with updates: http://xahlee.org/emacs/gnu_emacs_keybinding.html

A Curious Look at GNU Emacs's 1000+ Default Keybinding

Xah Lee, 2011-03-10

In Emacs, there's a command “describe-bindings” 【F1 b】. By default, there are a total of 1353 bindings. In this page, let's look at what they are. (you can get the list by calling “describe-bindings” in emacs, or see this file: gnu_emacs_keybinding.txt.)

(A bit tech detail: “describe-bindings” lists all keyboard shortcuts that's available to you in your current setup. The exact result depends on the current major mode, minor modes, and your custom keybinding.)

The Space-cadet keyboard

Many of the bindings refer to keys on lisp machine keyboard. So, here's a photo of lisp keyboard for reference.

Space-Cadet keyboard-2m

The Space-cadet keyboard, one of the early Lisp Machine keyboards. Source

(For more lisp machine keyboard photos, see: lisp keyboard photos.)

Alt Key

It has 137 bindings starting with the notation A-.

A-/                Prefix Command
A-1                Prefix Command
A-3                Prefix Command
A-<                «
A-=                ¯
A->                »
A-?                ¿
A-C                ©

I think these refer to the key labeled “Alt mode” on lisp keyboard. (if you know, please comment)

The purpose seems to be for inputting non-ASCII symbols. Today such key is called Alt Graph key. (on the Mac, the Opt key function as AltGr. On Windows, the right Alt becomes AltGr if you set your keyboard layout to one of European layouts.)

Dead & Mute Keys

There are 226 keys with the notation of dead- in it. e.g.

<S-dead-acute>  Prefix Command
<dead-acute>  Prefix Command
<S-dead-tilde> A Ã
<S-dead-asciitilde> A Ã
<dead-tilde> A  Ã
<S-dead-grave> A À
<dead-grave> A  À
<S-dead-circumflex> 1 ¹
<S-dead-circum> 1 ¹
<S-dead-asciicircum> 1 ¹
<dead-circumflex> 1 ¹
<dead-circum> 1 ¹
<dead-asciicircum> 1 ¹
<S-dead-acute> A Á
<dead-acute> A  Á
<S-dead-diaeresis> A Ä
<dead-diaeresis> A Ä

These are binding for Dead key for entering chars with Diacritic marks. A dead key is a modifier key similar in concept to Alt Graph key, except that it doesn't produce a char until another key is pressed.

Here's example of letters with diacritic and their names:

  • é = e with acute mark
  • à = a with grave mark
  • ê = e with circumflex
  • ñ = n with tilde
  • ü = u with diaeresis

Note that the S- is the notation for the “Shift” key. So, <S-dead-tilde> A would be something like 【Shift+dead~ A】.

There's also 70 keys with the notation of mute-, similar to the “dead” above. Not sure what they are.

(Thanks to Frédéric Perrin and Jason Rummey for help.)

“C-x 8” for Special Symbol Input

There are about 1k bindings left after the discounting the above.

There are 140 bindings for C-x 8. Example:

C-x 8 <   «
C-x 8 =   ¯
C-x 8 >   »
C-x 8 ?   ¿
C-x 8 C   ©
C-x 8 L   £
C-x 8 P   ¶
C-x 8 R   ®
C-x 8 S   §
C-x 8 Y   ¥
C-x 8 ^   Prefix Command

These are for entering special symbols that we can actually use within emacs today for inputting special chars — without using operating system's AltGr mechanism. (See: Emacs and Unicode Tips.)

Help, F1, “C-h”

There are 48 keys with <help> notation. Example:

<help>    help-command
C-h <help>  help-for-help
<f1> <help> help-for-help
<help> C-a  about-emacs
<help> C-c  describe-copying
<help> C-d  view-emacs-debugging
<help> C-e  view-external-packages
<help> C-f  view-emacs-FAQ
...
<help> i  info
<help> k  describe-key
<help> l  view-lossage
<help> m  describe-mode

The “Help” is a key on lisp keyboard, but also on many other keyboards, including NeXT, Sun Microsystems, and older Apple keyboard. See: Source www.pfu.fujitsu.com.

Then there are 48 keys with <f1> notation. Example:

<f1>    help-command
C-h <f1>  help-for-help
<f1> C-a  about-emacs
<f1> C-c  describe-copying
<f1> C-d  view-emacs-debugging
<f1> C-e  view-external-packages
<f1> C-f  view-emacs-FAQ
...
<f1> i    info
<f1> k    describe-key
<f1> l    view-lossage
<f1> m    describe-mode

There are also 48 keys with C-h notation.

C-h   help-command
<C-home>  beginning-of-buffer
C-h C-a   about-emacs
C-h C-c   describe-copying
C-h C-d   view-emacs-debugging
C-h C-e   view-external-packages
C-h C-f   view-emacs-FAQ
...
C-h i   info
C-h k   describe-key
C-h l   view-lossage
C-h m   describe-mode

All these are equivalent maps. (e.g. F1 = Help = 【Ctrl+h】) It's interesting to note that these do not seem to be key translations. Instead, each binding is defined in each set.

C-x Prefix

There are 204 with the C-x notation. Example:

C-x C-@   pop-global-mark
C-x C-b   list-buffers
C-x C-c   save-buffers-kill-terminal
C-x C-d   list-directory
C-x C-e   eval-last-sexp
C-x C-f   find-file
C-x TAB   indent-rigidly
...
C-x $   set-selective-display
C-x '   expand-abbrev
C-x (   kmacro-start-macro
C-x )   kmacro-end-macro
C-x *   calc-dispatch
C-x +   balance-windows
C-x -   shrink-window-if-larger-than-buffer
C-x .   set-fill-prefix
C-x 0   delete-window
C-x 1   delete-other-windows
C-x 2   split-window-vertically
...
C-x a   Prefix Command
C-x b   switch-to-buffer
C-x d   dired
C-x e   kmacro-end-and-call-macro
C-x f   set-fill-column
C-x h   mark-whole-buffer
...
C-x <C-left>  previous-buffer
C-x <C-right> next-buffer
C-x <left>  previous-buffer
C-x <right> next-buffer
C-x C-k C-a kmacro-add-counter
C-x C-k C-c kmacro-set-counter
C-x C-k C-d kmacro-delete-ring-head
C-x C-k C-e kmacro-edit-macro-repeat
C-x C-k C-f kmacro-set-format

“view-mode” Minor Mode Keys

There are 38 keys for “view-mode”. They are almost all single symbol keys. Example:

0 .. 9    digit-argument
<   beginning-of-buffer
=   what-line
>   end-of-buffer
?   describe-mode
@   View-back-to-mark
C   View-kill-and-leave
E   View-exit-and-edit
F   View-revert-buffer-scroll-page-forward
H   describe-mode
Q   View-quit-all

Ctrl+Meta Bindings (C-M)

There are 36 bindings with notation C-M-. Example:

<C-M-down>  down-list
<C-M-end> end-of-defun
<C-M-home>  beginning-of-defun
<C-M-left>  backward-sexp
<C-M-right> forward-sexp
<C-M-up>  backward-up-list
C-M-@   mark-sexp
C-M-a   beginning-of-defun
C-M-b   backward-sexp
C-M-c   exit-recursive-edit
C-M-d   down-list
C-M-j   indent-new-comment-line
C-M-k   kill-sexp

These are designed to navigate/edit lisp code. (See: How to Edit Lisp Code with Emacs.)

Note the M- is the syntax for Meta key. It is a key on Lisp keyboards. Today, by default, the Alt key on PC keyboards is interpreted as Meta.

Number Pad Keys

There are 56 bindings for the keys on the numberical keypad. They have notation kp-. Example:

<C-S-kp-1>  <C-S-end>
<C-S-kp-2>  <C-S-down>
<C-S-kp-3>  <C-S-next>
...
<M-kp-next> <M-next>
<S-kp-down> <S-down>
<S-kp-end>  <S-end>
<S-kp-home> <S-home>
<S-kp-left> <S-left>
<S-kp-next> <S-next>
...
<kp-0>    0
<kp-1>    1
<kp-2>    2
...
<kp-add>  +
<kp-decimal>  .
<kp-delete> C-d
<kp-divide> /
<kp-down> <down>
<kp-end>  <end>

All these are key translations and does not do anything special. For example, keypad 0 is the same as the 0 key on the main typing area. So, the code <kp-0> translates to 0. When Num Lock is off, the 4 key on numpad is the key. So, the code <S-kp-left> (which means holding down Shift then pressing the on the numpad) simply translates to <S-left>.

Ctrl, Meta, Esc keys

Now, there are 300+ bindings left. 98 of them are Meta keys with the notation M-. 105 of them are Ctrl keys with the notation C-. 20 of them are Esc keys with the notation ESC. Some of the Ctrl definitions is Ctrl with mouse button.

Ancient Special Keys

Now, there about 100 bindings left.

Here's the file: gnu_emacs_keybinding_rest.txt.

Some keys interesting are these:

<again>   repeat-complex-command
<begin>   beginning-of-buffer
<compose-last-chars>    compose-last-chars
<copy>    clipboard-kill-ring-save
<cut>   clipboard-kill-region
<delete-frame>  handle-delete-frame
<deletechar>  delete-char
<deleteline>  kill-line
<escape>  ESC
<linefeed>  C-j
<execute> execute-extended-command

<f16>   clipboard-kill-ring-save
<f18>   clipboard-yank
<f20>   clipboard-kill-region
<find>    search-forward
<header-line> Prefix Command
<iconify-frame>     ignore-event
<insertchar>  overwrite-mode
<insertline>  open-line
<language-change>   ignore
<left-fringe> Prefix Command
<lwindow> ignore
<make-frame-visible>    ignore-event
<menu>    execute-extended-command
<mode-line> Prefix Command
<select-window>     handle-select-window
<switch-frame>      handle-switch-frame

I think most of these are actual keys. You can still see some of these keys on Sun Microsystem's keyboard. (alas, Sun just died a year ago.) For photo of Sun keyboard, see: Sun Microsystem's “Type 6” Keyboard.

Super & Hyper?

Curiously, there's no definition for Super s- and Hyper H- keys. These are the other prominent keys on lisp keyboard other than Meta M-. (See: Emacs: How to define Hyper & Super Keys.)