I want to use vim to view the output of
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
%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
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" -
%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.