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?
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".
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.
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 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 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.