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.
    – user12563
    Commented Nov 13, 2018 at 18:46

2 Answers 2


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. Commented Nov 28, 2018 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. Commented Nov 27, 2018 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
    Commented Nov 27, 2018 at 21:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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