Possible to change length of tab depending on file

2019-04-05 15:53发布

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.

标签: vim vi
2条回答
Fickle 薄情
2楼-- · 2019-04-05 16:33

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=2and :set tabstop=2for e. g. HTML files. I guess the syntax files of your installation are responsible for your brace indentation symptom as well.

查看更多
小情绪 Triste *
3楼-- · 2019-04-05 16:40
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.

查看更多
登录 后发表回答