Use Artistic Style with vim

Artistic Style is a “Free, Fast and Small Automatic Formatter for C, C++, C++/CLI, C#, and Java Source Code”. It is basically a utility that reformats source code in a conventionally-defined indent and coding style.

First, install the program.

On Ubuntu/Debian:

$ sudo apt-get install astyle

On OS X (with Homebrew):

$ brew install astyle

In order to use the command in a simple manner, you can set options in the options file ~/.astylerc. I use the following options that uses Kernighan & Ritchie (K&R) style. For more supported styles and options, see


Open vim, gVim or MacVim, and after editing some C/C++ files, use the following command to reformat the source code: