[ann] New plugin to use patience diff algorithm for vim

134 views
Skip to first unread message

Christian Brabandt

unread,
Feb 25, 2015, 3:57:15 PM2/25/15
to vim...@vim.org
Hi,

I made a new plugin to make Vim understand unified diffs.

This allows to generate diffs using the patience algorithm which might
provide better readable diffs. This really depends on the changes and
will not always provide better results but at least this allows to
easily switch between different diff algorithms.

Alternatively one can use any other tool to generate the diffs as long
as they are "unified" or "normal" style diffs.

You can also customize your setup to use any other tool to generated
diffs (e.g. mercurial) Read the help on how to configure the plugin
accordingly.

Screenshots are available at github:
https://github.com/chrisbra/vim-diff-enhanced

Installation:
Use the plugin manager of your choice. Or download the stable version of
the plugin, edit it with Vim (vim EnhancedDiff-XXX.vmb) and simply
source it (:so %). Restart and take a look at the help (:h
EnhancedDiff.txt)

Usage:

Once installed, take a look at the help at :h EnhancedDiff

Here is a short overview of the commands provided by the plugin:

:PatienceDiff - Use the Patience Diff algorithm for the next diff mode

:CustomDiff <algorithm> - Use <algorithm> to generate the diff. Use any of
myers
default
histogram
minimal
patience
After changing the algorithm, you need to run :diffupdate if you are in
diff mode to regenerate the diff.

Note: Those 2 commands use internally git to generate the diffs. Make sure you have at least git version 1.8.2 installed.

:DisableEnhancedDiff - Disable plugin (and use default Vim diff capabilities).

License:
The Vim License applies. See :h license

Best,
Christian
--
Der Vertreter klingelt an der Haustür.
Als ihm geöffnet wird, sagt er:
"Gnädige Frau, darf ich Ihnen unseren Verkaufsschlager vorführen,
von dem Ihre Nachbarin meint, Sie könnten ihn sich nicht leisten?"

Gary Johnson

unread,
Mar 4, 2015, 5:33:20 PM3/4/15
to vim...@googlegroups.com
On 2015-02-25, Christian Brabandt wrote:
> Hi,
>
> I made a new plugin to make Vim understand unified diffs.
>
> This allows to generate diffs using the patience algorithm which might
> provide better readable diffs. This really depends on the changes and
> will not always provide better results but at least this allows to
> easily switch between different diff algorithms.

Hi Christian,

Thanks so much for doing this. I often deal with messy merges, so I
am looking forward seeing the improved diff results. Of course I
haven't had to do any messy ones since I installed your plugin.

I think I've found a bug. When I start vimdiff from the command
line with the option

--cmd 'set diffopt+=iwhite'

then execute

:PatienceDiff
:diffu

I get the error message

EnhancedDiff: git diff not found in path, aborting!

That message is not accurate. The real reason that the call to
s:DiffInit() fails (at line 109 of autoload/EnhancedDiff.vim) is
this:

Vim(call):E121: Undefined variable: g:diffargs

There is only one occurrence of g:diffargs in your plugin, and
that's at line 40 of autoload/EnhancedDiff.vim. I think that
variable is supposed to be s:diffargs. Renaming it fixes the
problem.

I'm using EnhancedDiff.vim version 0.2 and Vim 7.4.640.

Regards,
Gary

Christian Brabandt

unread,
Mar 5, 2015, 2:11:13 AM3/5/15
to vim...@googlegroups.com
Hi Gary!
Thanks! I am fixing it now and will upload a new version.

Best,
Christian
--
Meinungen sind so etwas ähnliches wie Hämorrhoiden des Geistest.
-- Heimito von Doderer (Pseudonym: Stangeler, Reneé)

Christian Brabandt

unread,
Mar 5, 2015, 2:19:36 AM3/5/15
to vim...@googlegroups.com
BTW: If anybody has an example of some messy diff, where you'd like to
manually align the diffs, I would appreciate a copy. I am thinking of
adding the possibility to let the user manually align the diffs, so that
the resulting diff would look nicer.

Best,
Christian
--
Das sage ich nun wirklich nie!
Das ist wohl eher Joeys Satz.
-- Oliver Zendel

Ben Fritz

unread,
Mar 5, 2015, 1:40:50 PM3/5/15
to vim...@googlegroups.com
I tried working on a plugin to do that once, and found Vim didn't support it using the method I was thinking of.

I was trying to do it by splitting the files into multiple parts where the user marked alignment points, diffing the parts, and concatenating the diff of each part together.

But Vim doesn't parse well when it finds two diff hunks adjacent to each other; it makes the assumption that adjacent differences are always combined in a single hunk.

Eventually I was planning to look into what it would take to patch that, and write a plugin, but if you get to it first (or find another way to do it) I'd love to use it.

Christian Brabandt

unread,
Mar 5, 2015, 3:03:20 PM3/5/15
to vim...@googlegroups.com
Hi Ben!
I remember that discussion and that was exactly the way I was trying to
do that. I was asking for examples, so that I could actually see, if
this will work. If not, we'll have to convince Bram to patch that part
out (I think this was just an off-by-one change).

BTW: If you want to contribute, I can give you access to the repository.

Best,
Christian
--
Frauen haben viele Fehler.
Männer haben nur zwei:
alles, was sie sagen
und alles, was sie tun
Reply all
Reply to author
Forward
0 new messages