Closed andersevenrud closed 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.
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).
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 :/
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 :)
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:]
@lewis6991 Very clever, makes sense! Merging it in now, thanks for the suggestion!
Don't give me all the credit, I just looked at how https://github.com/itchyny/vim-cursorword handled it.
btw, I actually preferred it this way. Can this be left as an option?
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.
Thought I'd make a proper issue instead of filling up your Reddit thread, heh.