Autocompletion in Vim – Dev

The best answers to the question “Autocompletion in Vim” in the category Dev.


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.


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

2015 Edit: I personally use YouCompleteMe now.


Use CtrlN 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 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.


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