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
setlocal indentexpr=MyCindent(v:lnum)
setlocal cinkeys+=}
let &l:indentkeys=&l:cinkeys

Comments[edit | edit source]

Community content is available under CC-BY-SA unless otherwise noted.