$VIMRC over .vimrc ?

28 views
Skip to first unread message

Christopher

unread,
Mar 17, 2026, 10:38:51 AM (2 days ago) Mar 17
to vim_use
When initializing Vim it searches first for $MYVIMRC, although that file doesn't exist in my case so it immediately goes to .vimrc. I'm reading the documentation on how to create this $VIMRC file as so that it's read first, rather then the .vimrc file ?

D. Ben Knoble

unread,
Mar 18, 2026, 11:48:15 AM (21 hours ago) Mar 18
to vim_use
On Tuesday, March 17, 2026 at 10:38:51 AM UTC-4 Christopher wrote:
When initializing Vim it searches first for $MYVIMRC, although that file doesn't exist in my case so it immediately goes to .vimrc. I'm reading the documentation on how to create this $VIMRC file as so that it's read first, rather then the .vimrc file ?

I'm afraid your question isn't clear to me, but let's look at `:help myvimrc`:

     c. Five places are searched for initializations.  The first that exists
is used, the others are ignored.  The `$MYVIMRC` environment variable is
set to the file that was first found, unless `$MYVIMRC` was already set
when using VIMINIT.  The `$MYVIMDIR` environment variable is
set to the personal 'rtp' directory, however it is not verified
that the directory actually exists.
I   The environment variable VIMINIT (see also |compatible-default|) (*)
    The value of $VIMINIT is used as an Ex command line.
II  The user vimrc file(s):
    "$HOME/.vimrc"   (for Unix) (*)
    "$HOME/.vim/vimrc"   (for Unix) (*)
    "$XDG_CONFIG_HOME/vim/vimrc"  (for Unix) (*)
    "s:.vimrc"   (for Amiga) (*)
    "home:.vimrc"   (for Amiga) (*)
    "home:vimfiles:vimrc"   (for Amiga) (*)
    "$VIM/.vimrc"   (for Amiga) (*)
    "$HOME/_vimrc"   (for Win32) (*)
    "$HOME/vimfiles/vimrc"   (for Win32) (*)
    "$VIM/_vimrc"   (for Win32) (*)
    "$HOME/config/settings/vim/vimrc" (for Haiku) (*)

Note: For Unix and Amiga, when ".vimrc" does not exist,
"_vimrc" is also tried, in case an MS-DOS compatible file
system is used.  For MS-Windows ".vimrc" is checked after
"_vimrc", in case long file names are used.
Note: For Win32, "$HOME" is checked first.  If no "_vimrc" or
".vimrc" is found there, "$VIM" is tried.  See |$VIM| for when
$VIM is not set.
III The environment variable EXINIT.
    The value of $EXINIT is used as an Ex command line.
IV  The user exrc file(s).  Same as for the user vimrc file, but with
    "vimrc" replaced by "exrc".  But only one of ".exrc" and "_exrc" is
    used, depending on the system.  And without the (*)!
V   The default vimrc file, $VIMRUNTIME/defaults.vim.  This sets up
    options values and has "syntax on" and "filetype on" commands,
    which is what most new users will want.  See |defaults.vim|.

So, unless you use VIMINIT to set MYVIMRC, MYVIMRC is intended to be set _by Vim_ to the file it finds.

Most folks I know use either ~/.vimrc or ~/.vim/vimrc (with equivalent ~/_vimrc or ~/vimfiles/vimrc on Windows). 

Christopher

unread,
Mar 18, 2026, 2:33:25 PM (18 hours ago) Mar 18
to vim_use
I read the documentation, therefore like with many I also use the system wide .vimrc file when starting vim. I want to know how to set  the $MYVIMRC as the documentation ? 

Marvin Renich

unread,
Mar 18, 2026, 3:46:39 PM (17 hours ago) Mar 18
to vim...@googlegroups.com
* Christopher <crestchr...@gmail.com> [260318 14:33]:
> I read the documentation, therefore like with many I also use the system
> wide .vimrc file when starting vim. I want to know how to set the $MYVIMRC
> as the documentation ?

It is set automatically by vim within the vim session. Assuming you are
using Linux (or other Unix-like OS), try

echo $MYVIMRC

from the command line. It should print a blank line if it is not set.
Now, invoke vim and try :echo $MYVIMRC from within vim. It will be set
to the full path of the vimrc file that was used.

Vim will export this for subshells. Still within vim, try

:! echo $MYVIMRC

(note the space after the "!"). This will create a subshell and
demonstrate that MYVIMRC is exported. After you leave vim, the variable
should not be set in your shell; this is normal.

You should not set this variable yourself; let vim do it.

...Marvin

Ben Knoble

unread,
Mar 18, 2026, 3:48:41 PM (17 hours ago) Mar 18
to vim...@googlegroups.com, vim_use

Le 18 mars 2026 à 14:33, Christopher <crestchr...@gmail.com> a écrit :



Vim should set it automatically; “:let $MYVIMRC” should show the value, for example. 

I don’t recommend using the system-wide vimrc for anything beyond extremely niche use cases (maybe special hardware or software settings?). The per-user vimrc is more predictable to reason about. In a single-user environment this may matter less, but still.

Igbanam Ogbuluijah

unread,
Mar 18, 2026, 7:33:23 PM (13 hours ago) Mar 18
to vim...@googlegroups.com
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to vim_use+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/vim_use/
> 70549B20-8E72-4C91-B37A-C4564E9A67DF%40gmail.com.

Hold on… the OP may have a point here.

The documentation does say something about environment variables; but I
think we are jumping into some user-global VIMRC because, quite frankly,
that's the cultural way of going this. But…!

The documentation does say there's an environment variable `VIMINIT`
which can be set as an Ex command, and this would be the first place Vim
looks to for initialization configuration. Now, the way I got this to
work is

VIMINIT="set number relativenumber" vim

I did this on a blank install of vim. Without the VIMINIT variable set,
there are no numbers.

So if you're looking to set an environment variable Vim respects on
initialization, this is it. That said, the amount of customizations
going into Vim these days is way too much for an environment variable;
plus… if you want to use the environment variable to source some file,
you might as well use a VIMRC, and use the `runtime` command for multipe
files. I think this is the reason the community has culturally favoured
the VIMRC route for customizations.

Just thought to call this out since the OP was specific about an
environment variable.


~ Igbanam

Eric Marceau

unread,
Mar 18, 2026, 8:57:10 PM (12 hours ago) Mar 18
to vim...@googlegroups.com

I did a little experiment:

$ gvim dum

  • At this point, the file 'dum' was opened with my proper default,
    ~/.vim/vimrc

$ MYVIMRC=~/.vimrc.HOLD ; export MYVIMRC
$ gvim dum

  • There are significant theme differences between the two files,
    but those differences were not reflected in the displayed theme.

$ MYVIMRC="" ; export MYVIMRC
$ unset MYVIMRC
$ VIMRC=~/.vimrc.HOLD ; export VIMRC
$ gvim dum

  • Again, those differences were not reflected in the displayed theme.

So ... are those two variables actually being used anymore?

Gary Johnson

unread,
1:13 AM (8 hours ago) 1:13 AM
to vim...@googlegroups.com
On 2026-03-18, Eric Marceau wrote:
> I did a little experiment:

[...]

I did something similar with terminal vim. I set MYVIMRC directly
in my environment and set it in VIMINIT, also in my environment,
before starting vim. In all cases, I could see both environment
variables within vim and in the environment after shelling out of
vim, but in no case was there any evidence of those variables
affecting the vimrc sourced by vim at startup. The $MYVIMRC file
did not appear in the output of :scriptnames and none of the
settings made in that file were set in vim. The only vimrc sourced
was the system vimrc, /etc/vim/vimrc on Ubuntu.

It does seem like something is broken, because from vim's
documentation, I would have expected the file specified by MYVIMRC
to have been sourced.

Regards,
Gary

Igbanam Ogbuluijah

unread,
3:01 AM (6 hours ago) 3:01 AM
to vim...@googlegroups.com
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/vim_use/20260319051249.GC10946%40phoenix.

It's not that something's broken; but there definitely is some
misconception.

What I think is going on is…

1. The top two places Vim searches for configuration are
a. a VIMINIT environment variable
b. Some VIMRC file
2. You can set an environment variable, VIMINIT; it should have Ex
commands in it.
3. If there's no VIMINIT, Vim searches some predefined paths to set
VIMRC.

I don't think VIMRC is an env variable Vim respects; I think it's an env
variable it sets based on where it finds a vimrc file.


~ Igbanam

Christopher

unread,
3:56 AM (5 hours ago) 3:56 AM
to vim_use
In my case running the command ":let $MYVIMRC" returns a invalid expression.  

Christopher

unread,
3:59 AM (5 hours ago) 3:59 AM
to vim_use
These are the paths Vim looks for configuration files.

system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim" 

In the documentation it states as mentioned above VIMINIT, also $MYVIMRC. This last part I will have to bring clarity too. 
Reply all
Reply to author
Forward
0 new messages