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.
Smart tabs plugin or the newer vim-stabs plugin (which stands for smarter-tabs). The plugin ensures that tabs are only used for indentation, while spaces are used everywhere else.
If you want to change the tab size, first set the tab size you want in Settings -> Editor -> Code Style -> Python -> Tab size, then re-indent the code you want by selecting it and pressing Ctrl-Alt-L .
The value of 'softtabstop' equals how many columns (=spaces) the cursor moves right when you press <Tab> , and how many columns it moves left when you press <BS> (backspace) to erase a tab.
shiftwidth — Referred to for “levels of indentation”, where a level of indentation is shiftwidth columns of whitespace. That is, the shift-left-right commands, the formatting commands, and the behavior of vim with cindent or autoindent set is determined by this setting.
set sw=4 ts=4 sts=4 " Defaults: four spaces per tab "
autocmd FileType html :setlocal sw=2 ts=2 sts=2 " Two spaces for HTML files "
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With