Я предпочитаю настроить свою среду, как показано в примере ниже. Я делаю общее правило замены табуляции пробелами и использую augroup
, когда мне нужно переопределить это правило. Makefiles - хороший пример того, когда вам может потребоваться TABS, а файл cpp - когда вам могут потребоваться пробелы.
" A tab produces a 4-space indentation
:set softtabstop=4
:set shiftwidth=4
:set expandtab
" replace tabs with spaces unless noted otherwise
" <snip>
augroup CPPprog
au!
"-----------------------------------
" GENERAL SETTINGS
"-----------------------------------
au BufRead,BufNewFile,BufEnter *.cpp,*.c,*.h,*.hpp set nolisp
au BufRead,BufNewFile,BufEnter *.cpp,*.c,*.h,*.hpp set filetype=cpp
au FileType * set nocindent smartindent
au FileType *.c,*.cpp set cindent
au BufRead,BufNewFile,BufEnter *.cpp let g:qt_syntax=1
" turn on qt syntax highlighting (a plugin)
au BufNewFile,BufRead,BufEnter *.c,*.h,*.cpp,*.hpp let c_space_errors=1
" trailing white space and spaces before a <Tab>
" <snip>
augroup END
" <snip>
augroup filetype
au! BufRead,BufNewFile,BufEnter *Makefile*,*makefile*,*.mk set filetype=make
augroup END
" In Makefiles, don't expand tabs to spaces, since we need the actual tabs
autocmd FileType make set noexpandtab