Next: Prefix Keymaps, Up: Key Bindings
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.
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 with your terminal. A key sequence gets its meaning from its binding, which says what command it runs. The role of keymaps is to record these bindings.
The global keymap is the most important keymap because it is always in effect. The global keymap defines keys for Fundamental mode; 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, actually work
by storing the new binding in the proper place in the global map.
See Rebinding.
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. On text terminals, typing a function key actually sends the computer a sequence of characters; the precise details of the sequence depends on which function key and on the model of terminal you are using. (Often the sequence starts with <ESC> [.) If Emacs understands your terminal type properly, it recognizes the character sequences forming function keys wherever they occur in a key sequence. Thus, for most purposes, you can pretend the function keys reach Emacs directly and ignore their encoding as character sequences.
Key sequences can mix function keys and characters. For example, if your keyboard has a <Home> function key, Emacs also recognizes key sequences like C-x <Home>. You can even mix mouse events with keyboard events, but we recommend against it, because such key sequences are inconvenient to use.
As a user, you can redefine any key, but it is usually best to stick to key sequences that consist of C-c followed by a letter (upper or lower case). These keys are “reserved for users,” so they won't conflict with any properly designed Emacs extension. The function keys <F5> through <F9> are also reserved for users. If you redefine some other key, your definition may be overridden by certain extensions or major modes which redefine the same key.