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.