I use git to persist my ~/.vim directory. I'd like to store my vimrc file in this directory as well so that it will also live in the repository. How do I change the location where Vim searches for the vimrc file?
3 Answers
You don't. Symlink it instead.
mv ~/.vimrc ~/.vim
ln -s ~/.vim/.vimrc ~/.vim
You cam do the symlink thing to sync your vimrc through Dropbox as well.
-
6I think you meant
mv ~/.vimrc ~/.vim
andln -s ~/.vim/.vimrc ~/.vimrc". That's what I do, too, as well as
ln -s ~/Dropbox/vimfiles ~/.vim`.– garyjohnAug 25, 2011 at 4:41 -
-
For Windows you can use
echo source ~/.vim/.vimrc > .vimrc
instead, which works better than the actual symlink variant Windows uses. Mar 6, 2013 at 22:51
digitxp's answer is probably the better one, but you can tell Vim to look for your vimrc anywhere you like with the -u command-line option, and gvimrc with -U, e.g.:
vim -u ~/.vim/vimrc -U ~/.vim/gvimrc
Vim 7.4 also sources ~/.vim/vimrc
by default. help vimrc
says:
Unix $HOME/.vimrc or $HOME/.vim/vimrc
But my current favorite solution for backing up files anywhere is https://github.com/technicalpickles/homesick which concentrates all config files in a single place and handles symlink management for you.