How to check python version that vim was compiled with?

Question:

In the terminal, it works to do

python -c "import sys; print(sys.version)"

but doing

:python -c "import sys; print(sys.version)"

in vim throws a SyntaxError.

Asked By: beardc

||

Answers:

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);
Answered By: pb2q

I just discovered here that you can also do it with

:python import sys; print(sys.version)
Answered By: beardc

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.

Answered By: patryk.beza

You could just run a python --version from within Vim directly:

  1. Open vim.
  2. In normal mode (NOT insert mode), type :!python --version.
  3. Type enter.

The version of python is displayed.

Answered By: user3264341
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.