I'm trying to understand how vimdiff work.
Here I tried to diff two simple files. The 1st:
abcdefghijklmnopqrstuvwxyz
foo
abcdefghijklmnopqrstuvwxyz iii
bar
The 2nd:
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
Here is result from diffmerge utility:
And here is result from vim:
Note that vim doesn't see the similarity between abc...xyz
and abc...xyz iii
lines and doesn't arrange them visually on one line.
Is there some settings to improve vimdiff in such cases?
As pointed out in the comments, vim uses the external utility diff
which doesn't do word diffs nor can it find moved-and-modified lines.
Even resorting to diffexpr is unsatisfactory, since Vim expects the data from the external utility to be in a "ed" style diff. This rules out using alternative diff utilities that make word or even char based diffs, like diffmerge.
The workaround some industrious plugin authors have cooked up is to wrap the results of these more sophisticated diffs and translate their output into the "ed" style diff for Vim to consume. I know of two such plugins which take this approach: chardiff
and vim-diff-enhanced
. Both give you word diffs. In addition, Vim-diff-enhanced allows you to toggle between various diff algorithms (myers, histogram, patience) so one may decide which diff produces the best result on a case by case basis.
I use vim-diff-enhanced, and it is better than the default diff but still not great. (note: it depends on git.) For example, I tried your test, as described in the question, and it did NOT recognize that lines 5 and 3 were the same (even with :set diffopt+=iwhite). Although, if I removed or added something to line 2 of your first sample file, then vimdiff matched the results you obtained from diffmerge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With