8

I use msysgit and I'd like to have gvim as my git editor.

I use cygwin bash instead of git bash.

Running

$ /cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe 

starts gvim. But if I set this as git editor:

$ git config core.editor /cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe

and run commit I get:

/cygdrive/c/Program Files (x86)/Vim/vim73/gvim.exe: -c: line 0: syntax error near unexpected token `('

I then add escaped backslashes where needed:

$ git config core.editor /cygdrive/c/Program\\\ Files\\\ \\\(x86\\\)/Vim/vim73/gvim.exe

This still gives me:

/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe: /cygdrive/c/Program Files (x86)/Vim/vim73/gvim.exe: No such file or directory
error: cannot run /cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe: No such file or directory
error: There was a problem with the editor '/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe'.

The thing is, I can copy the string from after "cannot run" and paste it and it runs. I guess it could be caused by either the spaces or the parentheses in Program Files (x86) (what on earth were they thinking?).

Since cygwin seems to handle it ok I figured I could create a symlink in say /usr/local/bin, as it is in my $PATH and set

$ git config core.editor /usr/local/bin/gvim

I confirm that /usr/local/bin/gvim starts gvim. Still, running a commit gives me:

error: cannot spawn /usr/local/bin/gvim.exe: No such file or directory
error: There was a problem with the editor '/usr/local/bin/gvim.exe'.

Unsetting core.editor and trying

$ export GIT_EDITOR=/usr/local/bin/gvim.exe 

gives me the same error.

This SO answer suggest that I use a script to open the editor.

I remove the soft link gvim.exe from /usr/local/bin and

$ cat > gvim
#!/bin/sh
/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe

$ chmod u+x gvim

I test run the script, it works, gvim starts.

$ gvim

Unfortunately when I run commit I get an error

$ git commit
error: cannot spawn /usr/local/bin/gvim: No such file or directory
error: There was a problem with the editor '/usr/local/bin/gvim'.

What can I do to get to use gVim as git editor? Has anybody tried it? Have I made mistakes? I must admit to being a novice when it comes to linux.

5
  • Have you tried using the cygwin vi instead? Have you tried the command which gvim? Sep 14, 2011 at 18:32
  • which gvim outputs /usr/local/bin/gvim, only when the soft link or the script is there. I should probably state clearer my reason for wanting gVim. I use it daily and have set it up as I want it. If I use any other I will have two editors settings to maintain.
    – johnny
    Sep 14, 2011 at 19:13
  • You may want to consider using symlinks or a repo for your rc files. Sep 14, 2011 at 19:23
  • You may have to do this with a batch file rather than a cygwin shell script. Also, beware of HOME environmental variable conflicts between Windows based gVim and what cgywin will set $HOME as.
    – Heptite
    Sep 14, 2011 at 19:36
  • @Heptite I tried to create a bat file for it too. No luck. I get the cannot spawn error mentioned in my question. And you're right about the conflicts. I have not had conflicts with gvim but with git. git config --global under cygwin saves to cygwin home, same under msysgit saves to windows home.
    – johnny
    Sep 15, 2011 at 7:44

3 Answers 3

6

git config seems to remove one level of quotes, so add another. This works for me (with another editor):

git config core.editor "\"c:/Program Files (x86)/Vim/vim73/gvim.exe\""

(Note the escaped quotes surrounding the path, this causes the editor started whenever you do e.g. git commit to be "c:/Program Files (x86)/Vim/vim73/gvim.exe", so with quotes that tell the bash shell to not try to interpret the () as whatever it thinks this means.)

0

When working with spaces in pathnames, it's generally a good idea to encapsulate them in quotes. This will solve your problem:

git config core.editor "/cygdrive/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe"
3
  • Unfortunately not. /cygdrive/c/Program\ Files\ (x86)/Vim/vim73/gvim.exe: /cygdrive/c/Program Files (x86)/Vim/vim73/gvim.exe: No such file or directory error: cannot run /cygdrive/c/Program\ Files\ (x86)/Vim/vim73/gvim.exe: No such file or directory error: There was a problem with the editor '/cygdrive/c/Program\ Files\ (x86)/Vim/vim73/gvim.exe'. The path is correct though, /cygdrive/c/Program\ Files\ (x86)/Vim/vim73/gvim.exe
    – johnny
    Sep 15, 2011 at 6:28
  • I'm sorry, I tried it with cygwin but I used the cygwin-git package. Could you tell me how you connected cygwin and msysgit? Sep 15, 2011 at 6:50
  • I installed msysgit and used git bash for a long time. I don't remember exactly why I started using cygwin, but what I did (do) is I add the path to Git (/cygdrive/c/Program Files (x86)/Git/bin) to my cygwin $PATH.
    – johnny
    Sep 15, 2011 at 7:52
0
#!/bin/dash -e
if [ "${1#/}" != "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=$1
fi
exec gvim ${k+"$k"}
  1. If no path, pass no path

  2. If path is empty, pass empty path

  3. If path is relative, pass as is

  4. If path is absolute, convert to Windows format

Then I set these variables:

export EDITOR=gvim.sh
export GIT_EDITOR='dash /usr/local/bin/gvim.sh'
  1. EDITOR allows script to work with Git

  2. GIT_EDITOR allows script to work with Hub commands

Source

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .