In Emacs, how do I swap two keys?
In Emacs, you can swap two keys (or key sequences) by using the
keyboard-translate function. For example, to turn C-h into DEL, you would add this line to your .emacs file:
(keyboard-translate ?\C-h ?\C-?)
To turn DEL into C-h, you would add this line to your .emacs file:
(keyboard-translate ?\C-? ?\C-h)
The first key sequence of the pair after the function identifies what is produced by the keyboard; the second, what is matched for in the keymaps.
Keyboard translations are not the same as key bindings in keymaps. Emacs contains numerous keymaps that apply in different situations, but there is only one set of keyboard translations, and it applies to every character that Emacs reads from the terminal. Keyboard translations take place at the lowest level of input processing; the keys that are looked up in keymaps contain the characters that result from keyboard translation.
Also see "Keyboard Translations" in the online manual.
This information comes from the Emacs FAQ.
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on May 13, 2009.







