vim - Setting tab width based on file type -
i'm trying learn use vim. indenting 4 spaces use 2 spaces languages, such nim , moonscript. tried adding .vimrc
:
autocmd bufnewfile,bufread,bufenter *.nim :setlocal tabstop=2 shiftwidth=2 softtabstop=2
problem? doesn't anything! happens tab nothing when press it! doing wrong?
autocmd bufnewfile,bufread *.nim setlocal tabstop=2 shiftwidth=2 softtabstop=2
this should work (after restarting vim / re-editing existing file via :e!
) fine, mixes filetype detection filetype settings. vim has intermediate abstraction called filetype, should use. it, map file globs *.nim
filetype nim
, , define settings either via :autocmd filetype
, or filetype plugin in ~/.vim/ftplugin/nim.vim
(for latter, need :filetype plugin on
in ~/.vimrc
).
steps
so, create filetype detection in ~/.vim/ftdetect/nim.vim
:
autocmd bufread,bufnewfile *.nim setfiletype nim
then, create filetype plugin in ~/.vim/ftplugin/nim.vim
:
setlocal tabstop=2 shiftwidth=2 softtabstop=2
you can check these loaded correctly via :scriptnames
output. after restart of vim, should work, , can add additional settings latter file. if filetype derived another, can add :runtime! ftplugin/javascript.vim
(for example) in there settings, too.
Comments
Post a Comment