How to set C++ compiler options for Syntastic

To learn how to install and use Syntastic, please see this post.

Syntastic should be able to detect the C++ compiler on your system and use it for syntax checking automatically. If you need to change it or set it explicitly, then add its command or full path to your .vimrc:

let g:syntastic_cpp_compiler = "g++"

You might want to enable some compiler options for Syntastic to apply on your code. For example, I like to add support for C++11 and also rigorously check for warnings, so I add this to my .vimrc:

let g:syntastic_cpp_compiler_options = "-std=c++11 -Wall -Wextra -Wpedantic"

Tried with: GCC 4.9.2, Vim 7.4 and Ubuntu 14.04

How to use Syntastic plugin for Vim

Syntastic is a plugin for Vim that can check the currently displayed code for syntax errors and mark those lines with the error messages. This is a type of feature that is typically available in an IDE. This is useful since compile or run-time errors in C++ (or any other language) can be discovered while writing the code without going outside Vim.

  • I use Pathogen to install Syntastic. This is as simple as cloning the Syntastic Github repository in my .vim/bundle directory.

  • If you have GCC and G++ installed to their default directories, then Syntastic should work immediately in any C++ file. Detailed help is available for Syntastic by using the command :help syntastic.

  • Open any C++ file and see what Syntastic knows about this file by using the command :SyntasticInfo.

  • Create a few syntax errors in a C++ file and save the changes with :w. You should be able to see those lines marked with special characters in the left column of the editor window. Navigating the cursor to that line shows its error at the bottom of Vim, below the statusline.

  • To jump between the lines with errors, the errors need to be first loaded into the Vim location list. To do that, use the command :Errors. A new subwindow appears at the bottom named Location list and you can see the errors listed there. Switch to that window, move to an error and press Enter to jump to that error line in your code.

  • Once the errors are loaded into the Vim location list, you can directly jump between the lines with errors in your code using the Vim commands :lnext and :lprev.

  • If you have installed Tim Pope’s unimpaired plugin, you can jump between errors using ]l and [l.

  • To setup Syntastic to automatically load errors into the location list, add this line to your .vimrc:

let g:syntastic_always_populate_loc_list = 1
  • By default, Syntastic does not check for errors when a file is loaded into Vim. To enable that, add this line to your .vimrc:
let g:syntastic_check_on_open = 1
  • By default, Syntastic checks for errors whenever you save the file. To disable this, add this line to your .vimrc:
let g:syntastic_check_on_wq = 0
  • To explicitly invoke syntax check on the current file, use the command :SyntasticCheck.

  • By default, Syntastic uses arrow symbols to indicate line with error. To spice things up, you can specify any Unicode symbol as the symbol. For example:

let g:syntastic_error_symbol = "✗"
let g:syntastic_warning_symbol = "⚠"

Tried with: Syntastic 3.5.0-72, Vim 7.4 and Ubuntu 14.04

How to install and use vim-powerline plugin for Vim

Statusline displayed by vim-powerline
Statusline displayed by vim-powerline

The statusline in Vim gets the job done: it shows the current mode and the location of the cursor in the currently open file. The vim-powerline plugin is a great way to jazz up the statusline of Vim and show lots of useful additional information. (As of this writing, folks are working on a new powerline plugin. This post is about the older vim-powerline plugin.)


The powerline plugin can be installed for Pathogen by cloning its Github repository.

Color support

The plugin uses lots of bright colors and needs 256-color support in Vim. One way to turn this on in Vim is by adding this line to your vimrc:

set t_Co=256

Fancy symbols

By default it shows a simple colored statusline. By using Unicode symbols, it can present a more beautiful statusline. To turn this on, add this line to your vimrc:

let g:Powerline_symbols = "fancy"

Patched fonts

The plugin can show symbols if the file is in version control (Git or Mercurial), for the filetype, for the line number and many more. For this to work, you need to patch your font and use that patched font for your terminal or Vim.

If you are on Ubuntu and using the default Ubuntu Mono font, then a patched version of this font can be obtained here. Follow the instructions on that page to install the fonts.

If you are on Windows and using Consolas, either directly or through SSH with PuTTY, I have more information in another post.

For other fonts and setups, use the script and directions in the fontpatcher directory.

Additional plugins

The plugin can show information on syntax errors and also version control information for Git and Mercurial. To view these status symbols and messages, install these three plugins: syntastic (for syntax checking), fugitive (for Git) and hgrev (for Mercurial).

With all this set up correctly, you get a Vim statusline that looks gorgeous and shows lots of useful information, both in terminal and GUI modes.

Tried with: Vim 7.3 and Ubuntu 12.04 LTS