How can I set cursorline only during a search?

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

How can I set cursorline only during a search?

Bok Woon Chua
I don't use the cursorline, but I would find it helpful to set it during a whenever I press 'n' or 'N' to make the line of the current search match pop out. However once I press anything other than n or N, I'd like to turn the cursorline off. I can do something like 'nnoremap n :setlocal cursorline<CR>n', but I'm not sure how I can conditionally turn it off provided the next key I press isn't an 'n' or 'N'. Any ideas how I could do this?

--
--
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: How can I set cursorline only during a search?

Andy Wokula
Am 13.06.2018 um 21:04 schrieb Bok Woon Chua:
> I don't use the cursorline, but I would find it helpful to set it
> during a whenever I press 'n' or 'N' to make the line of the current
> search match pop out. However once I press anything other than n or
> N, I'd like to turn the cursorline off. I can do something like
> 'nnoremap n :setlocal cursorline<CR>n', but I'm not sure how I can
> conditionally turn it off provided the next key I press isn't an 'n'
> or 'N'. Any ideas how I could do this?

cool demo for the incomplete mapping technique ...

nnoremap <script><silent> n  n:set cul<CR><SID>_search__
nnoremap <script><silent> N  N:set cul<CR><SID>_search__

nnoremap <script> <SID>_search__n  n<SID>_search__
nnoremap <script> <SID>_search__N  N<SID>_search__
nnoremap <silent> <SID>_search__   :set nocul<CR>

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: How can I set cursorline only during a search?

Bok Woon Chua
On Thursday, 14 June 2018 03:45:56 UTC+8, Andy Wokula  wrote:

> Am 13.06.2018 um 21:04 schrieb Bok Woon Chua:
> > I don't use the cursorline, but I would find it helpful to set it
> > during a whenever I press 'n' or 'N' to make the line of the current
> > search match pop out. However once I press anything other than n or
> > N, I'd like to turn the cursorline off. I can do something like
> > 'nnoremap n :setlocal cursorline<CR>n', but I'm not sure how I can
> > conditionally turn it off provided the next key I press isn't an 'n'
> > or 'N'. Any ideas how I could do this?
>
> cool demo for the incomplete mapping technique ...
>
> nnoremap <script><silent> n  n:set cul<CR><SID>_search__
> nnoremap <script><silent> N  N:set cul<CR><SID>_search__
>
> nnoremap <script> <SID>_search__n  n<SID>_search__
> nnoremap <script> <SID>_search__N  N<SID>_search__
> nnoremap <silent> <SID>_search__   :set nocul<CR>
>
> --
> Andy
Oh wow I'm not sure what you mean by incomplete, but it works. However I'm not sure what's going on. To my understanding <SID> is used for calling script functions prepended with an 's:', but where is the definition for the '_search__' function here?

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