Vim Tricks 2: Code Completion July 29, 2008

You may have used an IDE before that allows you to automatically complete parts of your code. In Microsoft's Visual Studio this is called "intellisense". It's very handy for speeding up development and for exploring objects that you can’t quite remember the attributes of. This week I found out how to add it to Vim.

I found a way of doing this for Python here and it shows how to map to a better shortcut (the same as is used in Visual Studio in fact). Unfortunately this only works for python and I was really hoping to have a way that works for as many languages as possible as I know Vim must support more and I use quite a few languages.

I did manage to find a simpler way that works for all of vim's supported languages here. Combining the two approaches gives an easy to use auto completion for loads of languages.

Just add the following to your .vimrc

          filetype plugin on
          inoremap <Nul> <C-x><C-o>

Then you can use Ctrl+Space to autocomplete your programming language keywords and the names of variables, functions and modules.