Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
This article was written for you. – romainl Jul 10 '14 at 19:29
That article is about use with git difftool, but I want to use it with git 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 by git diff. – Micah R Ledbetter Jul 10 '14 at 20:20
Oh right, why exactly do you want to use Vim instead of less? – romainl Jul 10 '14 at 20:30
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 Jul 10 '14 at 20:35
Try git diff --no-color or look up vimpager but I don't know if that works on windows. – FDinoff Jul 11 '14 at 4:11
up vote 4 down vote accepted

The remaining problem is that git diff still highlights the diff output with colors (as ANSI escape sequences), and expects the pager (i.e. Vim) to display that correctly. But Vim has its own syntax highlighting (also for diffs), and doesn't understand the sequences, so they show up as ugly ^[[m. You have two options:

  1. Disable Git's diff highlighting (command-line argument --no-color, but you can also unconfigure that via git config). Now you need to ensure that Vim uses the correct filetype (:set filetype=diff; you can pass that on the command-line via -c {cmd}).

  2. Make Vim understand and highlight the ANSI escape sequences; the AnsiEsc.vim plugin can do this.

I'd recommend the first approach.

share|improve this answer
Ahh, that makes perfect sense now that you say it! Thank you! (For the record, I did end up taking your suggestion and chose the first approach.) – Micah R Ledbetter Jul 11 '14 at 17:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.