Avoiding the escape timeout

86 views
Skip to first unread message

Andy Koppe

unread,
Oct 22, 2010, 2:10:01 AM10/22/10
to vim_use
Hi,

In Cygwin's mintty terminal, I've implemented a feature called
"application escape mode" that allows applications to switch the
escape key to a non-ambiguous keycode, so as to avoid the need for the
escape timeout. It's documented at
http://code.google.com/p/mintty/wiki/CtrlSeqs#Escape_keycode

A tip at http://code.google.com/p/mintty/wiki/Tips recommends putting
it to use like this:

let &t_ti.="\e[?7727h"
let &t_te.="\e[?7727l"
noremap <Esc>O[ <Esc>
noremap! <Esc>O[ <Esc>

This works fine at least in as far as getting out of insert mode is
concerned, but unfortunately it doesn't have the desired effect when
on the command line. Instead of cancelling a command, pressing Esc
appears to have the same effect as pressing Enter, so for example
trying to cancel ':q' will quit vim instead.

Unfortunately I haven't been able to find mappings that make this work
properly. Can anyone help?

Andy

Christian Brabandt

unread,
Oct 22, 2010, 4:38:38 AM10/22/10
to vim...@googlegroups.com

Do you have 'x' present in your cpoptions? If you do, that is the default
behaviour of <ESC> in command mode to execute the typed command.

regards,
Christian

Andy Koppe

unread,
Oct 22, 2010, 7:37:46 AM10/22/10
to vim_use
On Oct 22, 9:38 am, Christian Brabandt wrote:
> On Fri, October 22, 2010 8:10 am, Andy Koppe wrote:
> > In Cygwin's mintty terminal, I've implemented a feature called
> > "application escape mode" that allows applications to switch the
> > escape key to a non-ambiguous keycode, so as to avoid the need for the
> > escape timeout. It's documented at
> >http://code.google.com/p/mintty/wiki/CtrlSeqs#Escape_keycode
>
> > A tip athttp://code.google.com/p/mintty/wiki/Tipsrecommends putting
> > it to use like this:
>
> > let &t_ti.="\e[?7727h"
> > let &t_te.="\e[?7727l"
> > noremap <Esc>O[ <Esc>
> > noremap! <Esc>O[ <Esc>
>
> > This works fine at least in as far as getting out of insert mode is
> > concerned, but unfortunately it doesn't have the desired effect when
> > on the command line. Instead of cancelling a command, pressing Esc
> > appears to have the same effect as pressing Enter, so for example
> > trying to cancel ':q' will quit vim instead.
>
> > Unfortunately I haven't been able to find mappings that make this work
> > properly. Can anyone help?
>
> Do you have 'x' present in your cpoptions?

No. Both with an empty .vimrc, and with the commands above, I get the
following:

cpoptions=aABceFs

> If you do, that is the default
> behaviour of <ESC> in command mode to execute the typed command.

Ah, so it looks like a mapping to <ESC> bypasses the vim default of
cancelling the command and instead goes straight to the vi behaviour
of executing the command, irrespective of the 'x' flag in cpoptions.
Is that as intended?

I also stumbled across what looks like a solution: map the application
escape keycode to ^C instead when in command line (or insert) mode:

let &t_ti.="\e[?7727h"
let &t_te.="\e[?7727l"
noremap <Esc>O[ <Esc>
noremap! <Esc>O[ <C-c>

Does that make sense?

Thanks,
Andy

Andy Koppe

unread,
Oct 23, 2010, 3:01:50 AM10/23/10
to vim_use
On Oct 22, 12:37 pm, Andy Koppe wrote:
> On Oct 22, 9:38 am, Christian Brabandt wrote:
> > Do you have 'x' present in your cpoptions?
> >
> > If you do, that is the default
> > behaviour of <ESC> in command mode to execute the typed command.
>
> Ah, so it looks like a mapping to <ESC> bypasses the vim default of
> cancelling the command and instead goes straight to the vi behaviour
> of executing the command, irrespective of the 'x' flag in cpoptions.
> Is that as intended?
>
> I also stumbled across what looks like a solution: map the application
> escape keycode to ^C instead when in command line (or insert) mode:
>
> let &t_ti.="\e[?7727h"
> let &t_te.="\e[?7727l"
> noremap <Esc>O[ <Esc>
> noremap! <Esc>O[ <C-c>
>
> Does that make sense?

More to the point, is it possible to map that keycode in such a way
that the 'x' option is respected? Mapping to <C-c> of course does not
do that. And is it a bug that mapping to <Esc> triggers the vi
compatibility behaviour of accepting rather than cancelling a command
line, even if the 'x' option isn't set?

Andy

Christian Brabandt

unread,
Oct 24, 2010, 7:52:28 AM10/24/10
to vim_use, vim...@googlegroups.com
Hi Andy!

All I can say is, this happens on purpose. It doesn't feel right, but
may be there is a reason for it. If I read the code correctly, the
following patch "fixes" it:

--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -740,7 +740,7 @@
#endif

if (c == '\n' || c == '\r' || c == K_KENTER || (c == ESC
- && (!KeyTyped || vim_strchr(p_cpo, CPO_ESC) != NULL)))
+ && vim_strchr(p_cpo, CPO_ESC) != NULL))
{
/* In Ex mode a backslash escapes a newline. */
if (exmode_active


regards,
Christian

Ben Fritz

unread,
Oct 25, 2010, 12:05:19 AM10/25/10
to vim_use


On Oct 24, 6:52 am, Christian Brabandt <cbli...@256bit.org> wrote:
> All I can say is, this happens on purpose. It doesn't feel right, but
> may be there is a reason for it.

:help c_<Esc>

*c_<Esc>*
<Esc> When typed and 'x' not present in 'cpoptions', quit
Command-line mode without executing. In macros or when 'x'
present in 'cpoptions', start entered command.
Note: If your <Esc> key is hard to hit on your keyboard, train
yourself to use CTRL-[.

Note the "in macros" text. Apparently this also applies to mappings.
The "when typed" certainly does not apply to mappings.

Christian Brabandt

unread,
Oct 25, 2010, 3:12:47 AM10/25/10
to vim...@googlegroups.com

Yes. But I am asking, why it behaves that way. If I map ESC to a diferent
key, I want it to behave like ESC and not to do something different.

regards,
Christian

Andy Koppe

unread,
Oct 26, 2010, 1:20:15 PM10/26/10
to vim_use
I agree (even if there's a fairly straightforward workaround).

Thanks for looking into this,
Andy
Reply all
Reply to author
Forward
0 new messages