Thursday, March 19, 2026

Re: $VIMRC over .vimrc ?

On Thu, Mar 19, 2026 at 9:45 AM Marvin Renich <mrvn@renich.org> wrote:
>
> * Christopher <crestchristopher@gmail.com> [260319 03:56]:
> > On Wednesday, March 18, 2026 at 3:48:41 PM UTC-4 Ben Knoble wrote:
> > 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
>
> and
>
> > 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) (*)
>
> This quote is missing an important word, as shown above.
>
> Perhaps that word should be "or" rather than "and", but either way the
> meaning should be clear:
>
> If VIMINIT is set, it contains ex commands, vim does not search for or
> read any rc file, and MYVIMRC is not set.
>
> If VIMINIT is not set, vim searches for a file in the places listed
> above, and sets MYVIMRC to the file that was found and read.
>
> So, MYVIMRC is not an input to vim, it is how vim communicates to the
> user which file was found and read. If MYVIMRC is exported before
> invoking vim, it is ignored completely; it is neither read nor set.
>
> The user's vimrc file _must_ be one of the files listed above, unless
> you specify the -u option. The only way to specify the vimrc file in an
> environment variable is to export VIMINT="source /path/to/your/vimrc"
> before (or while) starting vim.
>
> The strongly recommended way is to _not_ use VIMINT, and to place your
> vimrc file at ~/.vim/vimrc. VIMINIT is a compatibility holdover.
>
> ...Marvin

Indeed. This is what I meant to convey, and I apologize if my initial
reply was not clear on this point:

Vim sets MYVIMRC for the user, not the other way around!

--
D. Ben Knoble

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/CALnO6CB5mct8F%3DD%3DSsnUWeEtWyjJNuCtHY-Kk9-od76qoH_V_w%40mail.gmail.com.

Re: $VIMRC over .vimrc ?

On Thu, Mar 19, 2026 at 3:56 AM Christopher <crestchristopher@gmail.com> wrote:
>
>
>
> On Wednesday, March 18, 2026 at 3:48:41 PM UTC-4 Ben Knoble wrote:
>
>
> Le 18 mars 2026 à 14:33, Christopher <crestchr...@gmail.com> a écrit :
>
> 
>
>
>
> On Wednesday, March 18, 2026 at 11:48:15 AM UTC-4 D. Ben Knoble wrote:
>
> 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).
>
>
> 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 ?
>
>
> 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.
>
>
> In my case running the command ":let $MYVIMRC" returns a invalid expression.

Indeed. Should be ":echo $MYVIMRC" then. (I usually go with :let for…
reasons… but it apparently doesn't work here.)

--
D. Ben Knoble

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/CALnO6CCnU44Aahyt2fLVbJ59BBm-VBJOiWHL-L8REi%2BoibcW4A%40mail.gmail.com.

Re: $VIMRC over .vimrc ?

* Gary Johnson <garyjohn@spocom.com> [260319 09:04]:
> That's what I used to think, too, was that MYVIMRC was set, but not
> read, by Vim. But ":help MYVIMRC" says this:
>
> *$MYVIMRC* *$MYVIMDIR*
> 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. ...
>
> It's that "unless `$MYVIMRC was already set" that I don't understand
> the meaning of. That suggests to me if $MYVIMRC is already set, Vim
> uses that value instead of looking further for the file.
>
> In my experiments, I executed
>
> VIMINIT='let $MYVIMRC="/path/to/a/vimrc"' vim
>
> expecting Vim to source /path/to/a/vimrc, but it didn't. I'm OK
> with the actual behavior, but I don't think the documentation is
> clear.

Christian's interpretation is how I also interpret this, and it is
empirically corroborated.

Everyone seems to quote the help as saying "unless `$MYVIMRC` was
already set when using VIMINIT."

However, my vim (9.0.0135 which is several years old) has the word
"and", and there are no backticks around $MYVIMRC: "unless $MYVIMRC was
already set and when using VIMINIT."

Perhaps the word "and" was inadvertently dropped when editing this
(perhaps to add the backticks)?

...Marvin

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/abwEpIDJzvUe/ou1%40basil.wdw.

Re: $VIMRC over .vimrc ?

* Christopher <crestchristopher@gmail.com> [260319 03:56]:
> On Wednesday, March 18, 2026 at 3:48:41 PM UTC-4 Ben Knoble wrote:
> 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

and

> 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) (*)

This quote is missing an important word, as shown above.

Perhaps that word should be "or" rather than "and", but either way the
meaning should be clear:

If VIMINIT is set, it contains ex commands, vim does not search for or
read any rc file, and MYVIMRC is not set.

If VIMINIT is not set, vim searches for a file in the places listed
above, and sets MYVIMRC to the file that was found and read.

So, MYVIMRC is not an input to vim, it is how vim communicates to the
user which file was found and read. If MYVIMRC is exported before
invoking vim, it is ignored completely; it is neither read nor set.

The user's vimrc file _must_ be one of the files listed above, unless
you specify the -u option. The only way to specify the vimrc file in an
environment variable is to export VIMINT="source /path/to/your/vimrc"
before (or while) starting vim.

The strongly recommended way is to _not_ use VIMINT, and to place your
vimrc file at ~/.vim/vimrc. VIMINIT is a compatibility holdover.

...Marvin

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/abv92rfq%2BH/vlJUq%40basil.wdw.

Re: $VIMRC over .vimrc ?

On Do, 19 Mär 2026, Gary Johnson wrote:

> That's what I used to think, too, was that MYVIMRC was set, but not
> read, by Vim. But ":help MYVIMRC" says this:
>
> *$MYVIMRC* *$MYVIMDIR*
> 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. ...
>
> It's that "unless `$MYVIMRC was already set" that I don't understand
> the meaning of. That suggests to me if $MYVIMRC is already set, Vim
> uses that value instead of looking further for the file.
>
> In my experiments, I executed
>
> VIMINIT='let $MYVIMRC="/path/to/a/vimrc"' vim
>
> expecting Vim to source /path/to/a/vimrc, but it didn't. I'm OK
> with the actual behavior, but I don't think the documentation is
> clear.

I understand this that Vim won't overwrite your $MYVIMRC environment
variable, if for whatever reason it already exists when starting Vim. It
doesn't mean it will use this value of this environment variable as an
init file that it should actually read.

Thanks,
Christian
--
God made the world in six days, and was arrested on the seventh.

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/abv3hXDtGRarmEsp%40256bit.org.

Re: $VIMRC over .vimrc ?

On 2026-03-19, Igbanam Ogbuluijah wrote:
> On Wed, Mar 18, 2026 at 10:12:49PM +0000, Gary Johnson wrote:
> > 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.

> 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.

That's what I used to think, too, was that MYVIMRC was set, but not
read, by Vim. But ":help MYVIMRC" says this:

*$MYVIMRC* *$MYVIMDIR*
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. ...

It's that "unless `$MYVIMRC was already set" that I don't understand
the meaning of. That suggests to me if $MYVIMRC is already set, Vim
uses that value instead of looking further for the file.

In my experiments, I executed

VIMINIT='let $MYVIMRC="/path/to/a/vimrc"' vim

expecting Vim to source /path/to/a/vimrc, but it didn't. I'm OK
with the actual behavior, but I don't think the documentation is
clear.

Regards,
Gary

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/20260319130425.GD10946%40phoenix.

Re: $VIMRC over .vimrc ?



On Thursday, March 19, 2026 at 3:01:12 AM UTC-4 Igbanam Ogbuluijah wrote:
On Wed, Mar 18, 2026 at 10:12:49PM +0000, Gary Johnson wrote:
> 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
>
> --
> --
> 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

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. 

--
--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/e84dc9e9-0831-4de2-a5d2-33aed9dbed5dn%40googlegroups.com.