GNU Emacs
Emacs
Dashboard

49.3.1 Keymaps

As described in Keys and Commands, each Emacs command is a Lisp function whose definition provides for interactive use. Like every Lisp function, a command has a function name, which usually consists of lower-case letters and hyphens.

A key sequence ( key, for short) is a sequence of input events that have a meaning as a unit. Input events include characters, function keys, and mouse buttons—all the inputs that you can send to the computer. A key sequence gets its meaning from its binding, which says what command it runs.

The bindings between key sequences and command functions are recorded in data structures called keymaps. Emacs has many of these, each used on particular occasions.

The global keymap is the most important keymap because it is always in effect. The global keymap defines keys for Fundamental mode (see Major Modes); most of these definitions are common to most or all major modes. Each major or minor mode can have its own keymap which overrides the global definitions of some keys.

For example, a self-inserting character such as g is self-inserting because the global keymap binds it to the command self-insert-command. The standard Emacs editing characters such as C-a also get their standard meanings from the global keymap. Commands to rebind keys, such as M-x global-set-key, work by storing the new binding in the proper place in the global map (see Changing Key Bindings Interactively). To view the current key bindings, use the C-h b command.

Most modern keyboards have function keys as well as character keys. Function keys send input events just as character keys do, and keymaps can have bindings for them. Key sequences can mix function keys and characters. For example, if your keyboard has a Home function key, Emacs can recognize key sequences like C-x Home. You can even mix mouse events with keyboard events, such as S-down-mouse-1.

On text terminals, typing a function key actually sends the computer a sequence of characters; the precise details of the sequence depend on the function key and on the terminal type. (Often the sequence starts with ESC [.) If Emacs understands your terminal type properly, it automatically handles such sequences as single input events.

Key sequences that consist of C-c followed by a letter (upper or lower case; ASCII or non-ASCII) are reserved for users. Emacs itself will never bind those key sequences, and Emacs extensions should avoid binding them. In other words, users can bind key sequences like C-c a or C-c ç and rely on these never being shadowed by other Emacs bindings.