Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to change length of tab depending on file extension? [duplicate]

Tags:

vim

vi

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.

like image 513
Kelp Avatar asked May 16 '11 01:05

Kelp


People also ask

What is smart tab vim?

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.

How do I change the tab length in Pycharm?

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 .

What is Softtabstop?

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.

What is Shiftwidth in vim?

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.


1 Answers

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.

like image 140
ZyX Avatar answered Nov 15 '22 21:11

ZyX