Wikia

Vim Tips Wiki

Changes: Indent C blocks where braces are opened and closed on a single line

Edit

Back to page

(Assign tip id + convert to TipNew template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 3: Line 3:
 
|previous=1619
 
|previous=1619
 
|next=1621
 
|next=1621
|created=March 17, 2009
+
|created=2009
 
|complexity=basic
 
|complexity=basic
 
|author=Sightless
 
|author=Sightless
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
This snippet, which should be put in <tt>~/.vim/indent/c.vim</tt> to work, gives indentation like this:
+
This snippet, which should be put in <code>~/.vim/indent/c.vim</code> to work, gives indentation like this:
 
<pre>
 
<pre>
 
for (;;)
 
for (;;)

Latest revision as of 06:39, July 13, 2012

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

CommentsEdit

Around Wikia's network

Random Wiki