简体   繁体   English

Vim 中的自动补全

[英]Autocompletion in Vim

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.我通常使用 PHP、Ruby、HTML、C 和 CSS 进行开发。

Use Ctrl - N to get a list of word suggestions while in insert mode.使用Ctrl - N在插入模式下获取单词建议列表。 Type :help i_CTRL-N to see Vim's documentation on this functionality.输入:help i_CTRL-N查看 Vim 关于此功能的文档。

Here is an example of importing the Python dictionary into Vim. 是一个将 Python 字典导入 Vim 的示例。

You can use a plugin like AutoComplPop to get automatic code completion as you type.您可以使用AutoComplPop 之类的插件在您键入时自动完成代码。

2015 Edit: I personally use YouCompleteMe now. 2015 年编辑:我现在个人使用YouCompleteMe

如果您使用的是 VIM 版本 8+,只需键入Ctrl + nCtrl + p

You can start from built-in omnifunc setting.您可以从内置的omnifunc设置开始。

Just put:只是说:

filetype plugin on
au FileType php setl ofu=phpcomplete#CompletePHP
au FileType ruby,eruby setl ofu=rubycomplete#Complete
au FileType html,xhtml setl ofu=htmlcomplete#CompleteTags
au FileType c setl ofu=ccomplete#CompleteCpp
au FileType css setl ofu=csscomplete#CompleteCSS

on the bottom of your .vimrc , then type <Ctrl-X><Ctrl-O> in insert mode..vimrc的底部,然后在插入模式下键入<Ctrl-X><Ctrl-O>

I always rely on this CSS completion.我总是依赖这个 CSS 补全。

There is also https://github.com/Valloric/YouCompleteMe and it includes things like Jedi and also has fuzzy match.还有https://github.com/Valloric/YouCompleteMe ,它包括 Jedi 之类的东西,也有模糊匹配。 So far I found YCM to be the fastest among what I have tried.到目前为止,我发现 YCM 是我尝试过的最快的。

Edit: There also exists some new ones like https://github.com/maralla/completor.vim编辑:还有一些新的,比如https://github.com/maralla/completor.vim

Another option is coc.nvim .另一种选择是coc.nvim

It's really fast and the completion is great as it uses intellisense the same autocompletion as VScode has.它非常快并且完成非常好,因为它使用与 VScode 相同的自动完成功能。 It also has linting capabilities.它还具有 linting 功能。 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 thing it is the best autocompletion engine for vim out there.设置和配置可能需要一些时间,但我认为这是最好的 vim 自动完成引擎。

I've used neocomplcache for about half a year.我已经使用neocomplcache大约半年了。 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. Neocomplcache 还有很多配置选项,项目页面上也有基本示例。

If you need more depth, you can look at the relevant section in my vimrc - just search for the word neocomplcache.如果您需要更深入的了解,可以查看我的vimrc中的相关部分 - 只需搜索 neocomplcache 一词即可。

Here is link !这是链接 for PHP.对于 PHP。

press the Ctrl + x followed by Ctrl + o keys while writing some PHP functions.在编写一些 PHP 函数时按 Ctrl + x,然后按 Ctrl + o 键。

Thanks to Oseems Solutions for the tutorial感谢 Oseems Solutions 的教程

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.如果您只想从当前缓冲区的缓存中自动完成, supertabneocomplete更容易安装,可以在 Mac 预装的 vim 上工作,无需 MacVim。

You can check other alternatives at vim awesome .您可以在vim awesome上查看其他替代方案。

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.我最近发现了一个名为OniVim的项目,它是一个基于电子的 NeoVim 前端,具有非常好的开箱即用的多种语言的自动完成功能,并且由于它基本上只是 NeoVim 的包装器,因此您拥有 vim 的全部功能如果 GUI 不能满足您的需求,您可以随时使用。 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.我使用 vim 已有 10 多年了,几周前开始试驾 Oni,虽然它确实存在一些错误,但它并没有妨碍我。 I would strongly recommend it to new vim users who are still getting their vim-fingers!我强烈推荐给仍在使用 vim 的新 vim 用户!

在此处输入图像描述

OniVim: https://www.onivim.io/ OniVim: https ://www.onivim.io/

For PHP, Padawan with Deoplete are great solutions for having a robust PHP autocompletion in Neovim.对于 PHP,使用DeopletePadawan是在 Neovim 中拥有强大的 PHP 自动完成功能的绝佳解决方案。 I tried a lot of things and Padawan work like a charm!我尝试了很多东西,学徒的工作就像一个魅力!

For Vim you can use Neocomplete instead of Deoplete.对于 Vim,您可以使用Neocomplete而不是 Deoplete。

I wrote an article how to make a Vim PHP IDE if somebody is interested.如果有人感兴趣,我写了一篇如何制作Vim PHP IDE的文章。 Of course Padawan is part of it.当然,学徒是其中的一部分。

use vscode and vim extension to it.使用 vscode 和 vim 扩展。 then you will get all benefit of vscode,along with vim keybindings.那么你将获得 vscode 的所有好处,以及 vim 键绑定。 if you are 24*7 on terminal or using 32 linux, you have to enable it using above mentioned methods.....如果您在终端上是 24*7 或使用 32 linux,则必须使用上述方法启用它.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM