3

I'm not a fan of hitting escape 3 times so I am trying to have the same functionality with two key presses.

I have tried the following:

(define-key key-translation-map (kbd "<ESC> <ESC>") 'keyboard-escape-quit)

This doesn't work and it actually seems to break the normal <ESC> <ESC> <ESC> functionality as well.

Any Ideas on how to do this?

sp00kyb00g13
  • 149
  • 2
  • 8

2 Answers2

2

This binding is in the global keymap. Generally key bindings that work in most or all buffers are in the global keymap. If in doubt, see How can I find out in which keymap a key is bound? to check.

So you can simply call

(global-set-key (kbd "<ESC> <ESC>") 'keyboard-escape-quit)

This overrides the previous binding of ESC ESC as a prefix. Note that if some package subsequently tries to set up a binding with ESC ESC as a prefix, this will signal an error; but this is not a commonly used prefix so you should be fine.

If you use Emacs in Unix-style terminals, this will break the use of Escape function key to encode Alt+function key (or Meta+function key in Emacs tradition), because function keys are encoded as character sequences that start with ESC. This is the reason why Emacs defines ESC ESC ESC rather than ESC ESC as a default binding. If that doesn't mean anything to you, forget I mentioned it.

0

Press C-g instead. It is shorter and works everywhere.

Heikki
  • 2,961
  • 11
  • 18
  • 1
    This is not exactly the same thing https://www.gnu.org/software/emacs/manual/html_node/emacs/Quitting.html#Quitting – JeanPierre Jul 06 '17 at 11:26