sent 03:05:13 21 August 2011, Sunday
by AK:
> Is there a better way to do this?
0. You said you want just
> to change $ command to go to N chars before the end of line
but what in this case `k' is doing in the second :normal command?
1. You must not use :normal here (you could replace
exe "normal \<End>"
with
normal! $
): use :normal! (with bang).
2. :h map-<expr>:
nnoremap $ "<Bar>$".((v:count>1)?(((v:count-1).'h'):(''))
> Why is <c-u> needed there?
Try typing `2:', then read a paragraph before :h function-range-example (second
paragraph in :h :call).
> If I
> remapped $, why does it keep trying to do built-in $ handling of count?
Because v:count is reset each time normal-mode command is executed. Guess why in
> exe "normal \<End>"
command is called *normal*?
> Why can't I do 'normal $' in the function despite using nnoremap?
Because you should use :normal!. I remember it to be stated somewhere in help
explicitely: `nore' *does not apply to :normal* (and also for feedkeys()).
Original message:
> Hi, I was trying to change $ command to go to N chars before the end of
> line, and found it surprisingly hard to do. Here's what I come up with:
>
> func! EndOfLine()
> exe "normal \<End>"
> let c = v:count
> let c2 = c - 1
> let cmd = "normal " . c2 . "k" . c . "h"
> if c | exe cmd | endif
> endfu
> nnoremap $ :<c-u>call EndOfLine()<cr>
>
>
> Is there a better way to do this? Why is <c-u> needed there? If I
> remapped $, why does it keep trying to do built-in $ handling of count?
> Why can't I do 'normal $' in the function despite using nnoremap?
>
> Thanks, -ak
No comments:
Post a Comment