Can I map double <Esc> (<Esc><Esc>)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I map double <Esc> (<Esc><Esc>)

Constantin Stefanov
Hello.

Is there way to map pressing <Esc> twice to something and not affecting
keys giving Esc sequences?

I tried
nnoremap <silent><Esc><Esc> :nohl<CR>

but if I press for example up arrow after first Esc, it gives strange
reuslts (its frist Esc is consumed, and other chars interpreted as if
there were no Esc before them).

Set timeoutlen and ttimeoutelen helps, but not completely.

Is ther a way to trigger map only if it is two <Esc>s and no keys after
them to avoid such effects?

--
Constantin Stefanov

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Yasuhiro MATSUMOTO-2
On Thursday, March 22, 2012 6:34:34 PM UTC+9, Constantin Stefanov wrote:

> Hello.
>
> Is there way to map pressing <Esc> twice to something and not affecting
> keys giving Esc sequences?
>
> I tried
> nnoremap <silent><Esc><Esc> :nohl<CR>
>
> but if I press for example up arrow after first Esc, it gives strange
> reuslts (its frist Esc is consumed, and other chars interpreted as if
> there were no Esc before them).
>
> Set timeoutlen and ttimeoutelen helps, but not completely.
>
> Is ther a way to trigger map only if it is two <Esc>s and no keys after
> them to avoid such effects?
>
> --
> Constantin Stefanov

add space between <silent> and <esc>

nnoremap <silent> <Esc><Esc> :nohl<CR>

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Constantin Stefanov
Yasuhiro MATSUMOTO wrote: > On Thursday, March 22, 2012 6:34:34 PM
UTC+9, Constantin Stefanov wrote:

>> Hello.
>>
>> Is there way to map pressing <Esc> twice to something and not affecting
>> keys giving Esc sequences?
>>
>> I tried
>> nnoremap <silent><Esc><Esc> :nohl<CR>
>>
>> but if I press for example up arrow after first Esc, it gives strange
>> reuslts (its frist Esc is consumed, and other chars interpreted as if
>> there were no Esc before them).
>>
>> Set timeoutlen and ttimeoutelen helps, but not completely.
>>
>> Is ther a way to trigger map only if it is two <Esc>s and no keys after
>> them to avoid such effects?
>>
>> --
>> Constantin Stefanov
>
> add space between <silent> and <esc>
>
> nnoremap <silent> <Esc><Esc> :nohl<CR>
Nothing changed, Esc then up arrow gives strange results.

--
Constantin Stefanov

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Tim Chase
On 03/22/12 06:42, Constantin Stefanov wrote:
> Nothing changed, Esc then up arrow gives strange results.

Is this in vim or gvim?

I suspect it's (non-g)vim and it's receiving an ANSI escape
sequence for the arrow keys.  So you'll need to tweak the
'timeoutlen' setting to be more than the time it takes you to hit
<esc><esc>, but less than the time it takes you to hit <esc><arrow>.

You might have better results in gvim (I don't know whether it
gets actual key-codes, or they're translated into ANSI escape
sequences).

-tim




--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Constantin Stefanov

Tim Chase wrote:
> On 03/22/12 06:42, Constantin Stefanov wrote:
>> Nothing changed, Esc then up arrow gives strange results.
>
> Is this in vim or gvim?
>
> I suspect it's (non-g)vim and it's receiving an ANSI escape
> sequence for the arrow keys.  So you'll need to tweak the
> 'timeoutlen' setting to be more than the time it takes you to hit
> <esc><esc>, but less than the time it takes you to hit <esc><arrow>.
Yes, it is vim, not gvim. I know about timeoutlen, but I hoped that
there is better soultion.

> You might have better results in gvim (I don't know whether it
> gets actual key-codes, or they're translated into ANSI escape
> sequences).
I do not use gvim, so can't check.

--
Constantin Stefanov

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Tim Chase
On 03/22/12 07:18, Constantin Stefanov wrote:

>
> Tim Chase wrote:
>> On 03/22/12 06:42, Constantin Stefanov wrote:
>>> Nothing changed, Esc then up arrow gives strange results.
>>
>> Is this in vim or gvim?
>>
>> I suspect it's (non-g)vim and it's receiving an ANSI escape
>> sequence for the arrow keys.  So you'll need to tweak the
>> 'timeoutlen' setting to be more than the time it takes you to hit
>> <esc><esc>, but less than the time it takes you to hit<esc><arrow>.
> Yes, it is vim, not gvim. I know about timeoutlen, but I hoped that
> there is better soultion.

the problem is that in the <esc><left> sequence, terminal Vim
sees "<esc><esc>[D", so the "<esc><esc>" mapping gets triggered
with the side-effect of issuing "[D" (a backwards jump and then a
delete-the-rest-of-the-line).  So to distinguish them, you need
to tell how much time goes between the "<esc><esc>" and the
"<esc><left>" which is done via 'timeoutlen'.  I'd just reach for
another key rather than messing with <esc><esc>.

Personally, I tend to add the functionality to control+L which
does a refresh anyways:

   :nnoremap <C-L> :noh<cr><C-L>

>> You might have better results in gvim (I don't know whether it
>> gets actual key-codes, or they're translated into ANSI escape
>> sequences).
> I do not use gvim, so can't check.

if you don't have it or use it, the issue is somewhat moot there. :-)

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Can I map double <Esc> (<Esc><Esc>)

Constantin Stefanov
Tim Chase wrote: > On 03/22/12 07:18, Constantin Stefanov wrote:

>>
>> Tim Chase wrote:
>>> On 03/22/12 06:42, Constantin Stefanov wrote:
>>>> Nothing changed, Esc then up arrow gives strange results.
>>>
>>> Is this in vim or gvim?
>>>
>>> I suspect it's (non-g)vim and it's receiving an ANSI escape
>>> sequence for the arrow keys.  So you'll need to tweak the
>>> 'timeoutlen' setting to be more than the time it takes you to hit
>>> <esc><esc>, but less than the time it takes you to hit<esc><arrow>.
>> Yes, it is vim, not gvim. I know about timeoutlen, but I hoped that
>> there is better soultion.
>
> the problem is that in the <esc><left> sequence, terminal Vim
> sees "<esc><esc>[D", so the "<esc><esc>" mapping gets triggered
> with the side-effect of issuing "[D" (a backwards jump and then a
> delete-the-rest-of-the-line).  So to distinguish them, you need
> to tell how much time goes between the "<esc><esc>" and the
> "<esc><left>" which is done via 'timeoutlen'.  I'd just reach for
> another key rather than messing with <esc><esc>.
>
> Personally, I tend to add the functionality to control+L which
> does a refresh anyways:
>
>    :nnoremap <C-L> :noh<cr><C-L>
I know why that happens, and have another key (I use Esc Tab), but Esc
Esc (and more than that, single Esc) seems better.

I tried to use some tricks with getchar, which can chow, is there
something more in input buffer, but it seems that if I return single Esc
from map, and take something alese from input, it will not be treated as
Esc sequence.

--
Constantin Stefanov

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php