tags:

views:

265

answers:

3

If I want to create a custom key combination to run a command, are there any keyboard shortcuts reserved for this? I always find it difficult to decide on which shortcut to override because I'm not sure what commands I shouldn't override and which commands plugins I may install in the future will try to set.

A: 

No, you can map any command to any key you feel like, if it is your configuration.

If you are creating your mode or lib, then choose keybinding that is not already taken.

Dev er dev
+6  A: 

You can redefine anything, but the convention is to use C-c l (where l is any letter).

As a user, you can redefine any key; but it is usually best to stick to key sequences that consist of `C-c' followed by a letter (upper or lower case). These keys are "reserved for users," so they won't conflict with any properly designed Emacs extension. The function keys through are also reserved for users. If you redefine some other key, your definition may be overridden by certain extensions or major modes which redefine the same key.

Personally, I try to find a hole in the keybindings to slip my customizations - and there are usually enough for me to find something reasonable. Also, I usually make my custom keybindings local to a minor mode, or major mode keymap, and avoid using global-set-key whenever possible. This helps keep holes in the keymaps.

For example, I overrode C-r in the minibuffer-local-map to change the path in the minibuffer to the "Resolved" pathname. So while C-r is globally bound to 'isearch-reverse, I don't miss that binding from within the minibuffer (and, it's becomes available if I start searching forward in the minibuffer).

Another example is that I wrote something that kills all the other buffers whose file name matches the filename of the current buffer. C-x k is 'kill-buffer, and luckily C-x K was free for my 'kill-other-buffers-of-this-file-name, which I like because it's a slight variation on the original keybinding. That is a global setting, but I do want the functionality available globally.

Trey Jackson
In addition, C-x C-k 0 through C-x C-k 9 and C-x C-k A through C-x C-k Z are reserved for keyboard macros, so you could use those if you wanted. (http://www.gnu.org/software/emacs/manual/html_node/emacs/Keymaps.html#Keymaps)
James Sulak
+10  A: 

I would suggest using unbound. It was made for just this type of scenario.

Once you have it required in your emacs config, typing the following will list possible unbound keys for your customization:

M-x describe-unbound-keys

It asks for a complexity level (I generally just use 5) for the key combination depending on how convenient (less options) or esoteric (more options) a key binding you are interested it.

jjames
+1 Didn't know about `unbound`, nice.
Trey Jackson