0

I thought that setting the environment variable MYVIMRC would make them use that as its rc file on startup, saving me from passing -u every time.

It's set correctly

:echo $MYVIMRC

shows /c/Users/theonlygusti/My Project/.vimrc

But none of the settings in the file seem to be run.

The file is just two lines rn:

set nocompatible
set expandtab tabstop=4 softtabstop=4 shiftwidth=4

But vim still uses 8-space-wide tabs instead of 4 spaces

3
  • 2
    :help MYVIMRC – D. Ben Knoble Jul 15 '20 at 13:28
  • Technically, it's :help $MYVIMRC but, yes. :) – B Layer Jul 15 '20 at 13:36
  • I think you may be interested in VIMINIT env variable – Jorengarenar Jul 15 '20 at 19:19
2

Setting the MYVIMRC environment variable does not affect what vimrc file is used for startup. I think you may have misinterpreted this bit of documentation:

The $MYVIMRC environment variable is set to the file that was first found, unless $MYVIMRC was already set [...]

This does not mean that Vim will use the file found in the MYVIMC environment variable if it is set. It just means it won't overwrite the environment variable with the location of the file it used if the environment variable already exists.

To manually specify which vimrc file to use without using -u, instead you can use the VIMINIT environment variable to source the file you want to use:

export VIMINIT='source /c/Users/theonlygusti/My\ Project/.vimrc'

As an alternative, you could instead use an alias so you still use the -u mechanism to specify the vimrc file, but don't have to type it out every time. e.g. in bash:

alias vim="vim -u /c/Users/theonlygusti/My\ Project/.vimrc"
0

Try add this line to the end of your .vimrc file so you have:

set nocompatible
set expandtab tabstop=4 softtabstop=4 shiftwidth=4
echom "My file was sourced at ".expand("%")

Then close and open vim again. If you dont see that message printing what file location was sourced then its running and its a problem with the settings not the finding of $MYVIMRC.

Within vim try :e $MYVIMRC and see the full path of the file it opens up. If it's blank, its loading a different file to what you expect. You can press 2<C-g> i.e. 2 then CTRL+g to see what file it opened. Is that the file you expected, if not see @D. Ben Knoble's comments about :help $MYVIMRC.

2
  • :e $MYVIMRC breaks at the first space in its path – theonlygusti Jul 15 '20 at 16:37
  • What is the result of :echo shellescape($MYVIMRC)? The space should be escaped with \ – run_the_race Jul 15 '20 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.