How do I tell the hidden path to Git on Windows?
So I downloaded a hidden plugin for Vim and tried to run it on my Windows 7 machine.
I don't have a path to git.exe
in mine %PATH%
, and I don't want to add it as there might be problems.
My Git is installed in C:\Program Files (x86)\Git\
. There's a config option for the fugitive where I could point my path to git.exe
( g:fugitive_git_executable
).
I've tried several options:
-
'C:/Program Files (x86)/Git/cmd/git.exe'
-
'C:\Program Files (x86)\Git\cmd\git.exe'
-
"C:\Program Files (x86)\Git\cmd\git.exe"
-
"C:\\Program Files (x86)\\Git\\cmd\\git.exe"
But nobody works. It seems that in 1, 2, 4 there is a problem with parentheses in the path. The resulting call :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 variable $PATH
?
Or more generally: when using a command system
in Vim, how can I invoke the programs underneath 'C:\Program Files (x86)\
?
source to share
In your vimrc add something like the following:
if has('win32')
let $PATH .= ';' . 'C:/Program Files (x86)/Git/bin'
endif
This will not affect the% PATH% value outside of Vim.
Alternatively, in order to make Fugitive work as advertised, you'll have to fix it a bit. In s: Git () replace
call s:ExecuteInTree('!'.git.' '.cmd)
from
if has('win32')
call s:ExecuteInTree('!"'.git.' '.cmd.'"')
else
call s:ExecuteInTree('!'.git.' '.cmd)
endif
and then put quotes around the executable path in your vimrc:
let g:fugitive_git_executable = '"C:/Program Files (x86)/Git/bin/git"'
(see correct citation for cmd.exe for multiple arguments .)
You might want to contact the maintainer. I would be surprised if this problem did not appear earlier.
I am just changing $ PATH. Some programs require $ PATH to be set correctly. Anyway.
(Plus: @echristopherson's solution is perfectly viable, but it's annoying having to do it in the 21st century.)
source to share
The standard directory C:\Program Files (x86)
can be abbreviated to C:\Progra~2
* . Such a shorthand name is how long filenames or filenames with spaces in them were actually represented in FAT file systems (which are internally limited to filenames of eight base characters and three extension characters) from Windows 95, but it is still supported for compatibility on modern Windows using NTFS, at least in some cases like folder Program Files (x86)
.
C:\Program Files
similarly C:\Progra~1
.
* In Vimscript, backslashes must be changed to forward slashes unless they are doubled or enclosed in single quotes.
source to share
While the other two answers ( 1 , 2 ) are workarounds for this 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, this is indeed one quote followed by a double AND quote (as if it weren't too weird) I need to escape the parentheses with ^(
and ^)
.
Although the problem is solved for me, I have no idea why I should specify the path this way ...
source to share