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.

  • 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 '16 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. – user1685095 Nov 10 '16 at 9:09
  • Yup you're totally right, that wasn't a clever idea :-) – statox Nov 10 '16 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 '16 at 9:18
  • you mean like this? – Christian Brabandt Nov 10 '16 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.