How to change the default location of .vimrc to inside ~/.vim/?

8

1

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?

leo

Posted 2011-08-25T03:49:39.623

Reputation: 337

Answers

11

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.

digitxp

Posted 2011-08-25T03:49:39.623

Reputation: 13 502

6I think you meant mv ~/.vimrc ~/.vim and ln -s ~/.vim/.vimrc ~/.vimrc". That's what I do, too, as well asln -s ~/Dropbox/vimfiles ~/.vim`. – garyjohn – 2011-08-25T04:41:18.487

Fixed. Thats the last time I answer on a phone at midnight :P – digitxp – 2011-08-25T13:08:22.917

For Windows you can use echo source ~/.vim/.vimrc > .vimrc instead, which works better than the actual symlink variant Windows uses. – Daan Bakker – 2013-03-06T22:51:56.653

5

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

Heptite

Posted 2011-08-25T03:49:39.623

Reputation: 16 267

1

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.

See also: https://stackoverflow.com/questions/3377298/how-can-i-override-vim-and-vimrc-paths-but-no-others-in-vim

Ciro Santilli 新疆改造中心法轮功六四事件

Posted 2011-08-25T03:49:39.623

Reputation: 5 621