Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start vim without vimrc / change vimrc with open files

Tags:

vim

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?

like image 543
Anshul Goyal Avatar asked Aug 30 '13 14:08

Anshul Goyal


People also ask

How do I open a vimrc file in Vim?

Opening vimrc Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter. In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file.

How do I source vimrc?

Sourcing it is the same as typing each command in order. You source with the command :source (usually shortened to :so ). The only file sourced by default is the . vimrc ( _vimrc on windows) so that's a place you can keep all the commands you use to set up Vim every time.

Where is vimrc default stored?

The system vimrc should normally be left unmodified and is located in the $VIM * directory.


1 Answers

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.

like image 64
romainl Avatar answered Nov 16 '22 03:11

romainl