I'd like to have search highlights (
set hlsearch) while the cursor is on a match and to turn it off automatically (
set nohlsearch) when I move the cursor away.
foo bar foo text text bar
After searching for bar: while the cursor is on "bar" the highlight is on, when the cursor moves away to "foo" or "text" the highlight is off and goes back on when I
N/return to "bar".
I found a search "hack" in this plugin and used it with @Tumbler41's idea:
:autocmd CursorMoved * if (search('\%#\zs'.@/,'cnW',line('.'))) | set hlsearch | else | set nohlsearch | endif
Only highlights when I'm on the first char but that's fine for me.