Typically, you set up a special file of type vimrc with settings for a specific language, and then use the autocommands in your main .vimrc to execute special vimrc when necessary. Here is my configuration for Haskell files ( .hs , etc.):
autocmd! BufNewFile,BufReadPre,FileReadPre *.hs so ~/.vim/haskell.vim autocmd! BufNewFile,BufReadPre,FileReadPre *.hsc so ~/.vim/haskell.vim autocmd! BufNewFile,BufReadPre,FileReadPre *.lhs so ~/.vim/haskell.vim autocmd! BufNewFile,BufReadPre,FileReadPre *.cabal so ~/.vim/haskell.vim
My ~/.vim/haskell.vim does things like "set expandtab" to use spaces instead of tabs and all kinds of magic for formatting and the like. You can often download good versions of these files for different languages from http://vim.org and other sites.
Please note that you can do much more than just change the vim settings. For example, you can run a file through a filter before and after editing:
" Edit gpg-encrypted ascii-armoured files autocmd! BufReadPre,FileReadPre *.asc set bin autocmd BufReadPost,FileReadPost *.asc '[,']!gpg -q -d autocmd BufReadPost,FileReadPost *.asc set nobin autocmd! BufWritePre,FileWritePre *.asc set bin autocmd BufWritePre,FileWritePre *.asc '[,']!gpg -e autocmd BufWritePost,FileWritePost *.asc undo autocmd BufWritePost,FileWritePost *.asc set nobin
Curt J. Sampson May 21 '09 at 7:54 a.m. 2009-05-21 07:54
source share