为 Python 设置 Vim
我真的很喜欢 Python 的 Emacs 编辑器,因为它有智能选项卡,例如,如果我有类似的东西
def foo():
if bar:
blah
[b]eep
,并且我在光标上按选项卡(位于蜂鸣声的 b 上),它不会插入新选项卡,从而导致语法错误,但它会切换蜂鸣声可能的级别。有什么方法可以在 Vim 上实现这种效果吗?
I really like the Emacs editor for Python because of its smart tabbing for instance if I have something like this
def foo():
if bar:
blah
[b]eep
and I press tab on the cursor (which is on the b of beep), it will not insert a new tab causing a syntax error but it would toggle through the possible levels that beep can be on. Is there any way of getting this effect on Vim?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
一般来说,vim 是一个非常强大的常规语言编辑器(宏对此进行了扩展,但我们暂时忽略它)。这是因为 vim 是 ed 之上的一个薄层,而 ed 只不过是一个使用正则表达式的行编辑器。 Emacs 的优点是构建在 ELisp 之上;使其能够轻松解析复杂的语法并执行缩进技巧,如您上面分享的那样。
说实话,我从来没能深入 emacs 的深处,因为它只是在我的 vim 洞穴中令人愉快的冥想。话虽如此,让我们开始吧。
入门
Janus
对于初学者,我强烈建议安装现成的 Janus 插件(fwiw,这个名字来自于 Janus Vim 的《星际迷航》剧集)。如果您想要一个快速访问 vim IDE 的快捷方式,那么这是您最划算的选择。
我从来没有经常使用它,但我看到其他人很高兴地使用它,而我当前的设置大量借用了旧的 Janus 版本。
Vim Pathogen
否则,请自行探索!如果你想了解 vim 插件的世界,我强烈建议安装 vim Pathogen。
它是某种包管理器。安装后,您可以将包
git clone
到您的~/.vim/bundle
目录中,它们会自动安装。不再有插件安装、维护或卸载的麻烦!您可以从 GitHub 页面运行以下脚本来安装病原体:
有用的链接
以下是我发现并喜欢的一些关于扩展 vim 的链接:
In general, vim is a very powerful regular language editor (macros extend this but we'll ignore that for now). This is because vim's a thin layer on top of ed, and ed isn't much more than a line editor that speaks regex. Emacs has the advantage of being built on top of ELisp; lending it the ability to easily parse complex grammars and perform indentation tricks like the one you shared above.
To be honest, I've never been able to dive into the depths of emacs because it is simply delightful meditating within my vim cave. With that said, let's jump in.
Getting Started
Janus
For beginners, I highly recommend installing the readymade Janus plugin (fwiw, the name hails from a Star Trek episode featuring Janus Vim). If you want a quick shortcut to a vim IDE it's your best bang for your buck.
I've never used it much, but I've seen others use it happily and my current setup is borrowed heavily from an old Janus build.
Vim Pathogen
Otherwise, do some exploring on your own! I'd highly recommend installing vim pathogen if you want to see the universe of vim plugins.
It's a package manager of sorts. Once you install it, you can
git clone
packages to your~/.vim/bundle
directory and they're auto-installed. No more plugin installation, maintenance, or uninstall headaches!You can run the following script from the GitHub page to install pathogen:
Helpful Links
Here are some links on extending vim I've found and enjoyed:
对于那些 2013 年夏天左右到达的人来说,我相信这篇文章中的一些内容已经过时了。
我遵循了此指南,其中建议使用 Vundle 而不是 Pathogen。使用一天后,我发现安装插件很简单。
klen/python-mode 插件值得特别提及。它提供 pyflakes 和 pylint 等功能。
我刚刚开始使用 Valloric/YouCompleteMe,我很喜欢它。它具有 C 语言自动完成功能,而且由于 jedi 集成,Python 也能很好地工作。根据此讨论,它很可能会取代 jedi-vim /davidhalter/jedi-vim/issues/119
最后浏览提供的 /carlhuda/janus 插件是一个很好的指南,帮助您了解您可能不知道正在寻找的有用脚本,例如 NerdTree、vim -fugitive、syntastic、powerline、ack.vim、snipmate...
以上所有“{}/{}”都可以在 github 上找到,您可以通过 Google 轻松找到它们。
For those arriving around summer 2013, I believe some of this thread is outdated.
I followed this howto which recommends Vundle over Pathogen. After one days use I found installing plugins trivial.
The klen/python-mode plugin deserves special mention. It provides pyflakes and pylint amongst other features.
I have just started using Valloric/YouCompleteMe and I love it. It has C-lang auto-complete and python also works great thanks to jedi integration. It may well replace jedi-vim as per this discussion /davidhalter/jedi-vim/issues/119
Finally browsing the /carlhuda/janus plugins supplied is a good guide to useful scripts you might not know you are looking for such as NerdTree, vim-fugitive, syntastic, powerline, ack.vim, snipmate...
All the above '{}/{}' are found on github you can find them easily with Google.
将以下内容放入您的
.vimrc
另请参阅详细说明
我个人使用 JetBrain 的 PyCharm 与 IdeaVIM插件 当做任何复杂的事情时,对于简单的编辑
.vimrc
的添加似乎就足够了。Put the following in your
.vimrc
See also the detailed instructions
I personally use JetBrain's PyCharm with the IdeaVIM plugin when doing anything complex, for simple editing the additions to
.vimrc
seem sufficient.有一组用于 Python 开发的 Vim 插件捆绑包:
http://www.vim.org/scripts/script.php?script_id=3770
There is a bundled collection of Vim plugins for Python development:
http://www.vim.org/scripts/script.php?script_id=3770
在 Linux 下,对我有用的是 John Anderson (sontek) 的指南,你可以找到它
他的配置截至今天已经是最新的了。
Under Linux, What worked for me was John Anderson's (sontek) guide, which you can find at this link. However, I cheated and just used his easy configuration setup from his Git repostiory:
His configuration is fairly up to date as of today.
前段时间我安装了 Valloric/YouCompleteMe,我发现它真的很棒。它为您提供文件路径、函数名称、方法、变量名称的补全...以及 davidhalter/jedi-vim
它使 vim 非常适合 python 编程(现在唯一缺少的是 linter)。
Some time ago I installed Valloric/YouCompleteMe and I find it really awesome. It provides you completion for file paths, function names, methods, variable names... Together with davidhalter/jedi-vim
it makes vim great for python programming (the only thing missing now is a linter).
回复:已死的“将 Vim 变成现代 Python IDE”链接,早在 2013 年,我保存了一个副本,将其转换为 HTML 页面以及 PDF 副本:
http://persagen.com/files/misc/Turning_vim_into_a_modern_Python_IDE.html
http://persagen.com/files/misc/Turning_vim_into_a_modern_Python_IDE.pdf
编辑(2017 年 9 月 8 日)更新的 URL。
Re: the dead "Turning Vim Into A Modern Python IDE" link, back in 2013 I saved a copy, that I converted to a HTML page as well as a PDF copy:
http://persagen.com/files/misc/Turning_vim_into_a_modern_Python_IDE.html
http://persagen.com/files/misc/Turning_vim_into_a_modern_Python_IDE.pdf
Edit (Sep 08, 2017) updated URLs.
一个非常好用的插件管理系统。包含的 vimrc 文件足以进行 python 编程,并且可以根据您的需求轻松配置。请参阅 http://spf13.com/project/spf13-vim/
A very good plugin management system to use. The included vimrc file is good enough for python programming and can be easily configured to your needs. See http://spf13.com/project/spf13-vim/