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.22k stars 51 forks source link

Illuminates even when word is not directly under cursor #3

Closed andersevenrud closed 6 years ago

andersevenrud commented 6 years ago

Hi,

Great work. It behaves very nice after the delay changes. There's only one thing that kind of feels weird, which is that it will highlight words that are not directly under the cursor. When I'm over a whitespace it will highlight the "next word".

Attaching a screenshot for demonstration.

2018-07-28-203336_3840x2160_scrot

Thought I'd make a proper issue instead of filling up your Reddit thread, heh.

RRethy commented 6 years ago

That's a known issue unfortunately. It's happening since expand('\<cword>') is what is used to get the word under the cursor, but if it has none, then it returns the first word in front of it. Currently, I dont have a fix, but I'll leave the issue open in case I find a fix in the future.

andersevenrud commented 6 years ago

I see. I'm pretty sure I'll get used to it :) I guess that also kinda answers #4 -- which I can probably override just by using a vim setting. (edit iskeyword that is).

RRethy commented 6 years ago

Looked into a bit more, the similar behaviour will happen if you are at the start of the line and press *, it will highlight the first word it finds. Don't think there is a nice fix unfortunately :/

andersevenrud commented 6 years ago

Indeed. For * usage it feels pretty natural since you're not jumping between whitespaces very often, but in this case it just initially felt weird. But now that I know the mechanics, it's all good :)

lewis6991 commented 6 years ago

Instead of using expand('<cword>'), can you use this instead?

let l:line = getline('.')
let l:col = col('.') - 1
let l:word = matchstr(l:line[:l:col], '\k*$') . matchstr(l:line[l:col:], '^\k*')[1:]
RRethy commented 6 years ago

@lewis6991 Very clever, makes sense! Merging it in now, thanks for the suggestion!

lewis6991 commented 6 years ago

Don't give me all the credit, I just looked at how https://github.com/itchyny/vim-cursorword handled it.

towc commented 6 years ago

btw, I actually preferred it this way. Can this be left as an option?