Tab stops (Re: [prog] C and curly braces - question of style?)
John Stoneham
lyric.programming at lyrically.net
Tue Aug 24 12:03:03 EST 2004
> > As someone mentioned (I think it was Akkana?), though, you tend to end
> > up with some combinations of tabs and spaces if you use
> > auto-indentation, and vi is no exception to that rule/problem. I wish
> > it'd pick up the characters used in the previous line and just
> > duplicate them, but I don't think it does.
>
> I mentioned this but perhas someone else did too. I think vi uses tabs for
> autoindent, and since I use tabs I haven't had this troble with vi, its other
> editors that mix them up.
It's possible to change this in vim (though old-school vi doesn't support it)
with 'set expandtab'.
Other options to check out are smartindent, cindent, smarttab.
I prefer 3-space indents and use spaces (I used to prefer tabs as they are
more correct in a semantic sense; however they cause problems when you try to
line stuff up on non-tabstop boundaries, so I gave up on them. Also, long
years of spaces-based coding standards at work). So my .vimrc starts:
syn on
set expandtab
set tabstop=3
set shiftwidth=3
set autoindent
set smarttab
Not sure why I'm not using smartindent... perhaps I should give it a try.
While we're talking indents, I should share the following useful function:
fun TotalFileIndent()
let oldLine=line('.')
normal(gg=G)
execute ':' . oldLine
endfun
map -- :call TotalFileIndent()<cr>
Now press -- to auto-indent your whole source file. (Java programmers be
careful, the default VIM indent-guide files don't handle anonymous subclass
syntax properly...)
- John
More information about the Programming
mailing list