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

- 32,039
- 22
- 142
- 171

- 2,498
- 2
- 16
- 18
4 Answers
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 vimrc
s, 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).

- 6,976
- 4
- 60
- 76

- 290,304
- 63
- 469
- 417
-
26To 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
-
9I'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
-
7I 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
-
1On 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
-
1I 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
: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.

- 5,031
- 17
- 33
- 41

- 3,444
- 5
- 17
- 25
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

- 3,275
- 1
- 18
- 30