Reputation: 3200
How can I use vimdiff to view the differences described in a diff file?
Upvotes: 48
Views: 28167
Reputation: 9430
Would you say more about why you want to use vimdiff for this?
For instance, do you want to visualize per-character differences in a (unified) diff file?. If so, someone answered my question about same with a suggestion to basically just fire up emacs on the diff and hit ALT-n
to cycle through hunks, nicely highlighting per-word or per-characters changes along the way (similar to vimdiff). It works well, but it's a bummer to fire up emacs just to do this. I only know enough emacs to do that then exit without mucking up the patch. :)
Anyway, the emacs answer gave me some ideas. I'm sure Vim can be cajoled into providing better highlighting for diff files, maybe something more like ediff. I looked into this a while back, and someone on the vim user list had the excellent suggestion to incorporate google-diff-match-patch. The Python interface could be used from a Python Vim ftplugin, for instance.
Sorry about using an "answer" to reply when this may not be a great answer, the formatting for "add comment" was too limited for what I wanted to say.
For posterity, here's a reference to another similar question (which already links here as well).
Upvotes: 1
Reputation: 205024
Instead of using /usr/bin/vimdiff
command, try this:
$ vim file :vertical diffpatch path/to/diff
(:vert diffpa
for short.)
This is equivalent to calling vimdiff
on the original file and the subsequently patched file, but vim
calls patch
on a temporary file for you.
If you want vim
's diff-mode to be entered automatically, use this:
$ vim file +'vert diffpa path/to/diff'
where +command
asks vim
to execute "command". (+123
jumps to line 123, +/abc
jumps to the first match for "abc", it's all documented.)
Regarding Ken's query: if the diff file includes hunks applying to files other than the file you're currently editing, no worries; vim
calls the patch
executable underneath, which will ask for the locations of these mysteriously missing files, and you can tell patch
to just skip those hunks.
Upvotes: 58
Reputation: 27434
Coming from the other direction. I wrote a Vim plugin that shows the changes that have been made to a file since the last save in either vimdiff or unified diff format.
Get it here: diffchanges.vim
Upvotes: 4
Reputation: 78922
Make a copy of the original file, apply the diff and then
vimdiff original_file patched_file
You could also look at vim.org scripts which have been written to deal with svn diff output. If you are generating your diff from a version control system then take a look at the vcscommand.vim : CVS/SVN/SVK/git integration plugin.
Upvotes: 2