Vim indentation & C

25 January 2014
A while back I wrote about Vim, which I had adopted in favour of XEmacs for professional use. While Vim's (well, GVim's really) automatic indentation seemed fine for Python programming, I was not so sure about using it for other programming languages. Nevertheless I decided to have a go at getting Vim/GVim to use my preferred indentation style, which is done by changing the cinoptions parameter.

Intended style

My preferred bracing style is Whitesmiths, except with the first open brace being unindented. Not sure where this preference came from, but I suspect it is due to the idea that the opening of scope at the start of a function is different from that with conditionals and loops. This was probably in part due to the incorrect teaching that variables can only be declared at the start of functions. Whatever the reason the preference stuck, even when I subsequently used other languages.

The settings

With nothing else much left to do, these go into your ~/.gvimrc file:

set cindent set cinoptions={s,f0,>s,ns,^-sg0i0(0u0w1Ws

I'm not sure if autoindent and smartindent also need to be explicitly set as well, but my guess is that cindent will deal with these automatically.