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

Highlighting of a ptr var in C/C++ #27

Closed RRethy closed 5 years ago

RRethy commented 5 years ago
Foo *foo;
foo->bar();

Hovering over foo will not highlight the other instance of foo for most people. This is due to the default iskeyword option for C/C++ files. Ideally, it would highlight it.

A simple fix would be to fix this specific use case, but it could arise for other cases I haven't observed. It might be nice to be able define a regex pattern to highlight, similar to how hl-groups are currently used. For example,

let g:Illuminate_regex_modifier = '(<cword>)%(-|)'

Let's say the foo is hovered over, then it would highlight foo and foo- but not highlight the - in the second one.

Another solution would be to have a list of temporary modifications to iskeyword, for example,

let g:Illuminate_iskeyword_modifications = [ '-' ]

Then when matching is done, iskeyword would be modified, and then restored after highlighting. This second option might not work and isn't very flexible.

RRethy commented 5 years ago

Neither solution fixes all edge cases.

A possible alternate solution would be to avoid using \k in the matching regex and instead use something more custom to only match letters/numbers and no punctuation. Will need to measure performance impact however.