2

I have done some searching around and can not quite find what I am looking for so I figured I would ask. This could be due to not using the right terms however.

I am new to emacs, having used vim for eight years or so, but I really need an editor I can morph to my will so I am switching. Now in vim there is a leader key you can define to avoid overlapping bindings with various extensions. In emacs there are supposed to be chords set aside for the user only but various modes do not adhere to this. Is there a way in emacs I can ensure my custom bindings do not overlap similar to the vim leader key? The reason I ask is I want to keep my bindings sane.

Inaimathi
  • 13,853
  • 9
  • 49
  • 93

4 Answers4

6

The manual details the conventions:

C-hig (elisp) Key Binding Conventions RET

Sequences reserved for the end-user are:

  • C-c<letter> for any (un-modified) upper or lower case letter: [A-Za-z]
  • Function keys F5, F6, F7, F8, F9 (again, without modifier keys)

I recommend using the easiest of these sequences as prefix bindings, as you can then follow them with any key at all, giving you a large number of options.

Someone else's recommendation that I liked was to unbind C-z if you don't commonly use suspend-frame, as that opens up another convenient prefix.

Of course, if you set up Super and Hyper modifier keys for your OS & keyboard, you would likely gain more convenient sequences than you could find uses for. This is a very reasonable option for many people with the additional modifier keys found on many modern keyboards.

Finally, the key-chord library is quite a popular way of creating new convenient and non-conflicting bindings by using pairs of (un-modified) keys typed together or in quick succession (or a single key tapped twice). This works very well in my experience, although you obviously have to be very careful to avoid binding sequences which might occur naturally.

phils
  • 71,335
  • 11
  • 153
  • 198
1

I personally use C-' as my 'leader key' for my personal keybinding map. You can create the prefix and bind keys to it like so:

(global-set-key (kbd "C-'") ctl-quote-map)
(define-key ctl-quote-map (kbd "C-p") 'stumpwm-move-window-up)
(define-key ctl-quote-map (kbd "C-n") 'stumpwm-move-window-down)
(define-key ctl-quote-map (kbd "C-f") 'stumpwm-move-window-right)
(define-key ctl-quote-map (kbd "C-b") 'stumpwm-move-window-left)
(define-key ctl-quote-map (kbd "r") 'stumpwm-interactive-resize-window)

Nobbody steps over something that obscure, and if you use the left control it's a balanced double pinky motion. C-; is also good, which is what I use for the stumpwm escape key.

Burton Samograd
  • 3,652
  • 19
  • 21
  • As a side note if I wanted to put C- on caps lock can I do that for just emacs or do I need to map it at the system level? – William Lewis Jr May 07 '13 at 13:28
  • If you're on linux using X windows check out 'man xmodmap' for a low level way to remap Control/Caps lock near the end of the man page. I don't think you can remap control in emacs. – Burton Samograd May 07 '13 at 15:17
  • Ok thanks I knew about xmodmap was just wondering if emacs can do it for itself. Thanks again. – William Lewis Jr May 07 '13 at 16:41
1

There are Emacs keybinding conventions, some of which honestly surprised me.

The relevant pieces are that C-c [a-zA-Z] and <F[5-9]> are reserved for end users.

Inaimathi
  • 13,853
  • 9
  • 49
  • 93
0

Good answers so far:

I'd throw in free-keys as a good way to check your binding is free before creating it - to avoid overlapping with yourself. helm-descbinds is good for finding your existing bindings to help you remember them as well incidentally.

Att Righ
  • 1,439
  • 1
  • 16
  • 29