I want to use vim to view the output of git diff
.
I am running Windows 8 and I have vim 7.4 installed. I have, for convenience, created an environment variable VIMDIR set to Vim's install directory (set VIMDIR=C:\Program Files (x86)\Vim\vim74
), and added this directory to the %PATH%.
Vim comes with a %VIMDIR%\macros\less.bat
script, which can be used as a pager, so that less.bat file.txt
or dir | less.bat
will display the output in a vim-based pager. I use this regularly, and it works fine. I'd also like to use vim, rather than Git's less.exe, as git's pager, so that it runs when I do git diff
, but I'm running into problems.
I have tried using vim's less.bat
batch file
If I set %GIT_PAGER%
to %VIMDIR%\macros\less.bat
and do a git diff
, I get an error message:
C:\Program Files (x86)\Vim\vim74\macros\less.bat: -c: line 0: syntax error near unexpected token `('
C:\Program Files (x86)\Vim\vim74\macros\less.bat: -c: line 0: `C:\Program Files (x86)\Vim\vim74\macros\less.bat'
I believe this is because git is an MSYS program, meaning it can't handle Windows-style C:\whatever
paths.
I have also tried invoking vim's less macro directly
So that doesn't work. The next thing I tried was to examine less.bat
and set %GIT_PAGER%
to something based on that file. In that file, I see this line, which instructs vim to read from stdin:
vim --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" -
I set %GIT_PAGER%
to a modified version of this that uses MSYS-style paths:
set GIT_PAGER="/c/Program Files (x86)/Vim/vim74/vim.exe" --cmd "let no_plugin_maps = 1" -c "runtime! macros/less.vim" -
That does successfully launch vim! But there is still a problem: colors aren't working and there are escape characters littered all over the screen. Note that normally, syntax highlighting works just fine. If I run these commands, it will display the diff file I generated with color:
git diff > test.diff
less.bat test.diff
However, if I simply call git diff
and have it use %GIT_PAGER%
to display the diff for me in the console, it shows me this:
What else can I try?
I'm not sure what else to try. Is anyone else using vim to view git diffs on Windows? How are you doing it?
Thanks for any help.
git difftool
, but I want to use it withgit diff
.git difftool
is useful, but when I use it, I tend to use kdiff3. What I want to do right now is replace the pager used bygit diff
.git diff --no-color
or look up vimpager but I don't know if that works on windows.