1

I want to remove magit local keybinding for "C-w" (to use global one). But can't find which hook I can use for that.

2
(add-hook 'magit-status-mode-hook
          (lambda () (define-key magit-status-mode-map "\C-w" nil)))

Use C-h m to view the doc for the current major mode and C-s hook to search for hook, then you should know which hook to use.

The following is another way without using hook:

(with-eval-after-load 'magit
  (define-key magit-status-mode-map "\C-w" nil))
4

To remove Magit's binding use:

(with-eval-after-load 'magit
  (define-key magit-status-mode-map "\C-w" nil))

This delays changing the key binding until the keymap you want to change actually exists. You should never use a major-mode hook to change a key binding, because that would re-establish the (un)binding every time a buffer is created that uses the same major-mode.

But in this particular case there is no reason to restore the default binding. Magit's binding for C-w,magit-copy-section-value, does shadow the global binding, kill-region. But that doesn't matter because kill-region only works when the region is active, and magit-copy-section-value does fall back to do the same thing as kill-region does, when the region is active. So effectively Magit does not shadow the global binding, it augments it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.