4

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?

9
  • 4
    Can you provide an example where this happens? I would think this question is more suited as an issue for fugitive? Commented Jul 6, 2015 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
    Commented Jul 7, 2015 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.
    – vitvly
    Commented Jul 7, 2015 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
    Commented Jul 8, 2015 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
    Commented Jul 8, 2015 at 12:53

1 Answer 1

8

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.

1
  • 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
    Commented Apr 18, 2020 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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