4

I feel like this might be because of my lack of vimscript knowledge. Basically I want to write a patch for this plugin https://github.com/actionshrimp/vim-xpath to make it work for python3 (and hence vim8).

I can just change it to say py3 everywhere it currently says py however that breaks it for python2 and so wouldn't be submittable as a pull request.

I don't want to litter the code with if/else has("python3") everywhere - ideally I'd like to assign the relevant command to a variable in an if else and then just use it everywhere. Or something similarly elegant

How do I do that?

6

See help pythonx in Vim 8:

Because most python code can be written so that it works with python 2.6+ and python 3 the pyx* functions and commands have been written. They work exactly the same as the Python 2 and 3 variants, but select the Python version using the 'pyxversion' setting.

  • Does this only support vim8? What if I write a plugin that is compatible with Vim 7? – artificerpi Jan 27 '18 at 6:02
  • @artificerpi I guess you can use has(“python3”) and handle it yourself – laktak Jan 27 '18 at 12:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.