I use Vim as my main IDE for C/C++-related development (as well as for almost all other development). If you use (or are thinking about using) Vim as an IDE, you better get some good autocompletion functionality. This kind of autocompletion is provided by OmniComplete, which has been available since Vim 7.0. Just having OmniComplete is a nice thing, but it’s much more helpful if it’s configured properly to work with the libraries you use, such as wxWidgets. In this post, I will show you how to get OmniComplete working for wxWidgets. However, the procedure I will show can be easily adapted to almost all libraries.
The first step is to install ctags (if you haven’t got it installed already). This provides the tags file on which the autocompletion is based. ctags is available directly from the package manager of all popular distros.
The next step is to install the OmniCppComplete plugin for Vim. The plugin uses the ctags-generated tags file for the autocompletion. In order for the autocompletion to properly work with classes, you need to create the ~/.ctags file and add some default options. Each option should be listed on a new line. Your ~/.ctags file should look like this:
--c++-kinds=+p
--fields=+iaS
--extra=+q
These options will now be used as defaults when running ctags.
The next step is to create a tag file for the wxWidgets library. This can be done using the following command:
ctags -f ~/.vim/wxwidgetstags -R /usr/include/wx-2.8
Don’t forget to replace /usr/include/wx-2.8 with the path to the header files for wxWidgets. This will create the tags file under your ~/.vim directory.
The next step is to tell Vim to use this tags file. This is done by adding the following line to your ~/.vimrc:
:set tags+=~/.vim/wxwidgetstags
And now you’re done. OmniComplete will now work for wxWidgets, listing members and functions for any of the wxWidgets classes.
Remember, you can repeat the last two steps for any other libraries you use in order for OmniComplete to work with them too.
N.B. Don’t forget to run ctags -R . in your project’s root dir if you want OmniComplete to work for classes you defined.
One thought on “Setting Up OmniComplete (Autocompletion) for wxWidgets in Vim”