Setting Global Keybindings

Emacs Elements has a nice video on how to set global keybindings. On the one hand, it seems elementary but there are plenty of wrinkles that many users are only dimly aware of. The video notes that there are many ways of specifying the key sequence for a binding. Many of them are there merely for backwards comparability and Emacs Elements recommends that you stick with the kbd function to convert easy-to-read key sequences into the appropriate internal format.

Still, if you’re like most folks, you have a mixture of methods. They all work and there’s no problem intermixing them so you can use whatever is most comfortable for you. The video describes the kbd method as a list, which is technically true, but it’s actually a function call to a function called “kbd”.

One of the things I learned from the video is that you can assign compound key bindings easily. For example, you can simply bind function-abc to <F7> a and function-xyz to <F7> b in the normal way. I always assumed that you needed to create a key map bound to <F7> to do this but, as the video shows, it’s much simpler.

The video is centered around using global-set-key for all this but as one of the commenters notes, as of Emacs 29 that has been deprecated in favor of keymap-global-set. The new functions appear to be merely a renaming for consistency so you needn’t rush to change your existing configurations.

Most Emacs users probably know most of the material in the video but it’s worth watching in case you can learn something new. I did and I’m 16 years or more into Emacs.

This entry was posted in General and tagged . Bookmark the permalink.