Vim 中的自动补全
我在自动完成方面遇到问题。如何在打字时获得代码建议?
我通常使用 PHP、Ruby、HTML、C 和 CSS 进行开发。
I'm having trouble with autocompletion. How can I get a code suggestion while I'm typing?
I usually develop in PHP, Ruby, HTML, C and CSS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
在插入模式下,使用 Ctrl-N 获取单词建议列表。输入
:help i_CTRL-N
查看 Vim 关于此功能的文档。这里是一个将Python字典导入到Vim中的例子。
Use Ctrl-N to get a list of word suggestions while in insert mode. Type
:help i_CTRL-N
to see Vim's documentation on this functionality.Here is an example of importing the Python dictionary into Vim.
您可以使用 AutoComplPop 这样的插件在您键入时自动完成代码。
2015 编辑:我个人现在使用 YouCompleteMe。
You can use a plugin like AutoComplPop to get automatic code completion as you type.
2015 Edit: I personally use YouCompleteMe now.
如果您使用的是 VIM 版本 8+,只需键入
Ctrl + n
或Ctrl + p
。If you are using VIM version 8+, just type
Ctrl + n
orCtrl + p
.您可以从内置
omnifunc
设置开始。只需将:
放在
.vimrc
的底部,然后在插入模式下输入
即可。我一直依赖这个 CSS 补全。
You can start from built-in
omnifunc
setting.Just put:
on the bottom of your
.vimrc
, then type<Ctrl-X><Ctrl-O>
in insert mode.I always rely on this CSS completion.
还有 https://github.com/Valloric/YouCompleteMe 它包括 Jedi 之类的东西,还有模糊匹配。到目前为止,我发现 YCM 是我尝试过的最快的。
编辑:还存在一些新的,例如 https://github.com/maralla/completor.vim
There is also https://github.com/Valloric/YouCompleteMe and it includes things like Jedi and also has fuzzy match. So far I found YCM to be the fastest among what I have tried.
Edit: There also exists some new ones like https://github.com/maralla/completor.vim
另一个选择是 coc.nvim。
它的速度非常快,而且补全效果也很棒,因为它使用与 VScode 相同的智能感知自动补全功能。
它还具有 linting 功能。所以它表明你可能有一个错误。
它支持多种语言。
设置和配置可能需要一些时间,但我认为它是 vim 最好的自动完成引擎。
Another option is coc.nvim.
It's really fast and the completion is great as it uses intellisense the same autocompletion as VScode has.
It also has linting capabilities. So it shows you were you might have a bug.
It supports a multitude of languages.
It might take a bit to set up and configure but I think it is the best autocompletion engine for vim out there.
我已经使用 neocomplcache 大约半年了。它是一个插件,可以收集所有缓冲区中的单词缓存,然后提供它们供您自动完成。
上一个链接中的项目页面上有一系列屏幕截图。 Neocomplcache 还具有大量配置选项,其中项目页面上也有基本示例。
如果您需要更深入的了解,可以查看我的 vimrc 中的相关部分 -只需搜索单词 neocomplcache 即可。
I've used neocomplcache for about half a year. It is a plugin that collects a cache of words in all your buffers and then provides them for you to auto-complete with.
There is an array of screenshots on the project page in the previous link. Neocomplcache also has a ton of configuration options, of which there are basic examples on the project page as well.
If you need more depth, you can look at the relevant section in my vimrc - just search for the word neocomplcache.
这是链接!对于 PHP。
在编写一些 PHP 函数时,按 Ctrl + x,然后按 Ctrl + o 键。
感谢 Oseems Solutions 提供的教程
Here is link! for PHP.
press the Ctrl + x followed by Ctrl + o keys while writing some PHP functions.
Thanks to Oseems Solutions for the tutorial
如果您只想从当前缓冲区的缓存中自动补全,supertab 比 更容易安装="https://github.com/Shougo/neocomplete.vim" rel="nofollow">neocomplete,可以在 Mac 预装的 vim 上开箱即用,无需 MacVim。
您可以在 vim Awesome 查看其他替代方案。
If you only wanna auto-completion from cache of your current buffers, supertab is easier to install than neocomplete, can work on Mac pre-installed vim out of box without the need of MacVim.
You can check other alternatives at vim awesome.
对于 PHP,Padawan 与 Deoplete 是在 Neovim 中实现强大的 PHP 自动完成功能的绝佳解决方案。我尝试了很多东西,Padawan 的工作非常有魅力!
对于 Vim,您可以使用 Neocomplete 而不是 Deoplete。
如果有人感兴趣的话,我写了一篇如何制作 Vim PHP IDE 的文章。当然Padawan也是其中的一部分。
For PHP, Padawan with Deoplete are great solutions for having a robust PHP autocompletion in Neovim. I tried a lot of things and Padawan work like a charm!
For Vim you can use Neocomplete instead of Deoplete.
I wrote an article how to make a Vim PHP IDE if somebody is interested. Of course Padawan is part of it.
我最近发现了一个名为 OniVim 的项目,它是一个基于电子的 NeoVim 前端,具有非常强大的功能。开箱即用的多种语言的自动完成功能,而且由于它基本上只是 NeoVim 的包装,因此如果 GUI 不能满足您的需求,您可以使用 vim 的全部功能。它仍处于早期开发阶段,但正在快速改进,并且围绕它有一个非常活跃的社区。我使用 vim 已有 10 多年了,几周前开始试用 Oni,虽然它确实存在一些错误,但并没有妨碍我。我强烈推荐它给那些仍在使用 vim 的新 vim 用户!
OniVim:https://www.onivim.io/
I recently discovered a project called OniVim, which is an electron-based front-end for NeoVim that comes with very nice autocomplete for several languages out of the box, and since it's basically just a wrapper around NeoVim, you have the full power of vim at your disposal if the GUI doesn't meet your needs. It's still in early development, but it is rapidly improving and there is a really active community around it. I have been using vim for over 10 years and started giving Oni a test drive a few weeks ago, and while it does have some bugs here and there it hasn't gotten in my way. I would strongly recommend it to new vim users who are still getting their vim-fingers!
OniVim: https://www.onivim.io/