I have 2 .vimrc configuration files ~/.vimrc and ~/.vimsqlrc.

Is there a way I can source either of them (switch from one to another) while I have some files already opened? As an extension, how do I turn off the loading of vimrc (i.e, don't use any vimrc) while I have files open?

share
1  
Isn't :source filename working? – Adrian Aug 30 '13 at 14:21
    
The vimrc is sourced once when vim is loaded. It is never sourced again (unless you manually source it). (So I think the answer to your question is you can't) – FDinoff Aug 30 '13 at 14:23
    
@Adrian No it itsn't. – mu 無 Aug 30 '13 at 14:24
    
@FDinoff Do you have some links as references? – mu 無 Aug 30 '13 at 14:25
2  
@ansh0l probably :h initilization or :h vimrc. What are the differences between the two vimrc? It seems like you might be able to go with per filetype settings. – FDinoff Aug 30 '13 at 14:30
up vote 23 down vote accepted

Your ~/.vimrc is read and executed only once. If you want to nullify it with another file, you'll have to change the value of every single option and unmap every single mapping in, of course, both files. This sounds like a very bad and unnecessarily complex idea.

If you want another environment, just use another environment:

$ vim                 <-- starts Vim normally, reading ~/.vimrc
$ vim -u ~/.vimsqlrc  <-- starts Vim using your alternative vimrc
$ vim -u NONE         <-- starts Vim without any vimrc
$ vim -u NORC         <-- starts Vim without any vimrc, but with plugins

but I'm afraid you'll have to stop and restart Vim for that.

Anyway, your question has a very strong XY problem smell. Do you want to have specific settings for *.sql files?

If that's your goal, you can put your settings in ~/.vim/after/ftplugin/sql.vim like this:

setlocal autoindent
nnoremap <buffer> <F6> :echo "F6"<CR>

Using setlocal for options and <buffer> for mappings ensures that your settings are only applied for *.sql files.

share
    
With his last comment this is exactly what he wants – FDinoff Aug 30 '13 at 14:44
    
@FDinoff, yeah, that's what I thought while watching the comments count grow. – romainl Aug 30 '13 at 14:46
    
@romainl Not exactly *.sql files. Say I have a file which has sql statements littered every here and there. Now, whenever I want to edit such a file, the default vimrc settings are applied, even if all I want to do is fiddle around with the sql once I have the file open. – mu 無 Aug 30 '13 at 15:11
1  
Another option is to simply put specific sql settings in your vimrc like this: autocmd Filetype sql (do something). Especially if you only have a few settings for sql files which you want to change, I like this option better than creating a new file. – Steve SP Aug 31 '13 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.