Filetype Plugin
This is what you're probably looking for, and is a very neat approach. You'll need to set filetype plugin on
in your vimrc to get this to work. A file must then be created at ~/.vim/ftplugin/<language>.vim
which will be loaded automatically for any buffers using that language.
For example, instead of writing your JavaScript settings to ~/.vimrc_js
, write them to ~/.vim/ftplugin/javascript.vim
.
Autocmd
autocmd
is the simplest way to set something on a language-specific basis:
autocmd Filetype <language> <setting>
This goes directly in your vimrc and will load settings for a specified filetype only.
To enable spellcheck across various text files, for example, one could use:
autocmd FileType markdown,tex,textile setlocal spell
You can set multiple settings at once by separating them with a pipe, those this quickly becomes unwieldy:
autocmd FileType php setlocal shiftwidth=4 tabstop=4|let php_sql_query=1
AutoCMD + Source
On rare occasions you might have enough settings to warrant a separate file, but would like to load them for multiple languages. Using filetype plugins, you'll end up with duplicate files or symlinks.
A simple alternative is to fall back to autocmd, but instead of writing the settings in one big line, you can instead source a file. For example:
autocmd FileType markdown,tex,textile source ~/.vim/lang_settings/text.vim