I would like to fix only spacing in badly formatted C/C++ source code.The Vim command = fixes only indentation. Utility indent is not suitable, because it reformats totally all source code, but want to minimize changes (for example avoid to break lines, minimize noise for diff and SCM).For example, fix for( i=1; i<10; i++ ){tofor (i = 1; i < 10; i++) {
Fix spacing with vim
indentation;whitespace
This function almost does the job.Comment on the right side shows resultfunction! Fix_spacing()    %s/\<\(if\|for\|while\|switch\)(\s*/\1 (/ge      if (    %s/\<\(else\){/\1 {/ge                           else {    %s/}\(else\)/} \1/ge                             } else    %s/ *){ */) {/ge                                 ) {    %s/\((\) \(\S\)/\1\2/ge                          no space after (    %s/\n\n\n\+/\r\r/ge                              single empty line    %s/\([,;]\)\(\S\)/\1 \2/ge                       space after ,;    %s/\(\S\) \([,;)]\)/\1\2/ge                      no space before ,;)    %s/\s*$//ge                                      no terminal space    %s/^\([^ ^\t].*\){/\1\r{/ge                      { on new line for functionsendfunctionThis code inserts and deletes spaces around some keywords, brackets, comma, semicolon, terminal space and some line fixes.