use vimdiff with a diff file

走远了吗. 提交于 2019-11-28 17:11:49

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.

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

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.

Adam Monsen

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).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!