简体   繁体   中英

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.

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.

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 + nCtrl + p

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.

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

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 thing it is the best autocompletion engine for vim out there.

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.

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

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 .

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/

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.

use vscode and vim extension to it. then you will get all benefit of vscode,along with vim keybindings. if you are 24*7 on terminal or using 32 linux, you have to enable it using above mentioned methods.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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