E. Turok
E. Turok

Reputation: 116

Must .vimrc be located in the home directory?

I just moved my .vimrc, .vimrc~, ..vimrc.un~ files from my home directory into a folder called .vim. Now all of the preferences I made in .vimrc are not working when I edit a file in vim. I then moved my .vimrc file back into my home directory and all of a sudden my preferences are working again.

This leads me to wonder: does .vimrc need to be in the home directory? If so, why? And is there any way to change this?

I'm a total newbie with vim and so any help would be greatly appreciated. Thanks!

Upvotes: 1

Views: 3268

Answers (2)

G. Bai
G. Bai

Reputation: 513

An easy way to check where your Vim config files should be located:

$ vim --version | grep vimrc

You should see something like this:

   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"

So for user vimrc file, you could place it as $HOME/.vimrc or ~/.vim/vimrc.

Upvotes: 3

romainl
romainl

Reputation: 196886

  • Your .vimrc, with a period, must be in your $HOME directory:

      ~/.vimrc
    
  • You can move it to your ~/.vim/ directory but you must drop the period:

      ~/.vim/vimrc
    

Trying random things is a losing strategy. Instead, consider reading the relevant documentation and doing things properly. From :help vimrc:

[...]

Places for your personal initializations:
    Unix          $HOME/.vimrc or $HOME/.vim/vimrc
    MS-Windows    $HOME/_vimrc, $HOME/vimfiles/vimrc
                  or $VIM/_vimrc
    Amiga         s:.vimrc, home:.vimrc, home:vimfiles:vimrc
                  or $VIM/.vimrc
    Haiku         $HOME/config/settings/vim/vimrc

The files are searched in the order specified above and only the first
one that is found is read.

RECOMMENDATION: Put all your Vim configuration stuff in the
$HOME/.vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it
easy to copy it to another system.

[...]

Upvotes: 6

Related Questions