targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

Error after sourcing vimrc when `g:targets_nl` is set

Open victorkristof opened this issue 4 years ago • 1 comments

Hi there,

Thank for the great plugin!

After I source my vimrc, targets.vim gets some errors for operations on i{text-obj} and a{text-obj} (e.g., diw):

Error detected while processing function targets#e:
line    6:
E714: List required
Error detected while processing function targets#e:
line   12:
E121: Undefined variable: nKeys
Error detected while processing function targets#e:
line   19:
E121: Undefined variable: lKeys
Error detected while processing function targets#e:
line   26:
E121: Undefined variable: nKeys
Error detected while processing function targets#e:
line   26:
E116: Invalid arguments for function s:hasPrefix(nKeys, pending) || s:hasPrefix(lKeys, pending)

This is how I configured the plugin in my vimrc:

let g:targets_nl = 'nN'

When removing this line, the error disappears.

victorkristof avatar Sep 02 '20 11:09 victorkristof

targets.vim changes the value of g:targets_nl to be a list when it is loaded. In this case, that list is ['n', 'N']. So, if you reset the variable to a string after it is loaded, that results in the error E714: List required. As a workaround, you can instead use

let g:targets_nl = ['n', 'N']

If you always set it to be a list, then the issue doesn't occur.

IMO, this is still a bug with targets.vim, it really should just do the conversion each time. I would have to imagine that any speed up from doing the conversion once would be premature optimization.

I will probably make a PR to fix this in a sec

rgreenblatt avatar Apr 23 '21 00:04 rgreenblatt