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

Illuminate word under cursor only if there is another occurrence #28

Closed nitasn closed 5 years ago

nitasn commented 5 years ago

I would find this plugin most helpful if, as the title says, illumination of the word under the cursor would mean there is a place to jump to with # \ *. If this could be done, it would make the plugin very helpful to me and would be the reason for me to use it :)

RRethy commented 5 years ago

You may find this setting useful:

let g:Illuminate_highlightUnderCursor = 0

Checkout the docs for a description of this setting.

That being said, here are a few things to keep in mind with the feature:

  1. The mechanism that is used under the hood is :h matchadd(), it doesn't return of inform the caller of the number of matches. In order to match only if others are matched would require preemptively calling :h search() with a regex that avoids matching the pattern under the cursor (the regex can be found here), then checking if a match was found. However, this is a potentially large overhead for very little return and therefore should be a setting that is opted into.

  2. #* rely on <cword> while illuminate does not (illuminate is more accurate, see #3 for a how it is more accurate). Since they do not necessarily match the same thing, having illuminate match does not imply there is a match for # or * (and vice-versa).

  3. This is minor, but the current behaviour is consistent with other editors (jetbrains at least) that have this illumination.

The solution presented in the first point above would be fairly easy to implement, a small modification to this function should suffice (you will need to call :h search() and the regex linked to above). The setting would also need to be added since this would not be on by default and thus the docs/README would need updating. That being said, as mentioned in the second point, it would still not imply that #* would have something to jump to. I noticed you forked the repo and will therefore avoid working on this to give you the chance to try it out. gl.

RRethy commented 5 years ago

I'm going to close this since I don't see any progress on your branch and this isn't a feature I would implement since I think the overhead of the additional search() call and added complexity is not worth the return.