1

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?

  • 1
    C-g should default to abort-recursive-edit which will exit the minibuffer, unless you have another recursive-edit active. You could also write your own function using top-level which aborts all levels of recursive-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/… – lawlist Aug 12 '14 at 7:26
  • Can this be moved to SO so that I can place a bounty on the question and get some usable elisp? – The Unfun Cat Aug 13 '14 at 3:53
  • Here is something like what you are seeking, but it is not recommended. You can always comment it out later if you decide you want the default behavior: (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). – lawlist Aug 13 '14 at 4:04
2

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.)]

1

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. – The Unfun Cat Aug 12 '14 at 9:20
1

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).

0

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.

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.