In Vim, is it possible to change the default location of the user vimrc file, i.e., from $HOME/.vimrc to some other location ?
8 Answers
Another solution might be to create a symlink
to you preferred location. I have my .vimrc
in $HOME/.vim/.vimrc
and symlink
to it. This way I can have it in a git repo and backup it.

- 1,261
- 13
- 30

- 23,169
- 18
- 105
- 180
-
1Oh what one would give to work on a platform with such easy access to symlinks. :) – dash-tom-bang Nov 05 '12 at 22:36
-
7@dash-tom-bang This is not common knowledge, but every major OS supports it, *including* Windows (ever since Vista). Try the [mklink](http://technet.microsoft.com/en-us/library/cc753194(v=ws.10).aspx) utility. – Tamás Szelei Nov 06 '12 at 12:32
-
Also, I just looked up that it is also possible do to pre-vista with an utility called [fsutil](http://serverfault.com/a/7175). Makes sense, since NTFS probably wasn't updated since it's inception. – Tamás Szelei Nov 06 '12 at 12:34
-
win: mklink /j /virtual/folder/_vimrc /real/_vimrc – sfy Oct 25 '17 at 15:51
The VIMINIT
variable is my preferred method. The problem with aliasing vim with the -u
flag is that if vim is opened in some way other than from the shell command your configuration won't get pulled in. Setting $VIMINIT does not suffer from this drawback. Check this out for more information.
export VIMINIT='source $MYVIMRC'
export MYVIMRC='~/.vim/vimrc' #or any other location you want
Note that Vim normally sets the MYVIMRC
variable, though I'm not sure exactly what it's used for. Based on my testing, using VIMINIT
in this fashion will result in it not being automatically set on startup as it would normally be. This is why I'm setting it myself.
This works for neovim too!

- 3,087
- 1
- 31
- 47
-
This works for me on both Ubuntu and Cygwin. I also don't see the need for `MYVIMRC` here - e.g. `export VIMINIT='source ~/.vim/vimrc'` works on my small test. It might bite me later though, so I'll use it for now anyway. – user2023370 Nov 27 '18 at 12:59
-
This was not enought for autoloading my `pathogen.vim`; I had to `set runtimepath` as well, as per [this](https://superuser.com/questions/413942/use-another-users-vimrc-and-vim#comment1169304_557073) comment. – simlev Sep 10 '20 at 08:24
You must start vim with the command vim -u ./path/to/your/vimrcfile
vim -u NONE
is a good way to start Vim without any plugin or customisation.
See :help starting.txt
for more information.

- 40,509
- 10
- 68
- 97
-
1Does the -u option mean that vim will only start with these customizations and all the global customizations from /etc and all will be skipped? – Vivek Aug 18 '11 at 15:28
-
3From starting.txt :`If Vim was started with "-u filename", the file "filename" is used. All following initializations until 4. are skipped.` The skipped steps include the use of the system wide vimrc. So it is `yes` to your question. – Xavier T. Aug 18 '11 at 15:34
On Windows, I have the _vimrc
that's in my home directory contain one line, source c:\path\to\my.vimrc
.
I have not yet worked out a good way to move the entirety of my vimfiles folder, but that's less critical as it's all stuff I've installed from elsewhere. I.e., it'd be easy to restore if I lost it. (I know that I can change runtimepath
but my problem is more coming up with a "good" way to do so.)
Update
After six years I extended slightly from what I mention in the comments below; as I put stuff into 'after' and wanted to just keep rtp
clean I got something that has been solid for a while now. Today in my %USERPROFILE%\_vimrc
I do hardcode the actual paths to things and it changes on every machine I use (and I basically do the same thing on *nix) but this gets copied around mostly-manually when setting up a new PC. I also have a version which I can use to launch Vim on another connected machine on the network, e.g. a co-worker's machine, so I get my config and all that, but the gist is:
set runtimepath^=E:/dotfiles/vim
set runtimepath+=E:/dotfiles/vim/after
set runtimepath-=~/vimfiles
set runtimepath-=~/vimfiles/after
runtime vimrc
and then %USERPROFILE%\_gvimrc
just has one line:
runtime gvimrc
(Both vimrc
and gvimrc
are in the /dotfiles/vim
folder and also on Bitbucket.)

- 17,383
- 5
- 46
- 62
-
I have since just decided to do `set runtimepath^=d:\path\to\vimfiles` which unfortunately hardcodes the location of those files but now at least I can keep them in source control. As it turns out, the more I use Vim, the more customization I want for my setup. – dash-tom-bang Nov 05 '12 at 22:35
-
-
This is the best solution after my opinion. I would say to add this to the ~/.bash_profile-file: alias vim="/PATH/TO/VIM-DIR/vim -S ~/PATH/TO/VIMRC-DIR/.vimrc" And the path to vim can be found by writing which vim (to see which vim is being used). – Zeth May 11 '17 at 18:24
-
This worked perfectly for me, after I realized that the line cannot be: source "c:\path\to\my.vimrc" (AKA must not use quotation marks) – Dan Jan 29 '20 at 14:41
I see two options, depending on your needs.
- Have ~/.vimrc import the other location
- create an alias in your bashrc alias vim="vim -u otherlocation"

- 121
- 4
I edited
C:\Program Files\Vim\_vimrc
and changed both the runtimepath and sourced my own .vimrc.
I also use these settings in Cygwin (and have them version controlled). So it's this in practice (added at the bottom of the _vimrc file):
let &runtimepath = 'C:\cygwin\home\cygwinaccount\.vim,' . &runtimepath
source C:\cygwin\home\cygwinaccount\.vimrc
Bliss ! :)

- 3,322
- 4
- 28
- 26
In linux:
You can edit .bashrc
or .zshrc
startup script and add the following lines to change the default location of .vimrc file
export VIMINIT='source $MYVIMRC'
export MYVIMRC='~/.vim/.vimrc' # Note the . (dot) before vimrc. If that is what you have called it.

- 5,732
- 1
- 57
- 70
I feel like the simplest solution is to just have a single line in ~/.vimrc
that loads the vimrc from the other location, i.e.:
source PATH/TO/OTHER/LOCATION/.vimrc

- 1,992
- 1
- 15
- 14