qstrahl / vim-matchmaker

Highlight matches for the word under the cursor
38 stars 10 forks source link

Don't Highlight Anything When Cursor is Not on Word #18

Open xanderdunn opened 9 years ago

xanderdunn commented 9 years ago

You can see in the below screenshot that although my cursor is not actually on any word at all, Matchmaker is highlighting (underlining) the word closest to the cursor.

screen shot 2015-01-03 at 18 36 56

It's very strange that anything should be highlighted when I'm not focusing on anything. I find it much more of a distraction than it is helpful. Could we highlight words only when the cursor is truly on top of them? Or perhaps at least make this an option?

Thanks!

qstrahl commented 9 years ago

I agree. The reason for this is we just use expand('<cword>') which is interpreted as the word closest to the cursor. I could put in a check of some kind to assert that the character under the cursor is a keyword character.

On Sat, 3 Jan 2015 21:42 Alex Dunn notifications@github.com wrote:

You can see in the below screenshot that although my cursor is not actually on any word at all, Matchmaker is highlighting (underlining) the word closest to the cursor.

[image: screen shot 2015-01-03 at 18 36 56] https://cloud.githubusercontent.com/assets/1313618/5604542/dee9ccd8-9377-11e4-956a-aff1e6c48017.png

It's very strange that anything should be highlighted when I'm not focusing on anything. I find it much more of a distraction than it is helpful. Could we highlight words only when the cursor is truly on top of them? Or perhaps at least make this an option?

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/qstrahl/vim-matchmaker/issues/18.

matt1003 commented 8 years ago

There is a potential solution described on stack overflow: http://stackoverflow.com/questions/15020143/vim-script-check-if-the-cursor-is-on-the-current-word

let cInd = strridx(getline('.'), expand(""), col('.') - 1)
let isOnKeyword = (cInd >= 0 && (cInd + strlen(expand(""))) >= (col('.') - 1))