Setting up Vim for C++ development

Vim is a powerful text editor that supports multiple programming languages and comes with a whole host of features such as a multi-level undo tree, powerful search and replace, and an extensive plugin system allowing for customisation. One advantage of using a text editor over an IDE is speed. The official Vim C++ Wiki page contains some useful tips for using Vim with C++.

Managing Vim plugins

Plugins are useful for adding extra functionality to Vim. The Vundle (Vim bundle) plug-in manager for Vim installs, updates, cleans, searches and configures plugins. Installing Vundle is the first step for setting up Vim for C++ development.

Installing a Vim plugin from GitHub using Vundle requires three simple steps:

Clone the plugin repository to your ~/.vim/bundle/ directory

Update your ~/.vimrc file with the new plugin details

Install the plugin by launching Vim and running :PluginInstall

To check what plugins are installed, startup Vim and type :PluginInstall and a list of installed plugins will appear.

Code completion for C++

The YouCompleteMe code completion engine for Vim supports several programming languages and specifically uses a Clang-based engine for C++ code completion. It also includes a semantic engine triggered by typing . or -> or :: as well as diagnostics.

Syntastic relies on external checkers in order to perform syntax checks, so these should be added to your ~/.vimrc file.

Install the plugin by launching Vim and running :PluginInstall

Check that everything is installed correctly by running :SyntasticInfo (the C++ checkers you installed should be listed in the output)

Debugging for C++

When it comes to debugging C++ code, some people choose to debug in Vim whilst others prefer to switch to an IDE. Clewn integrates the GNU debugger (gdb) into the Vim editor which allows for gdb command completion, breakpoints, watch variables etc.

Tags for C++ code

When browsing large C++ projects it can be useful to view an outline of the classes with their associated methods shown. The tagbar plugin provides this functionality by displaying a tags in a window, ordered by scope.

An almost Vim IDE for C++

The yavide project aims to create an Integrated Development Environment (IDE) similar to Eclipse or Visual Studio in Vim. This is an ambitious task and thus far includes a bunch of plugins working together to create this functionality. Features include a project explorer, project builder, class browser, code auto-completion, code navigation, code syntax highlighting and auto-formatting, as well as code management.