Start vim without vimrc / change vimrc with open files

vim

Solution

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.

Problem

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?

Original source