有没有办法将多对文件排队以便与 vimdiff 进行比较?
我有几十个文件需要与 vimdiff 进行比较和合并。有什么方法可以将文件对排队进行比较,以便我可以一次打开它们,而不是一次又一次返回 shell 来打开每对文件?
可以通过在自己的选项卡中打开每一对来完成此操作吗?我的 shell 是 Bash。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是另一个答案,在其自己的选项卡中打开每一对。
再次将以下内容保存在文件 (do2.sh) 中:
执行时,它将在其自己的选项卡中打开这些对。
Here is another answer that opens each pair in it's own tab.
Save again the following in a file (do2.sh):
when you execute it will open the pairs in their own tab.
如果您想比较目录中的所有文件的所有组合,请按以下方法操作,并且仍然避免将两个文件对(或一个文件与其自身)进行比较:
If you want to compare all the files in a directory with each other in all combinations, here's how to do that and still avoid comparing a pair twice (or a file with itself):
通过全局设置所有 diffy 选项(以及一些自动命令,因为如果您尝试同时比较 8 个以上的文件,vim 会生气),这可以在没有任何 shell 恶作剧的情况下完成
。这将打开缓冲区中的所有文件,并将 vim 垂直分割为两个窗口(如果需要水平窗口,请使用
-o2
),并且始终处于 diff 模式,即使您在缓冲区之间切换或打开新文件也是如此。如果您要将所有文件合并到一个超级文件中,那么使用
:bn
就可以解决问题。如果您要合并文件对,则需要
:windo bn N
的一些变体,其中 N 取决于您列出文件的方式:A1 A2 B1 B2 C1 C2< /code>,
:windo bn 2
会做正确的事情A1 B1 C1 A2 B2 C2
,您首先需要转到A2
code> 缓冲区,然后:windo bn 1
会做正确的事情,我从 帮助文件:
并且只是根据经验发现了自动命令废话的必要性。
This is doable without any shell shenanigans by setting all the diffy options globally (along with some autocommands, because vim gets angry if you try to diff more than 8 files at once)
This will open all your files in buffers, and vertically split vim into two windows (use
-o2
if you want horizontal), and always be in diff mode, even if you switch between buffers or open new files.If you're merging all your files together into one super-file, then using
:bn
will be fine for getting around.If you're merging pairs of files, then you'll want some variation of
:windo bn N
, where N depends on how you listed your files:A1 A2 B1 B2 C1 C2
,:windo bn 2
will do the right thingA1 B1 C1 A2 B2 C2
, you'll need to initially go to theA2
buffer, and then:windo bn 1
will do the right thingI pulled the settings from the help file:
And only discovered the need for the autocommand nonsense empirically.
据我所知,你不能使用单个 vim 命令来做到这一点。您可以从 for 循环内启动 vimdiff。
或者尝试“meld”http://meld.sourceforge.net/
You can't do it using a single vim command as far as I am aware. You could start vimdiff from within a for loop.
Alternatively try "meld" http://meld.sourceforge.net/
就像 StephenPaulger 所建议的那样,for 循环对于少量文件来说效果很好。
我这样做的方法是创建一个包含以下内容的小脚本(例如 do.sh):
一旦退出,这将允许您在对不同文件进行比较时不必在 shell 中键入任何内容一对文件的 diff 会立即显示另一个文件。
这里使用的另一个有用的技巧是将以下内容放入 .vimrc 中
,如果没有更改,则只需按 f4 退出,如果有更改,则按 f5。
Like StephenPaulger suggested a for loop would work well for a small number of files.
The way that I would do it is to create a small script (say do.sh) with the following contents:
this would allow you to not have to type anything in the shell while doing the diff for the different files, once you exit the diff for one pair of files the other shows up right away.
Another useful tip to use here is to put the following in your .vimrc
then if there are no changes you just press f4 to exit, if there are changes you press f5.