I'm not sure if this is package-specific (example here is olivetti-mode
), but when I try to "remap" with statement:
(define-key olivetti-mode-map (kbd "<f7> ]") 'olivetti-shrink)
(for some reason you have also wrap this in eval-after-load
, but omitted here)
The old keybinding for the function olivetti-shrink
(C-c ]
) stays in place, so that I now get two keybindings for the same function. I only want the new key-binding. As a general rule, do you have to map to nil
whenever you want to change the key binding:
(define-key some-mode-map (kbd "old-key") nil)
(define-key some-mode-map (kbd "new-key") function)
I'm wondering if this is really so.
Answer?:
According to this tutorial the answer is YES: you have to do it every time.
One workaround is to use use-package
which allows you to configure a bunch of options after loading, including keybindings.
eval-after-load
is that you can't make changes to a keymap that doesn't exist yet. – phils May 1 '17 at 3:32use-package
is a workaround, you would still have to unbind the old key if you don't want it to do anything. – npostavs May 1 '17 at 3:50