Vim – applying separate settings for different file types
Posted by ajay on June 2, 2006
If you are using vim quite often, you might have configured your vimrc very well. But these settings grow continuously; so it is always not feasable to apply same settings for each and every filetype .. you might want to apply some x settings if you are writing a cpp programme and some y settings when you are editing an html code and so on. Your vimrc might be growing too large so you might want to separate it into different files; I mean different configuration for different file types. Here’s what you can do –
The syntex for specific filetype settings is
autocmd FileType cpp source ~/.vim/cpp.vim
autocmd FileType py source ~/.vim/py.vim
and so on…
now the third word in these lines specifies the extention and the fifth word specifies the file code to be executed .. that means from now onwards if a person will open a .cpp file ( cpp programme ) the vim settings writtin in ~/.vim/cpp.vim .. will be applied ..
you can specify settings for as many filetypes as you want .. and b sure that if you specify a source file in .vimrc of yours then even if you dont want to apply any settings as of now .. plzz create an appropriate file at an appropriate place which you have specified in the .vimrc otherwise whenever you will try to edit that filetype it will give errors .. thats it so now you can apply different settings for different codes.
I will put my .vimrc and some separate settings for different filetypes may be in a day or two .. any comments if you have any better ideas ..