+1 to Peter's answer, but Vim provides another solution as well. If you want to do something more complicated than a single setlocal
, like setting up a whole bunch of options, commands, and mappings at once, then vim's filetype plugin feature comes to the rescue.
You need to have filetype plugin on
or filetype plugin indent on
in your .vimrc
, and then to create a plugin for e.g. ruby you can create ~/.vim/ftplugin/ruby.vim
. Technically you can use any commands you like in here, to be run when a Ruby file is loaded, but the recommended ones include setlocal
, map <buffer>
, command -buffer
, and defining functions. Lots more information is in the User Guide; if you're pretty familiar with scripting vim then jump to :help 41.11
, otherwise read :help usr_40
and :help usr_41
.