方式一: vim 编辑时设置
:set ts=4 sw=4 sts=4 et方式二: .vimrc
$ vim ~/.vimrc#paste the configuration below into the file. Once vim is restarted, the tab settings will apply.
# The width of a TAB is set to 4. Still it is a \t.
# It is just that Vim will interpret it to be having a width of 4.
# size of a hard tabstop
set tabstop=4
# Indents will have a width of 4
set shiftwidth=4
# Sets the number of columns for a TAB. a combination of spaces and tabs are used to simulate tab stops at a width
set softtabstop=4
# Expand TABs to spaces. always uses spaces instead of tab characters
set expandtab
# make "tab" insert indents instead of tabs at the beginning of a line
set smarttab
参考
http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces