Autocompletion in Vim

VimAutocompleteMacvim

Vim Problem Overview


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.

Vim Solutions


Solution 1 - 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.

Solution 2 - Vim

You can use a plugin like AutoComplPop to get automatic code completion as you type.

2015 Edit: I personally use YouCompleteMe now.

Solution 3 - Vim

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

Solution 4 - Vim

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.

Solution 5 - 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

Solution 6 - 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.

Solution 7 - Vim

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.

Solution 8 - Vim

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/

Solution 9 - Vim

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

Solution 10 - Vim

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.

Solution 11 - Vim

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondiegocstnView Question on Stackoverflow
Solution 1 - VimBrandon FrohbieterView Answer on Stackoverflow
Solution 2 - VimmichaelmichaelView Answer on Stackoverflow
Solution 3 - VimÂngelo PolottoView Answer on Stackoverflow
Solution 4 - VimernixView Answer on Stackoverflow
Solution 5 - VimNishantView Answer on Stackoverflow
Solution 6 - Vimak17View Answer on Stackoverflow
Solution 7 - Vimsp3ctumView Answer on Stackoverflow
Solution 8 - VimParker AultView Answer on Stackoverflow
Solution 9 - VimBrian KenyaView Answer on Stackoverflow
Solution 10 - VimtningView Answer on Stackoverflow
Solution 11 - VimMatthieuView Answer on Stackoverflow