How to check python version that vim was compiled with?

I think you want this:

Type:

:python << EOF
import sys;
print(sys.version);
EOF

If vim was compiled with python, when you type :python << EOF in the command line, the command line will expand with newlines and wait for the EOF. Before the EOF, type your python code, and terminate with an EOF.

Edit: as you've already discovered, the EOF is unnecessary and you can have your script on a single line, sans quotes and -c. The EOF trick is nice for testing out python/VIM scripts in the command line.

:python import sys; print(sys.version);

Run :ve[rsion] in command-line mode or run vim --version from Bash.

  1. If vim was compiled with Python 3, you'll find -python and +python3.
  2. If vim was compiled with Python 2, you'll find +python and -python3.
  3. If vim was compiled without Python support, you'll find -python and -python31.

I'm not sure if it's possible to find both +python and +python3 in :ve output – currently probably not.


1Currently -python and -python3 seem to be the default for the Debian vim package. If you need vim support for scripting languages, install vim-nox, which is dedicated to them and therefore has (among other things) +python3 enabled. There is also an interesting, heavily refactored vim fork called neovim (or nvim in short). BTW: on Debian you can list all installed vim versions by running update-alternatives --list vim.


I just discovered here that you can also do it with

:python import sys; print(sys.version)

Tags:

Python

Vim