3 回答

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

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
編輯~/.vimrc,并為不同的縮進(jìn)添加不同的文件類型,例如,我希望html/rb縮進(jìn)2個(gè)空格,js/coffee文件縮進(jìn)4個(gè)空格:
" 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
請(qǐng)參考:按文件類型設(shè)置Vim空格首選項(xiàng)
- 3 回答
- 0 關(guān)注
- 954 瀏覽
添加回答
舉報(bào)