1

I share most of the configuration for vim and neovim between them and I set $VIM like this…

if has('unix')
  let $VIM = "$HOME/.config/vim"
elseif has('win32')
  let $VIM = "$HOME/vimfiles"
endif

…which makes it possible to set file paths elsewhere throughout the configuration for both Linux and Windows without using conditional statements (in most cases, but not all).

According to :h $VIM this is fine and pretty much the intended purpose of the variable. So why does :checkhealth give this error message in the new version of nvim (0.8.0)?

## Configuration                                                                                                                                                                                                                                                                                                                                                  
  - ERROR: $VIM is invalid: $HOME/.config/vim
2
  • 1
    Am I right in thinking that the only reason you need $VIM set that way is because you reference it in your personal config files? Would just using a different variable work for you? :let NOTVIM = "$HOME/vimfiles"
    – Rich
    Oct 7, 2022 at 10:15
  • @Rich That's what I have done in the end. I defined $VIMFILES. Cheers.
    – paradroid
    Nov 1, 2022 at 3:51

1 Answer 1

2

The health of $VIM variable is checked with the following logic1:

" If $VIM is empty we don't care. Else make sure it is valid.
if !empty($VIM) && !filereadable($VIM.'/runtime/doc/nvim.txt')
  let ok = v:false
  call health#report_error('$VIM is invalid: '.$VIM)
endif

You must not have $HOME/.config/vim/runtime/doc/nvim.txt, or if you have it, you must not have read-permission for that file (the latter case is highly unlikely). That's the reason for the error you're facing.

## Configuration
  - ERROR: $VIM is invalid: $HOME/.config/vim

The logic above tells us that $VIM is expected to point to the directory where vim's system files reside. As for the reason behind, a look at the nvim source code reveals that the environment variable $VIM is accessed only twice in the who codebase.

  • To set system vimrc file2
  • When checking for $VIMRUNTIME and finding it nil3.

($VIM is also handled when you do :echo $VIM, but that comes later in the execution time, and by then both $VIM and $VIMRUNTIME and most if not all variables have been set already.)

So, if we've got our own vimrc file (which means vim won't need the system vimrc) and we've set $VIMRUNTIME properly (pointing to where vim's system runtime files exist), then the value of $VIM should invite no complication. We can simply ignore the error put out by :checkhealth.

BUT if we've not set $VIMRUNTIME and have set $VIM to an arbitrary location, then the value of $VIMRUNTIME will be set wrongly at startup. See the stacktrace at the startup on a breakpoint at vim_getenv3.

gdb> where
#0  vim_getenv (name=0x7ff6f47638b9 <__func__.2+969> "VIMRUNTIME") at E:/projects/neovim/master/src/nvim/os/env.c:901
#1  0x00007ff6f44d62da in runtimepath_default (clean_arg=false) at E:/projects/neovim/master/src/nvim/runtime.c:1511
#2  0x00007ff6f446720f in set_init_1 (clean_arg=false) at E:/projects/neovim/master/src/nvim/option.c:316
#3  0x00007ff6f43ea95e in early_init (paramp=0x850f1ff530) at E:/projects/neovim/master/src/nvim/main.c:201
#4  0x00007ff6f43eab4d in wmain (argc=1, argv_w=0x22b48aa44b0) at E:/projects/neovim/master/src/nvim/main.c:257
#5  0x00007ff6f42513da in __tmainCRTStartup () at C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:326
#6  0x00007ff6f4251506 in mainCRTStartup () at C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:206

It's this case that will cause problems such as vim not finding syntax file ($VIMRUNTIME/syntax/syntax.vim), etc. Otherwise, we can use $VIM as our own personal environment variable.


5
  • @Rich I still don't understand. Could you explain what you misread? Or maybe write an answer explaining it.
    – 3N4N
    Oct 7, 2022 at 9:53
  • 1
    I read this: "The environment variable "$VIM" is used to locate various user files for Vim, such as the user startup script ".vimrc". [...] 1. The value defined by the $VIM environment variable. You can use this to make Vim look in a specific directory for its support files. setenv VIM /home/paul/vim" (emphasis mine) ...and inferred that you were supposed to be able to use $VIM like how the OP wants to. Having re-read it, I think it's intended use is a bit more subtle and specialised than that, although I'm still figuring out precisely what that intended use is.
    – Rich
    Oct 7, 2022 at 9:58
  • 1
    If I ever figure out what that is I'll write a frame challenge answer to this question explaining some other ways of achieving the goal (or you can, if the vim_use peeps clarify!)
    – Rich
    Oct 7, 2022 at 9:59
  • 1
    @Rich I have a feeling, that instead of a user startup script it should mean the system startup script Oct 7, 2022 at 12:07
  • @Rich and ChristianBrabandt, I added the explanation for $VIM. Please see if makes sense.
    – 3N4N
    Oct 9, 2022 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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