how to use Esc to quit ex command line mode

Frank Fischer frank.fischer at
Mon Jan 9 09:33:52 CET 2012

On Mon, Jan 09, 2012 at 02:36:56PM +0800, phay tsukiming wrote:
> Hi Frank and List:
>    Evil really rocks!But i can't quit command line mode with ESC and I noticed ESC is translated into Meta. So I use ctrl-g as a workaround instead.
>    Is there an 'official' way to quit cmdline mode as VIM does?

Currently ESC does not quit ex command line. You can use backspace to
"remove" the colon which quits ex mode (if the command line is empty).

To get the behavior you desire you can try the following:

(define-key evil-ex-keymap [escape] #'abort-recursive-edit)

This allows to quit ex with the Escape-Key.

But note that this only works for X11 Emacs and not in the terminal.
The reason is that in the terminal the Escape-Key does not generate
the "escape" event but the "ESC" key-code. But the same key-code is
generated by meta-sequences like "M-x". Thus using

(define-key evil-ex-keymap (kbd "ESC") #'abort-recursive-edit)

would work in terminal mode, too, but then *no* meta sequence like
M-f, M-<right>, M-a, M-e, ... would work anymore in ex-state.

As a side information, the same problem arises with the ESC key in any
other state and Evil contains some code to handle this. But this code
is integrated in Evil's internal state and keymap mechanism and can
therefore only be used in buffers that have Evil enabled. The ex
command line is a minibuffer and (currently) Evil is never enabled in
a minibuffer (in fact, ex-state is almost independent from all other
parts of Evil). This may change in future, but it has not a big
priority on my list because a full set of insert/normal/replace/visual
states is probably not that useful in minibuffers. (Although a nice
compromise could be something like start Evil in minibuffers, too, but
coming up in Emacs state by default.)


More information about the implementations-list mailing list