Git fails to launch Vim in Cygwin

cygwin;gitvimvimdiff

I have Git working with Vim in a Powershell environment on my work laptop (Windows 7). It pops up Vim when I commit or use my git vimdiff alias.

I have attempted the same setup under Cygwin (being a Unix guy at heart) but when I type git commit or git vimdiff, Vim does not pop up; seemingly, though, Git is waiting on Vim because the action never completes until I CtrlC (after which it takes a minute or so to recover). I can commit with inline commit messages (git commit -m "I would rather type this in Vim") and I can launch Vim/Vimdiff from the terminal with vim and vimdiff. I have my editor set to Vim in multiple places:

$ echo $EDITOR
vim
$ git config --get core.editor
vim

(Initially, I had not explicitly set it in Git, but only in the environment variable, and still had the same problem.)

It appears that I am running Windows Git in Cygwin. Being new to Cygwin, I did not realize this when I first asked the question. I could see how that might cause problems, but after playing around I have not yet been able to fix it.

Has anyone seen this problem before? Any idea how to fix it?

Best Answer

Thanks to @skarface, I have solved this problem with respect to commiting. First, as I mentioned in the edit to the question, it turned out I was not running Cygwin Git in Cygwin but actual Windows Git. Thus the integration issue makes sense: it is not finding vim or vimdiff.

I had to do:

git config --global core.editor C:/cygwin/bin/vim.exe

I am not sure why the above worked, since:

$ which vim
/usr/bin/vim

but:

$ ls C:/cygwin/usr/bin
ls: cannot access C:/cygwin/usr/bin: No such file or directory

So not sure exactly why that is the path that worked, but it did.


I have now solved it with respect to diffing as well. I had to:

$ git config --global diff.tool vimdiff
$ git config --global difftool.vimdiff.cmd  'C:/cygwin/bin/vim.exe -d "$LOCAL" "$REMOTE"'

This allowed me to start Vimdiff with Git, but there were still some hickups. I could view the files, but the tool itself was failing to diff, giving these errors:

diff errors

It looks like what was happening here is that Git was somehow screwing with Vim's shell option. In my .vimrc, I put this command:

set shell=bash

and now everything works smoothly.

Related Question