VIM: Setting custom tab behaviour for some filetypes

To change the VIM tab settings for some file types, you can put something like this into ~/.vimrc (or _vimrc in your VIM directory if you are on windows); create the file if it doesn’t exist:

" Default tab behaviour: Use spaces instead of tabs, a tab is 4 spaces
set expandtab
set shiftwidth=4
set tabstop=4

" But tab should be 2 spaces in HTML and Smarty templates
autocmd FileType html
  \ setlocal shiftwidth=2 |
  \ setlocal tabstop=2
autocmd FileType smarty
  \ setlocal shiftwidth=2 |
  \ setlocal tabstop=2

The first block sets the default behaviour. The second block overrides the settings for the html and smarty file types.

This entry was posted in General. Bookmark the permalink.