Monday, August 22, 2011

Re: Tweaking $ command

On 08/22/2011 01:58 PM, ZyX wrote:
> Reply to message «Re: Tweaking $ command»,
> sent 22:17:27 21 August 2011, Sunday
> by AK:
>
>> The 'k' was fixing downward movement of $ command. After replacing with
>> normal! $, it works without that fix.
> `$' does not move downward on its own. I don't see why it should move downward
> (unless you kill that condition: in this case it will move because 0-1==-1 and
> `-' moves, but upward).


It does move downward. 3$ moves 2 lines downward, etc.

>
>>> 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.
> Oops, I forgot to pull fixes to the message after testing:
> nnoremap<expr> $ "<Bar>$".((v:count>1)?((v:count-1).'h'):(''))


Thanks, that works and good to know. I think I still prefer function
version for readability.

>
>> 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.
> It is not related to :*map at all, it is property of `:'. By the way, you saw
> `<Bar>' above? It is for the same job here: drop count. Another possibility is
> <C-\><C-n>: in this case {count} is ignored.


Ok, I see.. but why does map or function have to do anything with that,
they already get v:count and v:linenumber1 etc (IIRC), why isn't it up
to them to choose how to use or not use them?

>
>>> 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?
> I don't said it is *applied*. I said it is *reset* when normal-mode command is
> executed. `normal' does execute the normal-mode command as clearly stated by its
> name.


Either reset or applied, I don't see the logic in having that happen
with the first normal command in a function.

>
>> 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>
> This won't work for {count}$, see above.

?? It does work for me in Vim 7.3. For both $ and {count}$ .


-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

No comments: