将 vimdiff 与 diff 文件结合使用

发布于 2024-07-07 06:15:34 字数 37 浏览 7 评论 0原文

如何使用 vimdiff 查看 diff 文件中描述的差异?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烟花肆意 2024-07-14 06:15:34

不要使用 /usr/bin/vimdiff 命令,而是尝试以下命令:(

$ vim file
:vertical diffpatch path/to/diff

简称 :vert diffpa。)
这相当于在原始文件和随后修补的文件上调用 vimdiff,但 vim 为您在临时文件上调用 patch

编辑

如果您希望自动进入 vim 的 diff 模式,请使用以下命令:

$ vim file +'vert diffpa path/to/diff'

其中 +command 要求 vim 执行“命令”。 (+123 跳转到第 123 行,+/abc 跳转到“abc”的第一个匹配项,这些都已记录。)

关于 Ken 的查询:如果 diff 文件包含 hunks应用于除您当前正在编辑的文件之外的文件,不用担心; vim 调用下面的 patch 可执行文件,它会询问这些神秘丢失的文件的位置,你可以告诉 patch 跳过这些大块。

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.

刘备忘录 2024-07-14 06:15:34

从另一个方向过来。 我编写了一个 Vim 插件,以 vimdiff 或统一 diff 格式显示自上次保存以来对文件所做的更改。

在这里获取它: diffchanges.vim

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

白衬杉格子梦 2024-07-14 06:15:34

复制原始文件,应用差异,然后

vimdiff original_file patched_file

您还可以查看 vim.org 脚本 已编写用于处理 svn diff 输出。 如果您从版本控制系统生成差异,请查看 vcs 命令.vim :CVS/SVN/SVK/git 集成插件

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.

暮色兮凉城 2024-07-14 06:15:34

您能详细说明一下为什么要使用 vimdiff 吗?

例如,您想要可视化(统一)差异文件中每个字符的差异?。 如果是这样,有人回答了我的问题与 一个建议基本上只是在差异上启动 emacs 并按 ALT-n 循环显示大块,很好地突出显示每个单词或每个字符的变化(类似于vimdiff)。 它工作得很好,但是仅仅为了做到这一点而启动 emacs 就太糟糕了。 我只知道足够的 emacs 来做到这一点,然后退出而不会弄乱补丁。 :)

不管怎样,emacs 的回答给了我一些想法。 我确信 Vim 可以被诱骗为 diff 文件提供更好的突出显示,也许更像 ediff。 我不久前研究过这个问题,vim 用户列表上的某个人对 合并 google-diff-match-patch。 例如,Python 接口可以从 Python Vim ftplugin 中使用。

很抱歉,当这可能不是一个很好的答案时,使用“答案”来回复,“添加评论”的格式对于我想说的内容来说太有限了。

对于后人来说,这里引用了另一个类似的问题(也已经链接到这里)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文