7
3
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.
This article was written for you. – romainl – 2014-07-10T19:29:48.440
That article is about use with
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
. – Micah R Ledbetter – 2014-07-10T20:20:12.583Oh right, why exactly do you want to use Vim instead of less? – romainl – 2014-07-10T20:30:55.357
The version of less.exe that comes with git clears my scrollback buffer when I use Powershell with ConEmu; vim's less macro doesn't do that. – Micah R Ledbetter – 2014-07-10T20:35:41.370
1Try
git diff --no-color
or look up vimpager but I don't know if that works on windows. – FDinoff – 2014-07-11T04:11:17.5471Nice question! You have a problem description, what you've tried, what didn't work when you tried it, why alternate solutions won't work, and even included screenshots for clarity. AND you clearly marked where something is speculation on your part. +1 for all that! – Ben – 2014-07-12T01:05:01.333