I ran into a problem with cursor color being reset when using gruvbox color scheme on both Linux and Windows. During debugging I discovered that the color scheme is reloaded if vimrc is located in $VIM. In my test case I have only two user files: vimrc and $VIM/vimfiles/colors/kgb.vim (the rest is the standard vim installation). I set VIMINIT to "source $VIM\vimrc" to control which vimrc is loaded.
set|grep VIM
MYVIMRC=C:\Users\Public\Vim\vimrc
VIM=C:\Users\Public\Vim
VIMINIT=source C:\Users\Public\Vim\vimrc
VIMRUNTIME=E:\Vim\vim81
cd %VIM%
find vim*
vimfiles
vimfiles/colors
vimfiles/colors/kgb.vim
vimrc
cat vimrc
echomsg "Before colo: " . execute("colo")
color kgb
echomsg "After colo: " . execute("colo")
cat vimfiles/colors/kgb.vim
echomsg "Executing script: " . expand("<sfile>")
let g:colors_name="kgb"
gvim.exe
:mes
Before colo: ^@default
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
After colo: ^@kgb
Before colo: ^@kgb
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
After colo: ^@kgb
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
NOTE: The above output shows that vimrc is loaded twice and colorscheme is loaded three times in Windows (only two times on Linux). If VIMINIT is not set and vimrc is located in $VIM, then vimrc is loaded only once, but colorsheme is still loaded twice on both Windows and Linux.
:scr
1: C:\Users\Public\Vim\vimrc
2: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
3: E:\Vim\vim81\plugin\getscriptPlugin.vim
4: E:\Vim\vim81\plugin\gzip.vim
5: E:\Vim\vim81\plugin\logiPat.vim
6: E:\Vim\vim81\plugin\manpager.vim
7: E:\Vim\vim81\plugin\matchparen.vim
8: E:\Vim\vim81\plugin\netrwPlugin.vim
9: E:\Vim\vim81\plugin\rrhelper.vim
10: E:\Vim\vim81\plugin\spellfile.vim
11: E:\Vim\vim81\plugin\tarPlugin.vim
12: E:\Vim\vim81\plugin\tohtml.vim
13: E:\Vim\vim81\plugin\vimballPlugin.vim
14: E:\Vim\vim81\plugin\zipPlugin.vim
15: E:\Vim\vim81\menu.vim
16: E:\Vim\vim81\autoload\paste.vim
:quit
Error:
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
If I move vimrc under vimfiles and set VIMINIT="source $VIM\vimfiles\vimrc" the scheme is loaded only once:
set|grep VIM
MYVIMRC=C:\Users\Public\Vim\vimfiles\vimrc
VIM=C:\Users\Public\Vim
VIMINIT=source C:\Users\Public\Vim\vimfiles\vimrc
VIMRUNTIME=E:\Vim\vim81
gvim.exe
:mes
Before colo: ^@default
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
After colo: ^@kgb
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
:quit
Error:
Executing script: C:\Users\Public\Vim\vimfiles\colors\kgb.vim
Any explanation why this is happening?
$HOME
is searched first anyway. So what's the reason to set$VIM
after all?