(emacs)Function Keys

Next: Mouse Buttons Prev: Init Rebinding Up: Key Bindings

Rebinding Function Keys

   Key sequences can contain function keys as well as ordinary
characters.  Just as Lisp characters (actually integers) represent
keyboard characters, Lisp symbols represent function keys.  If the
function key has a word as its label, then that word is also the name of
the corresponding Lisp symbol.  Here are the conventional Lisp names for
other function keys:

`left', `up', `right', `down'
     Cursor arrow keys.

`begin', `end', `home', `next', `prior'
     Other cursor repositioning keys.

`select', `print', `execute', `backtab'
`insert', `undo', `redo', `clearline'
`insertline', `deleteline', `insertchar', `deletechar',
     Miscellaneous function keys.

`f1' ... `f35'
     Numbered function keys (across the top of the keyboard).

`kp-add', `kp-subtract', `kp-multiply', `kp-divide'
`kp-backtab', `kp-space', `kp-tab', `kp-enter'
`kp-separator', `kp-decimal', `kp-equal'
     Keypad keys (to the right of the regular keyboard), with names or

`kp-0', `kp-1', ... `kp-9'
     Keypad keys with digits.

`kp-f1', `kp-f2', `kp-f3', `kp-f4'
     Keypad PF keys.

   These names are conventional, but some systems (especially when using
X windows) may use different names.  To make certain what symbol is used
for a given function key on your terminal, type `C-h c' followed by
that key.

   A key sequence which contains non-characters must be a vector rather
than a string.  To write a vector, write square brackets containing the
vector elements.  Write spaces to separate the elements.  If an element
is a symbol, simply write the symbol's name--no delimiters or
punctuation are needed.  If an element is a character, write a Lisp
character constant, which is `?' followed by the character as it would
appear in a string.

   Thus, to bind function key `f1' to the command `rmail', write the

     (global-set-key [f1] 'rmail)

   To bind the right-arrow key to the command `forward-char', you can
use this expression:

     (global-set-key [right] 'forward-char)

using the Lisp syntax for a vector containing the symbol `right'.
(This binding is present in Emacs by default.)

   You can mix function keys and characters in a key sequence.  This
example binds `C-x RIGHT' to the command `forward-page'.

     (global-set-key [?\C-x right] 'forward-page)

where `?\C-x' is the Lisp character constant for the character `C-x'.
The vector element `right' is a symbol and therefore does not take a
question mark.

   You can use the modifier keys CTRL, META, HYPER, SUPER, ALT and
SHIFT with function keys.  To represent these modifiers, prepend the
strings `C-', `M-', `H-', `s-', `A-' and `S-' to the symbol name.
Thus, here is how to make `Hyper-Meta-RIGHT' move forward a word:

     (global-set-key [H-M-right] 'forward-word)

automatically generated by info2www