RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.16k stars 47 forks source link

vim-illuminate has higer priority than * highlighting #13

Closed andreyorst closed 6 years ago

andreyorst commented 6 years ago

I did encountered this with my own implementation (yes, it's me), and didn't find a way to workaround this, though I didn't searched well enough. Maybe you'll came with something up.

When current word is highlighted by illuminate, pressing * will not result into highlighting work with hlsearch group until another word steals highlighting from illuminate.

RRethy commented 6 years ago

Hey again 😄 . So it originally did respect * highlighting but that was using a hacky check:

if l:matched_word !~ @/ || !&hls || !v:hlsearch

But with your comment I tried it again and now it's no longer respecting * so I think the check above didn't work before and the highlighting was being respected for some other reason (maybe a lucky bug lol).

That being said, I fixed it and now it respects highlighting. I'm using matchadd() for the highlighting (I think you were using :match if I recall correctly), and matchadd() takes an optional priority value, the lower the value the lower the priority (originally I had it as 10 since I read this the other way around where higher value is higher priority LOL). Hl-search has a priority of 0, so by passing in -1, illuminate will respect .

PR for reference

andreyorst commented 6 years ago

Thanks!

I use matchaddpos() in my other plugin, so I didn't really thought about using matchadd() here lol. Great fix