tôi perfer để thiết lập môi trường của tôi lên giống như ví dụ dưới đây minh chứng. Tôi thực hiện quy tắc chung về cách thay thế các tab bằng dấu cách và sử dụng augroup
khi tôi cần ghi đè quy tắc đó. Makefiles là một ví dụ tốt khi bạn có thể yêu cầu TABS và một tệp cpp là khi bạn có thể yêu cầu không gian.
" 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
Nguồn
2011-08-05 01:16:45