I'd like to be able to prevent Magit from closing a buffer when I press ESC. I also want to prevent my evil-escape-mode sequence (kj) from closing it as well.

Running C-h k ESC gives

<escape> runs the command magit-mode-bury-buffer, which is an
interactive compiled Lisp function in ‘magit-mode.el’.
It is bound to <escape>, <normal-state> <escape>, <menu-bar> <Magit> <Quit Magit>.

I'm not sure what the best approach is. Can I unbind magit-mode-bury-buffer from all of those commands? If so, how?

  • Your best bet would be to unbind these keys from magit's map (probably magit-mode-map from eval-after-load (or some other macro if you use something like use-package)). I don't know much about evil-escape-mode (or evil in general, so I have no idea what approach it takes, but my guess is that it attempts to look up what's bound to ESC. – DoMiNeLa10 Nov 13 at 18:46
up vote 0 down vote accepted

You can simply unbind the key after loading evil-magit. Something to the effect of

(require 'evil-magit)
(evil-define-key* evil-magit-state magit-mode-map [escape] nil)

should work.

  • Thank you. A combination of that and (setq evil-escape-excluded-major-modes (list 'magit-status-mode 'magit-refs-mode 'magit-log-mode))) to prevent evil-escape-mode worked. – Nick Stares Nov 28 at 2:52

This binding is established in evil-magit-mode-map-bindings from the evil-magit package, which I'll assume you use. I on the other hand don't use that or Vi key bindings in general, but from the little I believe to know about it, it seems weird that ESC would be bound to magit-mode-bury-buffer. You should probably open an issue in the projects issue tracker.


Update: The behavior that you don't want was intentionally added in #14. It can be reverted using:

(evil-define-key* evil-magit-state magit-mode-map [escape] nil)
  • Thanks. Looks like it was added as a feature here. – Nick Stares Nov 27 at 17:37
  • Please ask on that issue how to undo it (or learn how to do it from the evil documentation) and then post that here as an answer. – tarsius Nov 27 at 21:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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