Starting Native Windows GVim 8.2 from MinGW Git Bash

237 views
Skip to first unread message

joh...@nacs.net

unread,
May 15, 2020, 2:10:43 AM5/15/20
to Vim mailing list
I finally have a newish Windows 10 64-bit laptop for a course and, per
instructions, have installed Git Bash that uses MinGW from:
https://git-scm.com/downloads

I also have a standard native Window build of GVIm 8.2 installed under:
C:\Program File (x86)\Vim\vim82
which I believe was the default for the standard installer.

MinGW Git Bash ships with a built-in version of vim 8.2 as MinGW program, but
does not include GVim.

What I am looking to do is to start the native Windows version of GVim from a
the Git Bash prompt. Rather than change the path I hoped to use a simple bash
alias with a full path to start Windows GVim 8.2. This works except that the
bash prompt blocks as if Windows GVim is a console program and the shell is
waiting to get control back of the console. I am not entirely sure why the
shell waits for Gvim to exit. The same technique I am trying to was recommended
for MSysGit Bash and Vim 7.4 by Albert Armea at:
https://blog.albertarmea.com/post/115102365718/using-gvim-from-git-bash
The best reason I can fathom is that I read elsewhere that MinGW is a more
minimalist UNIX implementation than say Cygwin and does not implement fork()
despite providing the header file. Another possibility is that some trick
integration set up in the bundle for Vim and GVim with Git is inadvertently fighting my
attempt to use a Windows executable.

Due to how Bash is invoked by the Git Bash bundle, the easiest way for me to
configure user specific bash aliases or the like is to create two files:

~/.bash_profile is minimal and contains:

if [ -f ~/.bashrc ]; then. ~/bashrc; fi

~/.bashrc has my local alias and a bash function gvim () as follows:

gvim () { (env -u HOME -u VIM "/c/Program Files (x86)/vim/vim82/gvim.exe" "$*")& }

Another place on the Internet, I found advice to unset the HOME and VIM
environment variables local to MinGW Bash as Windows GVIm 8.2 is started, but I
converted a simple bash alias to bash function. While the env command above
would run GVim as a simple alias, the Git Bash shell blocks waiting for GVim to
exit. The bash function is needed so I can embed the env in a subshell with
parentheses and push it to the background, while still passing parameters to the
inner command line. This bash function works, starting GVim and letting the
shell continue. I do notice that this Windows GVim shows up as a process when
using the ps command at the Git Bash prompt. I am not sure if anything funny
happens, based on the order I close Git Bash and GVim.

I am not sure if this is the best approach. Another idea I saw on the Internet
suggested using the bash disown built-in command, but I was getting syntax
errors. I tried debugging with set -x in Git Bash but extra commands I did not
expect were being generated, probably due to Git integration. I decided that
this method is best, for now, but I am wondering if there are any gotchas
lurking here.

Thanks in advance for any advice.

joh...@nacs.net

unread,
May 15, 2020, 2:10:43 AM5/15/20
to Vim mailing list
Self correction: To support multiple parameters properly I should use "$@" not
"@*", which confuses Gvim, so:

~/.bashrc has my local alias and a bash function gvim () as follows:

gvim () { (env -u HOME -u VIM "/c/Program Files (x86)/vim/vim82/gvim.exe" "$@")& }

Alessandro Antonello

unread,
May 17, 2020, 8:42:51 AM5/17/20
to vim...@googlegroups.com, Vim mailing list
Hi, Joganns.

Years ago, when I was using Windows, I had the same problem with a different environment. I was using Msys2 (https://www.msys2.org/) to have e little "Linux" environment in the Windows box. My solution was alike. I built a bash script that put the GVim process in background. I never had a problem with that. But I always kept my bash session opened. In that time I was working with both Windows and Mac OSX at the same time. Then I built a single environment that worked on both machines with some customizations. I had a set of bash scripts written to do the same thing on both systems. And that made me choose Msys2 instead of GitBash.

That configuration worked for years. Today I work only on Mac OSX, but I kept the set of bash scripts and configuration as much as I could since I can get back to work on Windows any time.

Regards,

Alessandro Antonello

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200514220224.GC1444%40linux.site.
Reply all
Reply to author
Forward
0 new messages