vim for python 中的语法高亮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4746579/
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
Syntax highlighting in vim for python
提问by hidroto
How do I do I set the syntax highlighting in Vim 7 for python?
如何在 Vim 7 for python 中设置语法高亮?
I would like to set my own colorschemes, and syntax highlighting for a type of code file.
我想为某种类型的代码文件设置我自己的颜色方案和语法突出显示。
采纳答案by mdeous
The command to enable syntax highlighting in vim is :syntax on, if you want it to be active everytime you launch vim, just add a line containing syntax onin your .vimrc file.
在 vim 中启用语法高亮的命令是:syntax on,如果您希望每次启动 vim 时它都处于活动状态,只需syntax on在 .vimrc 文件中添加一行。
回答by Robie Basak
Put the line syntax onin your .vimrc.
把这条线syntax on放在你的.vimrc.
回答by Eric Leschinski
Syntax highlighting in vim for python (target is Ubuntu 12.10)
在 vim 中为 python 突出显示语法(目标是 Ubuntu 12.10)
Here is a walkthroughon how to setup syntax highlighting in Python for Ubuntu 12.10. What you see is what you get:
这是有关如何在 Python 中为 Ubuntu 12.10 设置语法突出显示的演练。你所看到的就是你得到的:


https://github.com/sentientmachine/Pretty-Vim-Python/
https://github.com/sentientmachine/Pretty-Vim-Python/
Once you get the hang of how to inject a color scheme and syntax highlighting into your vi editor for a particular user, then you can customize it
一旦您掌握了如何为特定用户将配色方案和语法突出显示注入 vi 编辑器中,您就可以对其进行自定义
There are hundreds of fashionable color schemes here: https://github.com/morhetz/gruvbox
这里有数百种时尚配色:https: //github.com/morhetz/gruvbox
Pick one that you like. Then download the python.vimand foobarcolorscheme9000.vimfiles and put them in the right spot as defined here: https://alvinalexander.com/linux/vi-vim-editor-color-scheme-colorschemeSet the appropriate commands in the ~/.vimrc and logout login.
选择一个你喜欢的。然后下载python.vim和foobarcolorscheme9000.vim文件并将它们放在此处定义的正确位置:https: //alvinalexander.com/linux/vi-vim-editor-color-scheme-colorscheme在 ~/.vimrc 中设置适当的命令并注销登录.
Page listing most useful and fashionable python Color schemes:
列出最有用和最时尚的 Python 配色方案的页面:
https://stackoverflow.com/a/11060884/445131
https://stackoverflow.com/a/11060884/445131
Then you could try programming in VimL script language yourself.
然后你可以自己尝试用 VimL 脚本语言编程。
Learn to edit the code that causes vim syntax highlighting to work. Make it better than it ever was.
学习编辑使 vim 语法突出显示工作的代码。让它比以往任何时候都好。
http://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/VimL_Script_language
http://en.wikibooks.org/wiki/Learning_the_vi_Editor/Vim/VimL_Script_language
回答by Revol89
- Verify that you have the latest version of vim, equally execute
sudo apt-get install vim - Modify the
.vimrcfile with the instructionecho "syntax on" >> ~/.vimrc - Open the file with
vi app.py. You will see the Syntax highlighting
- 验证你有最新版本的vim,同样执行
sudo apt-get install vim .vimrc使用说明修改文件echo "syntax on" >> ~/.vimrc- 用
vi app.py.打开文件。您将看到语法突出显示
回答by lacostenycoder
If you're on *nix system (linux, macos) or cygwin and if you already have vim :set syntaxset but your filename doesn't end with .pyyou can add a shebang to the first line of your file:
如果您使用的是 *nix 系统(linux、macos)或 cygwin 并且您已经:set syntax设置了vim但您的文件名不以结尾,.py您可以在文件的第一行添加一个shebang:
#!/usr/bin/env python
Next time you open the file in vim, you should see syntax highlighting. Note this will work for other file types, you just use the interpreter name i.e. (python, ruby, sh)
下次在 vim 中打开文件时,您应该会看到语法高亮显示。请注意,这适用于其他文件类型,您只需使用解释器名称即(python, ruby, sh)

