Possible Duplicate:
Changing Vim indentation behavior by file type
Hello. So, I switch between '2' and '4' spaces for tabs very often. Usually I use 2 spaces for a tab for HTML files and 4 spaces for a tab for programming. Is there anyway to configure VIM, so it will automatically adjust depending on the file extension? Also, how come VIM indents 8 spaces sometimes, like after I enter an open brace? I have it set to 4 spaces. Thanks.
Type
:help syntax
in vim. This will open a help file giving an overview with subsequent pages/files showing you how to bind file extensions to syntax files where you can:set shiftwidth=2
and:set tabstop=2
for e. g. HTML files. I guess the syntax files of your installation are responsible for your brace indentation symptom as well.Here are three different options: 'shiftwidth' ('sw') controls number of spaces for automatic indentation and some shifting commands (like
<<
in normal mode), 'tabstop' ('ts') controls visual length of a real tab character, you may want to leave defaults (8 visual cells), 'softtabstop' ('sts') controls what is being inserted/removed when you press<Tab>
and<CR>
. I suggest you either set it to the value of 'tabstop' or set it alongside with 'expandtab' because in other cases it will produce ugly tabs+spaces indentation.