How to invoke Windows' gvim in a Windows environment from within Cygwin?
When I give a gvim
command in Cygwin, I want it to invoke the gvim I've installed in my Windows.
I tried writing a function in my .bashrc called gvim
that invokes the gvim.exe in my Program Files folder, using cygpath
and all that, but the problem is, that apparently invokes the gvim with Cygwin's environment; :echo $HOME
prints C:\cygwin\home\Sundar instead of C:\Users\Sundar, and :diffsplit
reports failures in creating temporary files which I assume are related to the same. So, how can I invoke gvim from Cygwin but make it as if it was invoked through, say, the Start menu?
I tried changing the command to pass the gvim path to cmd.exe /c
, but that too somehow sets up the same environment. What do I need to do to make this work?
Solution 1:
gVim.exe looks for a HOME
variable when it is run. In your case, the Cygwin environment has its own HOME
var set, so it is using that.
You could change the HOME
value in your environment, but that could affect other applications. Then again, you might want that. In case you don't want that and assuming your Cygwin shell is using the Bash shell, since you've already suggested in your question that you're looking to create an alias or function, I would recommend setting the var only for that command instance, which Bash allows you to do by just setting it right before the command separated by a space...
VAR=abc command
The above runs command
as if VAR
was set to abc
, regardless of what it might actually be. Thus...
alias gvim='HOME=/cygdrive/c/Users/Sundar /path/to/gvim.exe'
... or...
gvim() { HOME=/cygdrive/c/Users/Sundar /path/to/gvim.exe $1; }
...would allow you to run the gVim executable with the HOME
var set to your preferred path, without otherwise disturbing your Cygwin environment.