tags:

views:

194

answers:

3

Say I get a patch created with git format-patch. The file is basically a unified diff with some metadata. If I open the file in Vim, I can see which lines have been modified, but I cannot see which characters in the changed lines differ. Does anyone know a way (in Vim, or some other free software that runs on Ubuntu) to visualize per-character differnces?

A counter example where per-character diff is visualized is when executing vimdiff a b.

A: 

After a little research, I notice this question has come up twice recently on the main Vim mailing list. The NrrwRgn plugin was mentioned both times (make two narrow regions and diff them). Using NrrwRgn as described by Christian Brabandt feels more like a workaround than a solution, but maybe that's good enough.

I tried out NrrwRgn and it, together with :diffthis, was indeed useful for illustrating per-character differences within parts of a single file. But it took many keystrokes. My Vimscript is pretty rusty, but it could likely be scripted. Maybe NrrwRgn could be enhanced to provide the desired functionality.

Thoughts?

Adam Monsen
A: 

Am not aware of per character difference tool, but there is a per word difference tool: wdiff.

refer examples Top 4 File Difference Tools on UNIX / Linux – Diff, Colordiff, Wdiff, Vimdiff.

thegeek
wdiff is interesting, thanks! To clarify my original question, I'm looking for something that provides enhanced syntax highlighting for a single file that happens to be in unified diff format.
Adam Monsen
+2  A: 

Given your references to Vim in the question, I'm not sure if this is the answer you want :) but Emacs can do this. Open the file containing the diff, make sure that you're in diff-mode (if the file is named foo.diff or foo.patch this happens automatically; otherwize type M-x diff-mode), go to the hunk you are interested in and hit C-c C-b for refine-hunk. Or step through the file one hunk at a time with M-n; that will do the refining automatically.

legoscia
Works for me! Heh, I've used Vim for 10 years, but I just installed emacs. :)
Adam Monsen