diff -u(unified) and
diff -u -w
(unified, ignore whitespace) and their ssh equivalents
svn diff(unified) and
svn diff -x -w(to ignore whitespace).
I know vimdiff exists, and have used it trivially once or twice. But never felt a need to dive in.
Right now, I'm looking at a file of a coworker's modified code, trying to figure out which version it originally corresponded to. I've looked at the diffs, and I think I know which version it is, but I was having trouble comparing the lines to see what some of the diffs mean.
I popped it up in vimdiff
vimdiff file1 file2and now I have a lovely side-by-side view of the two files, with coupled scrolling. Chunks of unmodified code are folded and out of the way. The vim folding commands work normally:
zowill open a given block if I need to see that code and
zcwill close that block back up.
zAto open all and
zCto close all.
The normal vim window/frame commands can be used to switch between the two frames. Since scrolling in either file scrolls both files, there isn't a big need to switch between the frames, except when examining long lines. By default, line-wrap is off for the diff, so long lines appear truncated until the viewport is scrolled.
control-w wwill switch between the two frames. Jump to the end of the long line with
$. Again, both frames will scroll together left/right just as with up/down. Alternatively,
:set wrapin command mode will enable word wrapping, this needs to be done in each frame independently. If literal tabs are making your lines too long, try displaying tabs as smaller entities: four character
:set ts=4or two character
:set ts=2. Again, this must be applied to each buffer independently.
I really like the intra-line difference highlighter. The whole line is highlighted, but the changed portions are highlighted in a different color. Purple and Red respectively in my setup. That helps me pinpoint the exact character changes, so I can focus on see the "why" of the change instead of digging for the "what".
vimdiff and svn is not an either/or proposition. svn allows an external diff command, via the
--diff-cmdswitch. Unfortunately, vimdiff doesn't work out-of-the-box with this flag, as svn adds extra information when passing to the diff program. A have a very short wrapper called vimdiff-svn-wrapper that I use to drop the extra arguments. I have this in my path and use
svn diff --diff-cmd vimdiff-svn-wrapper filenameto run svn diff on filename, displaying the output in vimdiff.
On the other end of the spectrum is svnvimdiff from vim.org. This runs vimdiff on the output of svn diff. It's messy the way it uses temp files and I just tried the version I downloaded last year it didn't work for me. I've just written a new version. Had I checked the link, I'd see the original is on version 1.5 and I have version 1.2. My version uses the vimdiff-svn-wrapper with svn diff --diff-cmd. I have directly copied his clever method of getting the modified svn files by parsing the output of
Time to get back to figuring out the changes in his code...