Indent C blocks where braces are opened and closed on a single line
From Vim Tips Wiki
Tip 1620 Printable Monobook Previous Next
created 2009 · complexity basic · author Sightless · version 7.0
This snippet, which should be put in ~/.vim/indent/c.vim to work, gives indentation like this:
for (;;)
{ do_something(); }
rather than having the contents of the loop at the same indent level as the 'for' keyword.
func! MyCindent(l)
let extra = match(getline(a:l),'^\s*{.*}$')==-1?0:&sw
return cindent(a:l)+extra
endfunc
setlocal indentexpr=MyCindent(v:lnum)
setlocal cinkeys+=}
let &l:indentkeys=&l:cinkeys