8

So I downloaded the fugitive plugin for Vim and try to get it running on my Windows 7 machine.

I don't have the path to git.exe in my %PATH% and I don't want to add it since issues could arise doing such.

My Git is installed at C:\Program Files (x86)\Git\. There's a config option for fugitive where I could tell my path to git.exe (g:fugitive_git_executable).

I've tried several flavours:

  1. 'C:/Program Files (x86)/Git/cmd/git.exe'
  2. 'C:\Program Files (x86)\Git\cmd\git.exe'
  3. "C:\Program Files (x86)\Git\cmd\git.exe"
  4. "C:\\Program Files (x86)\\Git\\cmd\\git.exe"

But none is working. Seems like in 1, 2, 4, there's a problem with the brackets in the path. The resulting call of :Git status is

C:\WINDOWS\system32\cmd.exe /c (C:\Program Files ^(x86^)\Git\cmd\git.exe status)

and the cmd window complains that "\Git\cmd\git.exe" could not be processed (translated from German).

How do I specify the path to git.exe so that I don't have to expand my $PATH variable?

Or more general: when using the system command in Vim, how do I call programs that are located under 'C:\Program Files (x86)\?

eckes
  • 64,417
  • 29
  • 168
  • 201

3 Answers3

6

In your vimrc, add something like the following:

if has('win32')
    let $PATH .= ';' . 'C:/Program Files (x86)/Git/bin'
endif

This won't affect the value of %PATH% outside of Vim.

Alternatively, to get Fugitive to work as advertised, you'll have to patch it a bit. In s:Git() replace

call s:ExecuteInTree('!'.git.' '.cmd)

with

if has('win32')
    call s:ExecuteInTree('!"'.git.' '.cmd.'"')
else
    call s:ExecuteInTree('!'.git.' '.cmd)
endif

and then put quotation marks around the path to the executable in your vimrc:

let g:fugitive_git_executable = '"C:/Program Files (x86)/Git/bin/git"'

(See correct quoting for cmd.exe for multiple arguments.)

You might want to get in touch with the maintainer. I'd be surprised if this issue hasn't cropped up before.

I just modify $PATH. Some programs require $PATH to be set correctly, anyhow.

(Plus: @echristopherson's solution is perfectly viable, but it's annoying to have to resort to that in the 21st Century.)

Community
  • 1
  • 1
1983
  • 5,882
  • 2
  • 27
  • 39
  • +1, good point. However, there MUST be a way how I could specify the path correctly. As well as the answer of echristopherson, this is a workaround. – eckes Sep 18 '14 at 10:48
  • Ended up using this way because it's pain-free. Accepting. – eckes Feb 20 '15 at 07:56
1

The standard directory C:\Program Files (x86) can be abbreviated to C:\Progra~2*. This kind of shortened name is how long filenames or filenames with spaces in them were actually represented on FAT filesystems (which internally are restricted to filenames of eight base characters and three extension characters) from Windows 95 on, but it's still supported for compatibility in modern Windows systems using NTFS, at least in specific cases like the Program Files (x86) folder.

C:\Program Files is, similarly, C:\Progra~1.

* In Vimscript the backslashes should be changed to slashes unless they are either doubled up or enclosed in single quotes.

echristopherson
  • 6,974
  • 2
  • 21
  • 31
  • Good point about slashes vs backslashes. Usually if you use slashes as a path separator in Vim, it will just do the right thing. – 1983 Sep 19 '14 at 08:33
1

While the other two answers (1,2) provide workarounds for the problem, playing around showed me that I need to specify the path this way:

let g:fugitive_git_executable = '"C:\\Program Files ^(x86^)\\Git\\cmd\\git.exe"'

Yes, it's really a single quote followed by a double quote AND (as if this wouldn't be odd enough) I need to escape the parentheses with ^( and ^).

Although the issue is solved for me, I got no clue why I have to specify the path this way...

Community
  • 1
  • 1
eckes
  • 64,417
  • 29
  • 168
  • 201