setting v:searchforward from a motion operator

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

setting v:searchforward from a motion operator

John Passaro
I am creating an operator mapping that sets the selection register based on the user's motion. e.g. =*iW to search for the current cWORD and stuff like that.

I would very much like to be able to set v:searchforward as part of this, but it's not clear how I can do this. Per :h function-search-undo, any value assigned to v:searchforward inside of a function is undone when the function returns. I can work around this most of the time, but not when doing an operator function using g@.

The mapping is implemented essentially like this:
nmap <silent> =* :<C-U>set operatorfunc=SetSearchPattern<CR>g@

This function sets the search pattern @/ and does a couple of other things. If I set v:searchforward inside it, the assignment is ignored.

I have other mappings that invoke this function then set v:searchforward in a separate exec statement:

vmap <silent> z* :call SetSearchFromSelection(visualmode())<CR>:let v:searchforward = 1<CR>
vmap <silent> z# :call SetSearchFromSelection(visualmode())<CR>:let v:searchforward = 0<CR>

But I don't know how to do this in conjunction with g@, since what comes after g@ is interpreted as a motion.

Any suggestions for how I can get around this restriction?

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: setting v:searchforward from a motion operator

Andy Wokula
Am 07.03.2019 um 21:32 schrieb John Passaro:
> The mapping is implemented essentially like this:
>
> nmap <silent> =* :<C-U>set operatorfunc=SetSearchPattern<CR>g@
>
> This function sets the search pattern @/ and does a couple of other
> things. If I set v:searchforward inside it, the assignment is
> ignored.

Maybe you can set v:searchforward before invoking SetSearchPattern() (?):


nnoremap <expr><silent> =* ':<C-U>'. SetupSearchPatCmd(). '<CR>g@'

func! SetupSearchPatCmd()
     return "set operatorfunc=SetSearchPattern|let v:searchforward = 1"
endfunc

--
Andy

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.