Beginning version 7 of vim, it has this nice auto-completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press [ctrl] + n or [ctrl] + p key while in edit mode. For example:

However, we can *teach* vim to autocomplete much other stuff by using so-called Dictionaries. We can have auto-completion for Python, Ruby, PHP, Bash, and any other programming languages code with this idea.

For example, let’s try to install a Python dictionary, by downloading it from here:

http://www.vim.org/scripts/script.php?script_id=850

The next thing to do is to extract the downloaded file to the appropriate folder:

$ mkdir ~/.vim
$ tar xf pydiction-0.5.tar.gz -C ~/.vim

and add these lines to your ~/.vimrc (be sure to replace “/home/user” with your own home directory)

if has("autocmd")
    autocmd FileType python set complete+=k/home/user/.vim/pydiction-0.5/pydiction isk+=.,(
endif " has("autocmd"

and let’s see the result:

There are many other scripts available on Vim’s script page worth trying as well.

Discuss the article:

Comment anonymously. Login not required.

Share!