181

Is there a command in the Vim editor to find the .vimrc file location?

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
niting112
  • 2,498
  • 2
  • 16
  • 18

4 Answers4

274

Just try doing the following:

:version

You will get an output which includes something like:

 system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"

As noted by Herbert in comments, this is where vim looks for vimrcs, it doesn't mean they exist.

You can check the full path of your vimrc with

:echo $MYVIMRC

If the output is empty, then your vim doesn't use a user vimrc (just create it if you wish).

Skippy le Grand Gourou
  • 6,976
  • 4
  • 60
  • 76
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • 26
    To clarify: `:version` tells what locations are searched, but doesn't give any info regarding what files were found. For that the $MYVIMRC variable is useful, as is looking at output of `:scripts` for full list of all loaded script files, including all vimrc files. – Herbert Sitz Jan 23 '12 at 20:38
  • 25
    @HerbertSitz `:scripts` -> `:scriptnames` (innocent typo) – Randy Morris Jan 23 '12 at 23:54
  • 9
    I'm running vim 7.4 on OSX 10.10.5 installed with Homebrew, and `:echo $MYVIMRC` outputs nothing. – Heath Borders Dec 09 '15 at 01:04
  • 7
    I know this is like two years old but regarding the last two comments. I got a blank output when running that command from the command line however when opening vim then typing ":echo $MYVIMRC" I got the real vimrc file. – Four_0h_Three Aug 09 '17 at 04:33
  • 1
    On Arch Linux, sudo would NOT honor `/etc/vimrc` until I `ln -s` it to `/root/.vimrc`. – Theodore R. Smith May 05 '19 at 15:25
  • 1
    I have user vimrc file: "$HOME/.vimrc" 2nd user vimrc file: "~/.vim/vimrc" but 2nd user vimrc file doesn't take effect, i need to put everything i want in $HOME/.vimrc what i'm missing? – Bashar Al-Abdulhadi Aug 09 '20 at 15:36
  • @BasharAl-Abdulhadi The `2nd user vimrc file` (e.g. `~/.vim/vimrc`) **does not take effect**, **if** the main `user vimrc file` (probably `~/.vimrc`) does exist. It's only a **strict fallback**. – Semnodime Jan 30 '23 at 18:38
7

:version does not provide a complete and exhaustive list.

It does not list /etc/vim for example, despite this being the path vim uses to pick up gvimrc and vimrc on my Ubuntu box running vim82 from vim-gtk3.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Jeremy Woodland
  • 3,444
  • 5
  • 17
  • 25
6

For nvim use :scriptnames like proposed in Randy Morris comment

mickours
  • 1,113
  • 12
  • 13
3

Run :script, which will show you all the locations where VIM is loading files from. Probably, your source file is located somewhere in those directories. If you find a different source file, you may insert the following in it:

if filereadable("/my/directory/.vim/.vimrc")
   source /my/directory/.vim/.vimrc
endif

And VIM will load your custom config file wherever it is.

Check it is working by looking for it in the output of :script

RicHincapie
  • 3,275
  • 1
  • 18
  • 30