3 回答

TA貢獻1802條經驗 獲得超4個贊
使用ftplugins或自動命令來設置選項。
ftplugin
在 ~/.vim/ftplugin/python.vim:
setlocal shiftwidth=2 softtabstop=2 expandtab
并且不要忘記將它們打開~/.vimrc:
filetype plugin indent on
(:h ftplugin有關更多信息)
自動命令
在~/.vimrc:
autocmd FileType python setlocal shiftwidth=2 softtabstop=2 expandtab
您可以代替任何的長命令或設置及其短版本:
autocmd:au
setlocal:setl
shiftwidth:sw
tabstop:ts
softtabstop:sts
expandtab:et
我也建議學習之間的差異tabstop和softtabstop。很多人不知道softtabstop。

TA貢獻1818條經驗 獲得超8個贊
編輯~/.vimrc,并為不同的縮進添加不同的文件類型,例如,我希望html/rb縮進2個空格,js/coffee文件縮進4個空格:
" by default, the indent is 2 spaces.
set shiftwidth=2
set softtabstop=2
set tabstop=2
" for html/rb files, 2 spaces
autocmd Filetype html setlocal ts=2 sw=2 expandtab
autocmd Filetype ruby setlocal ts=2 sw=2 expandtab
" for js/coffee/jade files, 4 spaces
autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype coffeescript setlocal ts=4 sw=4 sts=0 expandtab
autocmd Filetype jade setlocal ts=4 sw=4 sts=0 expandtab
請參考:按文件類型設置Vim空格首選項
- 3 回答
- 0 關注
- 961 瀏覽
添加回答
舉報