Question

Is there any way to set vimdiff's diff strategy to be the patience algorithm? It's built into git and seems to be much better than a normal diff.

For reference:

Was it helpful?

Solution 2

As of vim 8.1.0360 (Sep 2018), vim ships with xdiff (the same library that git uses for diffs), meaning patience diff is now natively supported in vim and neovim (see neovim issue 1466). Add this to your vimrc:

if has("patch-8.1.0360")
  set diffopt+=internal,algorithm:patience
endif

A nice introduction to both the new algorithm:patience and indent-heuristic diff options can be found at Vimways ~ The power of diff.

OTHER TIPS

I made a plugin that allows this. Try my EnhancedDiff plugin

see :help diff-diffexpr: http://vimdoc.sourceforge.net/htmldoc/diff.html#diff-diffexpr

you might be able to set it to something like

set diffexpr=MyDiff()
function MyDiff()
   let opt = ""
   if &diffopt =~ "iwhite"
     let opt = opt . "-w "
   endif
   silent execute "!git diff --no-index --patience " . opt . v:fname_in . " " . v:fname_new .  " > " . v:fname_out
endfunction

I tried this, but I did not get it to work as git outputs unified diff format, while vim expects ed style format (see doc above). You might have to transform the output of git diff, which is probably not what you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top