This one is a widely known feature of vim, as it should be for any other editor out there. Here’s a brief example on how to set your tab spacing settings depending on the filetype in vim. Add the following to your vimrc:

autocmd Filetype html setlocal ts=2 sts=2 sw=2
autocmd Filetype ruby setlocal ts=2 sts=2 sw=2
autocmd Filetype javascript setlocal ts=4 sts=4 sw=4

(As seen on stack overflow)

To find out the filetype of the current file in vim, type:

:set filetype

Settings will take effect when the file is loaded, so you may need to source your vimrc (:so ~/.vimrc) and then :e your file again.

blog comments powered by Disqus


30 January 2012