2015-03-04 14:34 GMT+03:00 Alexey Muranov <[email protected]>:
> On 4 mars 2015, at 11:44, Jürgen Krämer <[email protected]> wrote:
>
>>> Say, i've typed '42' before a motion key, but then changed my mind and 
>>> decided to use a different motion or a different count.  How do i cancel 
>>> '42' if i am in Visual mode?  (In Normal mode i can press <Esc>, but in 
>>> Visual mode this would also cancel the selection.)
>>>
>>> The only solution for Visual mode i've found so far is to press '@_'.  Is 
>>> there a better way?
>>>
>>> What if i've typed a wrong count in Operator-pending mode, like 'd42'?
>>
>> after you've started typing a count you can remove the last digit of the
>> count by pressing <Delete> (NOT <Backspace>), e.g., after you have typed
>> 42 as a count, pressing <Delete> twice will completely remove the count
>> and you are back in Visual mode.
>>
>> This behaviour is documented in the last sentence at ":help count".
>
> Thanks Jürgen, i haven't thought of this.
>
> In any case, if i need to cancel a count in a `vnoremap <expr> ...` mapping, 
> for example, i do not see a better option than '@_'.
>
> For Normal and Visual modes, i plan however to remap my `<Esc>` key using 
> something like this:
>
>     function s:NVMapExpr_EscKey()
>       if v:count
>         return '@_'
>       else
>         return "\<Esc>"
>       endif
>     endfunction
>     nnoremap <expr> <Esc> <SID>NVMapExpr_EscKey()
>     vnoremap <expr> <Esc> <SID>NVMapExpr_EscKey()

I would suggest to simply do

    noremap <expr> <Esc> (v:count?'@_':"\e")
    onoremap <expr> <Esc> (v:count?repeat("\<LT>DEL>",len(v:count)):"\e")

. Function is an overkill here.

>
> Alexey.
>
> --
> --
> 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
>
> ---
> You received this message because you are subscribed to the Google Groups 
> "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
-- 
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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to