3

What I want to do is make CursorMoved autocmd that would check if there is a search highlight is on and if it is it would start a timer that would deactivate it.

PS I know about all available workarounds like this plugin etc. They aren't good enough.

9
  • 1
    I don't know if it is possible to test for search highlighting but maybe you could use search() with the content of @/: if the result is not zero, then the last search has a match in the buffer and you can then use :nohl. See :h search(), :h @/ (and :h setreg() to handle registers properly)
    – statox
    Nov 10, 2016 at 8:40
  • 1
    Well, this kind of useless, because I can just do :nohl in timer (I hope I can, because :noh by itself doesn't work in autocmd. Doing :noh should be less expensive than search I guess. Nov 10, 2016 at 9:09
  • Yup you're totally right, that wasn't a clever idea :-)
    – statox
    Nov 10, 2016 at 9:10
  • 3
    The universal problem with hlsearch and :nohlsearch is precisely that they can't be used in functions or autocommands. This is what forces everyone to look for hacky workarounds. Also, keep in mind that timers didn't exist until very recently.
    – romainl
    Nov 10, 2016 at 9:18
  • you mean like this? Nov 10, 2016 at 14:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.