There is a great program called Artistic Style or Astil that does a whole bunch of code formatting for you. You can tell if you want space around the operators by opening curly braces on the same line as the loops, how you want to back off, etc. I tell you a little more about this: Automatic format C. It is easy to use, but the options allow you to customize a huge number of coding styles, including some predefined definitions for common styles, such as K & R.
Basically, once you install it in vimrc, just type gggqG to reformat your file. (gg to go to the beginning, gq to start formatting, G so that it is fully formatted to the end.)
This does not help formatting during your code, but it can be a life saver when working with an existing file that is not formatted correctly, or quickly clear your own code.
Derek
source share