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

Does vim-illuminate require Vim 8.x? #23

Closed scottchiefbaker closed 5 years ago

scottchiefbaker commented 6 years ago

I'm trying to run vim-illuminate on Vim 7.4x (CentOS 7) and I get this error:

"~/.vimrc" 270L, 9893C
Error detected while processing function illuminate#on_cursor_moved..<SNR>57_get_cur_word:
line    3:
E121: Undefined variable: l:col:

If I move to Vim 8.x I don't have any problems with the same config. I don't see anything in the docs about requiring 8 so I wasn't sure how to proceed.

scottchiefbaker commented 6 years ago

For the time being I've worked around this in my .vimrc with

if version >= 800
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Highlight the word under the cursor
Plugin 'RRethy/vim-illuminate'
" Time in millis (default 250)
let g:Illuminate_delay = 250
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
endif
RRethy commented 6 years ago

It should work for previous versions of Vim. The Illuminate_delay is only available on Vim8 since it uses the timers features (I'll update the README so that's clear). I'm going to build an older version of Vim on my machine and do some testing.

RRethy commented 5 years ago

It seems to be a Vim bug in Vim7.4. I can't find any reference to it in online forums but the problem is that list splicing doesn't work when using a variable as the start.

To reproduce, in Vim7.4 try this:

:let col = 1
:let str = "abcd"
:echo str[col:]

It will error but it shouldn't. If you ran echo str[1:] it will not error, and if you run the three commands above in Vim8 or Neovim it will work fine.

I'll put out a check for the Vim version and default to an older way that I would get the current word under the cursor (although it is not as good, see #3). This will stop the error. Weird bug, I'd recommend using Vim8 if you can since it will match the word a lot better (again, see #3 for more info).

scottchiefbaker commented 5 years ago

Whatever you did works for me on Vim 7.4.x now. Thank you!

RRethy commented 5 years ago

@scottchiefbaker Can you try looking https://github.com/RRethy/vim-illuminate/pull/29 and checking out the branch to see if highlighting works in Vim 7.4.x, thank you.