Tuesday, February 7, 2017

Python 2/3 scripting in vimscript

I've recently made the jump to python3 and I went to recompile vim with +python3 instead of +python. When I did this I noticed that all my python blocks in my .vimrc were failing.

Example of a python block:
```
python << endpython
# <some python code>
endpython
```


I was able to replace all of these with
```
python3 << EOF
# <some python code>
EOF
```

but all of my code in these blocks is 2/3 compatible and is critical for my .vimrc to function properly. Furthermore, I have several external vimscripts that use python blocks and having to change those is a pain.

Is there a way to dynamically define which python script to use?

```
if has('python3')
#define pythonX python3
else
#define pythonX python2
endif

pythonX << EOF
# <some python code>
EOF
```

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: