Search code examples
vimenvironment-variablesshmsys

Running gvim from MSYS --- how to avoid/change MSYS enviroment variables?


When I run gvim from MSYS, things go wrong during initialization. Namely, gvim can't find the initialization files that are in 'C:\Documents and Settings\username\vimfiles.

[Specifically, gvim reports the error E117: Unknown function: pathogen#infect during initialization, so it never found autoload\pathogen.vim. Doing :scriptnames also confirms that none of the setup files from vimfiles\ are run.]

I think I've debugged why it goes wrong. When you start MSYS, the MSYS shell inherits the windows enviroment variables, but changes some of them to it's custom values. C:\Documents and Settings\username is the value of $HOME in Windows, but MSYS sets it to something like C:/msys/user name. And of course, Vim uses $HOME to find the right initialization files.

I also notice set shell? has changed to something like shell=C:/msys/bin/sh instead of shell=C:\WINDOWS\system32\cmd.exe, but I hope this isn't important for fixing the initialization problem.

I need to run gvim with the normal windows environment variables. At least I need to be able to manually override a few important ones like $HOME to something I specify (i.e., I'm not concerned about my windows $HOME changing, so it's fine to use a static value).

I tried to reset $HOME manually in my vimrc, but by then it is too late.

Is there some trick to specifying $HOME early on during initialization, or as an extra command line parameter?

Alternatively, is there some trick with running commands from msys differently? I know almost nothing about how the shell C:/msys/bin/sh works, but I could conceive of some extra arguments that changes the visibile environment for the command (e.g. gvim.exe) you are typing.

---Edit---
Reposting the solution that worked (it achieves the later idea):

Instead of running gvim.exe, run the command HOME="C:\Documents and Settings\username" gvim.exe


Solution

  • In bash and other UNIX shells, you can do:

    $ HOME='/path/to/dir' gvim
    

    to temporarily set $HOME to a different value.

    I admit I'm not familiar at all with the Windows command line, but it might be worth a try.