在 vim 中比较窗口
我正在编写一个相当复杂的脚本。我怀疑有几个部分具有几乎相同的代码。我可以(以及如何)在 vim 中打开文件,在缓冲区上有两个(或更多)窗口,并在同一文件上比较窗口的内容吗? vimdiff 似乎只适用于两个文件。如果我复制该文件并尝试对两个版本进行 vimdiff,则差异源仍锁定在文件的开头。虽然我可以取消滚动锁定窗口,并将窗口移动到我想要比较的文件部分,但差异不会显示。有什么提示或技巧吗?我可以剪切并粘贴我想要与不同文件进行比较的部分,然后应用 vimdiff,但是当我尝试将单独的文件修补在一起时,我可能会迷失在哪个部分来自哪里,而且我确信一定有一个更直接的方法,更简单的方法。
I am working on a script that has become fairly convoluted. I suspect there are several sections that have nearly identical code. Can I (and how can I) open the file in vim, with two (or more) windows on the buffer, and diff the contents of the windows on the same file? vimdiff seems to work only on two files. If I make a copy of the file and try to vimdiff the two versions, the diff origin remains locked on the beginning of the file. Although I can unscroll-lock the windows, and move the windows to the parts of the file I want to compare the diffs do not show up. Any hints or tips? I could cut and paste the sections I want to compare to different files and then apply vimdiff but then I risk getting lost in what section came from where when I try to patch the separate files together, and I feel sure there must be a more straightforward, easier way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常做的就是比较一个副本
,然后愉快地重新排列“alt”版本,以便伪匹配位对齐。
请注意,(大概)git 包含出色的合并/差异功能,应该能够检测子文件移动的块更改。
虽然我还没有真正将其付诸实践,但我有一种预感,vim 的非常好的 git 插件
fugitive
可能能够利用其中的一些功能来使这变得更容易。 注意:完全期望这需要 scriptinh 才能使用,但我仍然认为分享这个想法会很好(如果你先接触到它,也许你可以分享一个脚本!)< /em>What I usually do is diff to a copy
And then happiliy rearrange the 'alt' version so that the pseudo-matching bits get aligned.
Note that (presumably) git contains spiffy merge/diff cow-powers that should be able to detect sub-file moved block changes.
Although I haven't (yet) actually put this into practice, I have a hunch that the very nice git plugin
fugitive
for vim might be able to leverage some of this horsepower to make this easier. Note: fully expect this to require scriptinh before being usable, but I still thought it would be nice to share this idea (perhaps you can share a script if you get to it first!)作为我偶尔使用的替代解决方案,我认为效果非常好是 linediff.vim。
它允许您使用视觉模式从任意缓冲区(或相同的缓冲区)中选择两个文本主体,并在它们上运行 vimdiff。它的美妙之处在于,当您编辑和保存临时差异缓冲区时,您可以使用更改更新原始缓冲区,而无需保存。
我的用例之一是当我解决与脚本重构和重新排序相关的合并问题时,其中函数已被移动并且可能还被修改。为了确保您不会丢失来自任一祖先的任何修改,您可以通过直观地选择函数的两个版本并运行 linediff 命令来单独区分函数的两个版本。
As an alternative solution that I've been using occasionally and which works very nicely in my opinion is linediff.vim.
It allows you to use visual mode to select two bodies of text from arbitrary buffers (or the same for that matter) and run vimdiff on them. The beauty of it, is that when you edit and save the temporary diff buffers, you update the original buffers with the changes, without saving.
One of my use-cases is when I'm resolving merge issues related to script refactoring and reordering, where a function has been moved and perhaps also modified. In order to make sure you do not lose any of the modifications coming in from either ancestor, you diff the two versions of the function alone by visually selecting them and running the linediff command.