So any way to provide a different vimrc file ( maybe at command line, giving it as parameter each time as vim --vimrc=somefile file-to-open) ?
Yes, use the -u
parameter:
vim -u ~/.my-custom-vimrc
From man vim
:
-u {vimrc} Use the commands in the file {vimrc} for initializations.
All the other initializations are skipped. Use this to
edit a special kind of files. It can also be used to skip
all initializations by giving the name "NONE". See ":help
initialization" within vim for more details.
My .vimrc file contains a command to automatically delete any trailing space while saving a file. But, I don't want this feature to be activated for specific files.
There's a different solution if you need special handling for some known filetypes; use the autocmd
command in your vimrc. For example, this is my filetype-dependent configuration:
" Mapping of filetypes to options
au FileType freerad setl noexpandtab sts=0 sw=8
au FileType make setl noexpandtab sts=0
au FileType php let php_sql_query=1
au FileType php let php_htmlInStrings=1
au FileType python setl shiftwidth=2 expandtab
au FileType sql setl noexpandtab sts=0 sw=8
" global options I do not want any filetype to override
au FileType * setl formatoptions-=ro " don't continue comments
If you need to apply options to something that vim doesn't automatically assign a certain filetype, you can add your own mapping (do that before using the autocmd
command):
" mapping of filenames to filetypes
au FileReadPost,BufReadPost,BufNewFile /etc/freeradius/* setl ft=freerad
au FileReadPost,BufReadPost,BufNewFile *.xt setl ft=xt
man vim
and look for-u
and-U
...