Correct C/C++ code indentation

#notes #Vim #C/C++

A quick way to correct the indentation of c/c++ code with vim, from stackoverflow.

First install astyle, the ANSI style

    apt-get install astyle

Then inside vim:

    :%!astyle     # astyle default mode is C/C++, this work on whole file
    :%!astyle --mode=c --style=ansi -s2     # ansi C++ style, use two spaces per indent level
    :1,40!astyle --mode=c --style=ansi      # ansi C++ style, filter only lines 1-40