Question

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

Was it helpful?

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.

OTHER TIPS

I believe you can define $HOME just like any other environment variable.
Try adding this to the start of your .vimrc.

let $HOME="C:\Documents and Settings\username"

I had a similar issue when running Cygwin (which is similar to MSYS).

The easiest solution for me was to simply set the HOME environment variable to an empty string. Otherwise, the Cygwin HOME value would be appended to the Windows USERPROFILE in GVim and it would fail to start correctly. Not explicitly setting the full path of the HOME means that I can use the same start-up files on different systems where the USERNAME may not be the same.

Likewise, the SHELL environment variable should not be inherited from Cygwin Bash. This results in errors when running shell or external programs via !. Again, I set this to be an empty variable since Vim is smart enough to figure out what it should be.

In my .bashrc, I set the following alias for running Windows gvim which starts GVim with the HOME and SHELL variables set to an empty string – just for that command.

gvim="/cygdrive/c/Program Files (x86)/Vim/vim74/gvim"
if [ -x "$gvim" ]; then
  alias gvim="HOME= SHELL= \"$gvim\""
fi
unset gvim

I achieved this by making a windows symbol link (Win 7 or higher).

Via a symbol link, you can even make vim and gvim to use the same configuration and plugin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top