I am using Vim with fugitive.vim plugin.

Sometimes when diffing files versus their HEAD version from Fugitive's Gstatus window, Vim shows all lines in a file as changed, when in reality only one or two lines are different (and command-line git diff shows differences correctly). Why is this happening?

  • 4
    Can you provide an example where this happens? I would think this question is more suited as an issue for fugitive? – Karl Yngve Lervåg Jul 6 '15 at 20:01
  • 3
    Is it possible that you have an issue with the end of line characters? When different people edit a file, some on windows and some on linux the end of line character are not the same and it can cause this kind of issue. – statox Jul 7 '15 at 7:15
  • @KarlYngveLervåg - thank you for your comment. I'll try to show an example. The problem is that it's difficult to reproduce the problem. I'll monitor my workflow until the problem appears, so that to have more concrete steps. – siphiuel Jul 7 '15 at 12:23
  • 1
    I run into something that sounds like this when I'm looking at many diffs, one after another. What's happening is more than 2 files are in diff mode. You can disable diff mode in all buffers with :bufdo diffoff. – tommcdo Jul 8 '15 at 3:41
  • 1
    @siphiuel I'm not sure if it's a bug or a workflow issue. From a Vim perspective, there's only ever one set of files being diffed against each other, so every buffer in diff mode is contributing to a single diff. I used to run into this a lot, but I don't anymore. Are you using the latest version of fugitive? (I'll post my answer once I'm at a full keyboard) – tommcdo Jul 8 '15 at 12:53

I think the most likely culprit is another buffer still in diff-mode. This can happen if you're looking at multiple diffs, one after another, and don't turn off diff-mode between diffs.

Disable diff-mode in irrelevant buffers

The solution is to find the offending buffer(s) and turn off diff-mode with :diffoff. If you don't want to search for it, you can use :bufdo diffoff. :bufdo visits each buffer sequentially and runs the command provided. This can have the unwanted side-effect of leaving your window displaying a different buffer after running the command.

| improve this answer | |
  • Two things: (1) diffoff! does not reset all vimdiff configs. (2) "This can have the unwanted side-effect of leaving your window displaying a different buffer after running the command" - always wondered why, and how to fix it. – fde-capu Apr 18 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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