Autocompletion on VIM

Éverton Arruda

Some time ago i read, in Renato Carvalho’s Blog (http://www.renatocarvalho.net/autocompletando-no-vim-dicionario-php.html), a post about autocompletion on VIM.

Autocompletion is a method which consists of completing a word when you write part of it, for example you write lin and press a key, on the keyboard, which is programmed to execute the autocompletion and it completes the word for you, giving you linux. For me it’s very useful.

If you want it too, all you have to do is:

1 – Create plugin and doc directories in ~/.vim:

1
$ mkdir -p ~/.vim/doc ~/.vim/plugin

2 – Download and install SuperTab plugin for VIM:

This plugin enables <tab> to be used for completion.
SuperTab Link:  http://www.vim.org/scripts/script.php?script_id=1643

3 – Download functions list of a language and save it to ~/.vim/doc:

Using google you should be able to find the function list of a language.
For this tutorial i’ll use a PHP functions list, you can get it at: http://lerdorf.com/funclist.txt, save this file in ~/.vim/doc as php-funclist.txt

4 – Add a few lines inside /etc/vim/vimrc:

Edit /etc/vim/vimrc and add the following lines:

1
2
3
if has("autocmd")
    autocmd FileType php  set complete-=k/home/$USER/.vim/doc/php-funclist.txt complete+=k/home/$USER/.vim/doc/php-funclist.txt
endif

These lines tell VIM to read the php-funclist.txt file and load it for autocompletion.

You could use another language functions list, all you have to do is change the name of the functions list file from the lines above.

Now you can test it, open vim and write part of a php function, then press the <tab> key and see what happens.

This tutorial was written by Rodrigo Carvalho, i made some modifications and, with his permission, i posted here.


One Response to “Autocompletion on VIM”

  • Nona Says:

    Muito bacana essa post, fiz aqui e ficou xibata.
    Estava procurando algo assim para o vim, vou ver se consigo achar pra outras linguagens que uso.
    :)

Leave a Reply