Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use vimdiff with a diff file

Tags:

vim

vimdiff

How can I use vimdiff to view the differences described in a diff file?

like image 386
user14437 Avatar asked Oct 28 '08 09:10

user14437


3 Answers

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.

Edit

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.

like image 156
ephemient Avatar answered Oct 17 '22 22:10

ephemient


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

like image 3
Jeremy Cantrell Avatar answered Oct 17 '22 21:10

Jeremy Cantrell


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.

like image 2
Ken Avatar answered Oct 17 '22 20:10

Ken