8

vimdiff has an annoying habit of displaying two almost-completely-different lines as the same partially-different line just because they share a character in common at the beginning or end.

For example:

foo.txt contains: The quick brown fox jumps over the lazy dog. bar.txt contains: This is a completely different line.

vimdiff foo.txt bar.txt displays these two lines side-by-side with everything but the Th at the beginning highlighted.

Is there a way to disable this behaviour and just display different lines as being different lines?

  • Annoying indeed. Although I am not familiar with an answer to that, what I do as a workaround is add some controlled lines at various places in both sides, then :diffupdate, so vimdiff "syncs" the locations of the two files with the added "anchor" matches. – ysap Jul 22 '17 at 15:41
1

Yes it is possible. Type the command

:hi! link DiffChange DiffText
  • 1
    You can also just do :hi! link DiffChange DiffText. But isn't this solution just papering over the problem? – Ingo Karkat Jan 5 '15 at 11:09
  • @Ingo Karkat: Nice I only tried :hi link that prints E414, not :hi! link. This is all about highlihghting changes between two files. The fact that, for vim, the section to highlight with the desired color is a line and not the part of a line, is not relevant to the user. – user2987828 Jan 5 '15 at 11:44
  • I interpreted the problem in a way that there should be a threshold for "similarity", so that 99%-differing lines should not be marked as changed, but 10%-differing still are. This is what your proposed solution doesn't achieve (and which indeed would require source code changes). – Ingo Karkat Jan 5 '15 at 11:51
  • @Ingo Karkat: The current question states just display different lines as being different lines?. I didn't check the question version that you answered though. I would personnaly like the inverse, to wit, with something like diffc does: highligh added an suppressed characters. And for that I also need to patch vim. – user2987828 Jan 5 '15 at 12:34
0

No, this is part of Vim's internal algorithm to further divide the line changes reported by the external diff tool.

It would be nice if this could be influenced through an option, but there current is none. You'd have to modify Vim's source code and compile your own special version. How about writing a patch and submitting it to the vim_dev mailing list?!

  • 1
    "No" and "have to modify Vim's source code" are wrong. See my answer. – user2987828 Jan 5 '15 at 10:54
0

I think it depends on the "diff" command output.

If you run ":help diff-options", you can see an example of the diff format that Vim expects:

    1a2
    > bbb
    4d4
    < 111
    7c7
    < GGG
    ---
    > ggg

The "1a2" item appends the line "bbb".
The "4d4" item deletes the line "111".
The '7c7" item replaces the line "GGG" with "ggg".

For the replaces (e.g. 7c7), I think vimdiff will put them in side-by-side and color it hl-DiffChange (e.g. purple in my default setting), and then highlight the different text in the line by hl-DiffText (e.g. red in my default setting).

For example, if I vimdiff these two files:

File 1:

This is common1
This is common2
11111111111111122222222222222222222222222222222222222
This is common4
This is common5

File 2:

This is common1
This is common2
This is a completely different line
This is common4
This is common5

Although the 3rd line of two files is completely different, vimdiff still put them side-by-side.

A hacky solution may be using a modify external diff program that produce the format you want.

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.