I often press the wrong combination of keys and open some obscure minibuffer mode. I have to press ESC three times (I think), which is pretty annoying. How do I make emacs quit the minibuffer with just one press of ESC?
5 Answers
Thanks for all your ideas. Seems like this should do the trick:
(define-key minibuffer-local-map (kbd "ESC") 'keyboard-escape-quit)
It only worked for isearch. Seems like I'd have to rebind it for every single function (smex, ibuffer, and all those other that uses the minibuffer).
I believe that ergoemacs uses the ESC
key the way you want. It also changes lots of other Emacs key bindings - but probably in ways that agree with your desire to "avoid long emacsy keypresses".
[Caveat:
I am no expert on ergoemacs, and I do not recommend using ESC
that way. ESC
has a particular role in Emacs wrt the Meta
modifier and keymaps, and treating it otherwise is asking for trouble sooner or later.
(Similarly, C-g
is fundamental to Emacs, and is even hard-coded in some cases, so it is not 100% replaceable by another key.)]
I usually use the following key combination: Ctrl-X (enter command-mode) K (Kill), then Enter.
This should kill the current mini-buffer.
-
Thanks, but I am looking to avoid long emacsy keypresses. That is one more keypress than I currently use (ESC ESC ESC); I'd just like to press ESC once to exit the minibuffer. Aug 12, 2014 at 9:20
I wanna do similar thing: press ESC to cancel the save-buffers-kill-terminal function during the "Save file" prompt.
I tried to rebind ESC in many minibuffer keymaps as mentioned in this Q&A. However, I still cannot cancel the "Save file" prompt by ESC.
After digging some elisp source codes, I found that query-replace-map is the keymap-parent of map-y-or-n-p, which is used by save-buffers-kill-terminal. So my final fix is:
(define-key query-replace-map (kbd "<escape>") 'keyboard-quit)
Note that it disables all shortcuts with meta key.
What you probably want is to use minibuffer-setup-hook
to bind ESC in every minibuffer's local map (that way, your "ESC" keybind should usually win against whatever the current function or mode is doing, even if it's using a different key map).
(add-hook 'minibuffer-setup-hook (lambda ()
(local-set-key (kbd "ESC") 'abort-minibuffers))
C-g
should default toabort-recursive-edit
which will exit the minibuffer, unless you have anotherrecursive-edit
active. You could also write your own function usingtop-level
which aborts all levels ofrecursive-edit
and exits the minibuffer. I like a custom function written by Stefan which lets me control the escape key to use it as both a modifier key and also as a key that works with just one press: stackoverflow.com/questions/20026083/…(global-set-key (kbd "<escape>") 'top-level) (define-key minibuffer-local-map "<escape>" 'top-level) (define-key minibuffer-local-ns-map "<escape>" 'top-level) (define-key minibuffer-local-completion-map "<escape>" 'top-level) (define-key minibuffer-local-must-match-map "<escape>" 'top-level) (define-key minibuffer-local-isearch-map "<escape>" 'top-level)
My recommendation, however, is to use the function written by Stefan (above).