如何检查vim编译的python版本?

时间:2022-06-16 07:00:06

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.

在vim中抛出一个SyntaxError。

3 个解决方案

#1


49  

I just discovered here that you can also do it with

我刚刚在这里发现你也可以这样做

:python import sys; print(sys.version)

#2


9  

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.

如果vim是用python编译的,当你在命令行中键入:python << EOF时,命令行将使用换行符展开并等待EOF。在EOF之前,键入您的python代码,并以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.

编辑:正如您已经发现的那样,EOF是不必要的,您可以将您的脚本放在一行,没有引号和-c。 EOF技巧很适合在命令行中测试python / VIM脚本。

#3


1  

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

在命令行模式下运行:ve [rsion]或从Bash运行vim --version。

  1. If vim was compiled with Python 3, you'll find -python and +python3.
  2. 如果用Python 3编译vim,你会发现-python和+ python3。

  3. If vim was compiled with Python 2, you'll find +python and -python3.
  4. 如果用Python 2编译vim,你会发现+ python和-python3。

  5. If vim was compiled without Python support, you'll find -python and -python31.
  6. 如果在没有Python支持的情况下编译vim,你会发现-python和-python31。

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

我不确定是否可以在:ve输出中找到+ python和+ python3 - 目前可能不是。


1Currently -python and -python3 seems to be default for Debian's vim package. If you need vim's support for scripting languages, install vim-nox which is dedicated for them and therefore has (among others) +python3 enabled. There is also 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.

1C目前-python和-python3似乎是Debian的vim包的默认值。如果您需要vim对脚本语言的支持,请安装专用于它们的vim-nox,因此启用了+ python3。还有一个有趣的,重度重构的vim fork叫做neovim(简称nvim)。 BTW:在Debian上,您可以通过运行update-alternatives --list vim列出所有已安装的vim版本。

#1


49  

I just discovered here that you can also do it with

我刚刚在这里发现你也可以这样做

:python import sys; print(sys.version)

#2


9  

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.

如果vim是用python编译的,当你在命令行中键入:python << EOF时,命令行将使用换行符展开并等待EOF。在EOF之前,键入您的python代码,并以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.

编辑:正如您已经发现的那样,EOF是不必要的,您可以将您的脚本放在一行,没有引号和-c。 EOF技巧很适合在命令行中测试python / VIM脚本。

#3


1  

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

在命令行模式下运行:ve [rsion]或从Bash运行vim --version。

  1. If vim was compiled with Python 3, you'll find -python and +python3.
  2. 如果用Python 3编译vim,你会发现-python和+ python3。

  3. If vim was compiled with Python 2, you'll find +python and -python3.
  4. 如果用Python 2编译vim,你会发现+ python和-python3。

  5. If vim was compiled without Python support, you'll find -python and -python31.
  6. 如果在没有Python支持的情况下编译vim,你会发现-python和-python31。

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

我不确定是否可以在:ve输出中找到+ python和+ python3 - 目前可能不是。


1Currently -python and -python3 seems to be default for Debian's vim package. If you need vim's support for scripting languages, install vim-nox which is dedicated for them and therefore has (among others) +python3 enabled. There is also 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.

1C目前-python和-python3似乎是Debian的vim包的默认值。如果您需要vim对脚本语言的支持,请安装专用于它们的vim-nox,因此启用了+ python3。还有一个有趣的,重度重构的vim fork叫做neovim(简称nvim)。 BTW:在Debian上,您可以通过运行update-alternatives --list vim列出所有已安装的vim版本。