On 08/20/2011 07:57 PM, ZyX wrote:
Reply to message «Tweaking $ command»,
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?


The 'k' was fixing downward movement of $ command. After replacing with normal! $, it works without that fix.

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'):(''))


That doesn't work for me, using vim 7.3 (even after adding the ')'). However, I prefer the function version because it's more readable.


Why is<c-u>  needed there?
Try typing `2:', then read a paragraph before :h function-range-example (second
paragraph in :h :call).


I see, but <c-u> seems like a pretty bad kludge. I remember using it at
least a couple of times before, and I still did not remember it because
it's pretty counter-intuitive. I think it would be better if there was
an arg to *map to turn it off, like <no-prepend-range>, because users
would look into *map arguments help for explanation of this behaviour.


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


That doesn't seem reasonable, why should Vim assume the count applies to
the first (of possibly dozens) normal command in a function?

Is this sort of questions ok to bring up on vim-use list?

Anyway, thanks a ton for your help and here's what I ended up with if
anyone wants to use this too:

func! EndOfLine()
    " Go to Nth char before end of line
    normal! $
    if v:count | exe "normal ".v:count."h" | endif
endfu
nnoremap $ :<c-u>call EndOfLine()<cr>


 -ak

--
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 via email to