如何在 Mac OSX 上为 Vim 安装 python 语法支持?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4652472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 16:46:07  来源:igfitidea点击:

How to install python syntax support for Vim on Mac OSX?

pythonvim

提问by readmymsg123

I recently started programming in python and have fallen in love with Vim over the past few weeks. I know want to use Vim as my primary editor for python files. I know there are python plugins for Vim, but I am very confused as to where/how I can install these. I don't really understand where Vim is installed. I'm running the latest version of Mac OS X Snow Leopard.

我最近开始用 python 编程,并且在过去几周里爱上了 Vim。我知道想使用 Vim 作为我的 python 文件的主要编辑器。我知道 Vim 有 python 插件,但我对在哪里/如何安装这些插件感到非常困惑。我真的不明白 Vim 安装在哪里。我正在运行最新版本的 Mac OS X Snow Leopard。

Any help would be greatly appreciated. Thanks!

任何帮助将不胜感激。谢谢!

采纳答案by alfredodeza

To best answer your initial question: "How to install python syntax support in Vim":

为了最好地回答您最初的问题:“如何在 Vim 中安装 python 语法支持”:

There is no need to install anything! If you have not made any modifications (e.g. no configuration changes for vim in ~/.vimrc) try the following:

无需安装任何东西!如果您没有进行任何修改(例如没有对 vim in 进行配置更改~/.vimrc),请尝试以下操作:

  • Open a Python file with vim
  • type the following command :syntax on
  • 用 vim 打开一个 Python 文件
  • 输入以下命令 :syntax on

You should now have VIM properly highlight your Python file.

您现在应该让 VIM 正确突出显示您的 Python 文件。

To avoid having to re-type those command over and over again, I would suggest you keep a configuration file for VIM. This is usually located in your home directory, if there is not one there already, create a ~/.vimrcfile and add the syntax ondirective there to have VIM automatically highlight your Python files.

为了避免一遍又一遍地重新输入这些命令,我​​建议您为 VIM 保留一个配置文件。这通常位于您的主目录中,如果那里还没有,请创建一个~/.vimrc文件并在syntax on那里添加指令以使 VIM 自动突出显示您的 Python 文件。

If you need to know more about structure/installation of plugins, then Senthil's answer is better suited :)

如果您需要了解有关插件结构/安装的更多信息,那么 Senthil 的答案更适合:)

回答by Senthil Kumaran

You will find that you have a folder by name .vimin your home directory cd ~and it will contain the following directories

您会发现.vim在您的主目录中有一个按名称命名的文件夹,cd ~它将包含以下目录

ftdetect/  ftplugin/  plugin/  syntax/

You need to download the pluginsand install them (copy them) to those directories.

您需要下载插件并将它们安装(复制)到这些目录。

Apart from that, in your .vimrc file have the following lines which will enable you to write python programs following PEP8.

除此之外,在你的 .vimrc 文件中有以下几行,这将使你能够按照 PEP8 编写 python 程序。

set autoindent
set tabstop=4
set expandtab
set shiftwidth=4
filetype indent on 

There are some good documentationout there as well.

还有一些很好的文档

回答by Kemin Zhou

for mac os x, the vimrc file is located in /usr/share/vim directory edit the vimdc file with any text editor. Add the syntax onto the last line of the file. Then next time you start a file you can see color. This is a system wide setting. In other linux flavor it may be located in /etc/ you can find this file by find /etc -name vimdc. The edit will affect all the users on the machine. These setting can overwritten by the $HOME/.vimrc file. In your home you may also have a .vim directory. To check that you have these, do ls -a in your home directory.

对于 mac os x,vimrc 文件位于 /usr/share/vim 目录中,使用任何文本编辑器编辑 vimdc 文件。将语法添加到文件的最后一行。然后下次启动文件时,您可以看到颜色。这是系统范围的设置。在其他 linux 版本中,它可能位于 /etc/ 中,您可以通过 find /etc -name vimdc 找到此文件。编辑将影响机器上的所有用户。这些设置可以被 $HOME/.vimrc 文件覆盖。在您的家中,您可能还有一个 .vim 目录。要检查您是否拥有这些,请在您的主目录中执行 ls -a。