Vim 中的自动补全

发布于 2024-10-20 02:46:45 字数 74 浏览 4 评论 0原文

我在自动完成方面遇到问题。如何在打字时获得代码建议?

我通常使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

慵挽 2024-10-27 02:46:45

在插入模式下,使用 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.

岛徒 2024-10-27 02:46:45

您可以使用 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.

救星 2024-10-27 02:46:45

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

If you are using VIM version 8+, just type Ctrl + n or Ctrl + p.

殊姿 2024-10-27 02:46:45

您可以从内置 omnifunc 设置开始。

只需将:

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

放在 .vimrc 的底部,然后在插入模式下输入 即可。

我一直依赖这个 CSS 补全。

You can start from built-in omnifunc setting.

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.

I always rely on this CSS completion.

彼岸花似海 2024-10-27 02:46:45

还有 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

对不⑦ 2024-10-27 02:46:45

另一个选择是 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.

撞了怀 2024-10-27 02:46:45

我已经使用 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.

完美的未来在梦里 2024-10-27 02:46:45

这是链接!对于 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

生活了然无味 2024-10-27 02:46:45

如果您只想从当前缓冲区的缓存中自动补全,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.

苦笑流年记忆 2024-10-27 02:46:45

对于 PHP,PadawanDeoplete 是在 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.

何以畏孤独 2024-10-27 02:46:45

我最近发现了一个名为 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!

enter image description here

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文