127: How do I bind keys (including function keys) to commands? 1. Find out what character sequence is generated by the keystroke sequence you wish to bind to a command. See question 131 for how to do this. Keep in mind that the character sequences generated by a keystroke sequence varies from one terminal to another. You may also get different results depending on what type of machine you are running on (see question 130). For example, these keystrokes may generate these character sequences: F1 ---> ESC [ 2 2 4 z Shift-R10 ---> ESC O t L7 ---> ESC [ 3 1 ~ Remove ---> C-@ 2. Figure out what the Emacs Lisp syntax is for this character sequence. Inside an Emacs Lisp string, RET, LFD, DEL, ESC, SPC, and TAB are specified with `\r', `\n', `\C-?', `\e', ` ', and `\t'. C-x is specified by `\C-x'. M-x is specified the same was as "ESC x". (Control characters may also be specified as themselves, but I don't recommend it.) An Emacs Lisp string begins and ends with the double quote character, `"'. Here are some examples: ESC [ D ---> "\e[D" ESC [ 2 2 7 z ---> "\e[227z" ! ESC [ 1 8 ~ ---> "\e[18~" + C-M-r ---> "\e\C-r" 3. If some prefix of the character sequence is already bound, you must unbind it by binding it to `nil'. For example: (global-set-key "\e[" nil) 4. Pick a command to bind your key sequence to. A command can be a "symbol" with a function definition, or a "lambda list", or a string (which is treated as a macro). For example: (global-set-key "\e[D" 'backward-char) (global-set-key "\e[227~" "\exgoto-line\r") ; macro See `Key Bindings' and `Rebinding' in the online manual.