Do this: Not this: -------- -------- #define MAX 50 int buf[MAX]; int buf[50]; if( i< MAX) { ... } if( i < 50) { ... }
int blah(int x, int y) { stmt1; stmt2; while (...) { stmt3; stmt4; if(...) { stmt5; stmt6; stmt7; } else { stmt8; } stmt9; } stmt10; }vim will auto-indent C code for you. You can also re-format C source in vim by puting the cursor at the start of the line you want to select to start reformating and scroll down (or shift-G to select to the end) and then hit = (SHIFT-V, SHIFT-G, =) (visual select, go to last line, re-format)
if ( ((blah[i] < 0 ) && (grr[j] > 234)) || ((blah[j] == 3456) && (grr[i] <= 4444)) || ((blah[i] > 10) && (grr[j] == 3333)) ) { stmt1; stmt2; } else { ...Here is an example of breaking up a long comment into multiple lines:
x = foo(x); /* compute the value of the next prime number */ /* that is larger than x (foo is a really bad */ /* choice for this function's name) */Here are two ways to break up a long string constant:
printf("here is a really long string with an int value %d", x); printf(" that I want to print to stdout\n"); OR printf("here is a really long string with an int value %d" " that I want to print to stdout\n", x);The easiest way to make sure you are not adding lines longer than 80 characters wide is to always work inside a window that is exactly 80 characters wide. If your line starts wrapping around to the next line, its too long.