I\'ve got some sections in my .vimrc that look like this:
autocmd Filetype ruby setlocal ts=2
autocmd Filetype ruby setlocal sts=2
autocmd Filet
You can call a function, if you like:
autocmd Filetype ruby call SetRubyOptions()
function SetRubyOptions()
setlocal ts=2
...
endfunction
ftplugins are the neat answer to your question.
.vimrc has a line such as :filetype plugin on{rtp}/ftplugin/{thefiletype}.vim or {rtp}/ftplugin/{thefiletype}/whatever.vim (see :h rtp for more details).:setlocal command to ensure filetype-specific settings are only for that file (e.g., don't turn all comments purple across all filetypes).See examples in vim distribution if you plan to override default settings ; or among the many ftplugins I wrote otherwise), just write down your :setlocal, :*map <buffer>, etc. definitions.
It represents some more line to type, but at least, it does scale.
You can chain most commands with |:
au Filetype ruby
\ setlocal ts=2 |
\ setlocal sts=2 |
\ ...
Not sure if this syntax is better or worse than writing a function. Some commands can't be chained like this, but you can use execute to get around that; see :h :bar.
Also see :h line-continuation for an explanation of the weird syntax with the \ at the beginning of the lines.