Next: , Previous: , Up: Mastering Key Bindings in Emacs   [Index]


5.5.4 Representing Keys in Code

kbd

In order to actually bind a key you must first tell Emacs what key you intend to use. Unfortunately there’s more than one way of representing keys in Emacs: as a string, or as a vector. There is a macro built in to Emacs called kbd, which translates a human-readable key into a format Emacs can understand.

Function and Navigation Keys

One important point to note is that you must surround function and navigation keys with ‘<’ and ‘>’. Those keys include F-keys, arrow keys and home row keys, like so: ‘<home>’, ‘<f8>’ and ‘<down>’. But if you want to represent the key ‘C-c p’ then write (kbd "C-c p").