Tuesday, July 17, 2012

Re: Allow normal command then motion (using g@) and [count]command in the same mapping

El lunes, 16 de julio de 2012 15:24:08 UTC-3, Ben Fritz escribió:
> On Monday, July 16, 2012 11:02:15 AM UTC-5, FaQ wrote:
> > Hello. I've been trying to figure out this for some time now, and couldn't find a solution.
> >
> > I have this mapping:
> >
> > nmap <silent> -c :<C-U>set opfunc=Add_comment_operator<CR>g@
> >
> > Below you'll find the Add_comment_operator() code, but I think it's not really relevant. This mapping allows me to do things like -ciw to comment the word under the cursor, or -ca{ to comment the block the cursor is in.
> >
> > Now, I would like it also to be able to type 4-c and comment four lines of code (the current one and three below). I don't know how to do this. I tried checking if there is a count querying the v:count variable, but then if I find out there isn't, the :normal g@ command doesn't do what I expect (it doesn't executes &opfunc after the motion).
>
> In what way did you check the v:count variable? It should work. Also v:count1 should work, if you like that one better.
>
> In this situation, I'd probably use an <expr> mapping. The mapping should call a function that either sets the opfunc option and returns g@ (without a count, because the count still applies), OR which returns your current map string, with the desired count to g@ inserted just prior to where g@ occurs in the current string.


(I don't know why, some characters in your response were all converted to html entities...)

Checking the v:count variable does work. What doesn't work is the :normal g@ command. I isolated my case and reduced it to this to show the "problem":

nmap <silent> -c :call A()<CR>

function! A()
se opfunc=B
normal g@
endfunction

function! B(t)
echo "HI!"
endfunction

If you type -cj or something, nothing gets echoed.

Anyway, I'll try your approach, which from a first look seems it's going to cover my needs. Thanks a lot for the pointer :).

Cheers,
FaQ

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