有没有办法将多对文件排队以便与 vimdiff 进行比较?

发布于 2024-10-27 00:34:30 字数 139 浏览 1 评论 0 原文

我有几十个文件需要与 vimdiff 进行比较和合并。有什么方法可以将文件对排队进行比较,以便我可以一次打开它们,而不是一次又一次返回 shell 来打开每对文件?

可以通过在自己的选项卡中打开每一对来完成此操作吗?我的 shell 是 Bash。

I have a few dozen files I need to compare and merge with vimdiff. Is there any way to queue pairs of files for comparison so that I may open them all at once, rather than returning to the shell again and again to open each pair of files?

Could this be done by opening each pair in its own tab? My shell is Bash.

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

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

发布评论

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

评论(5

二智少女猫性小仙女 2024-11-03 00:34:30

这是另一个答案,在其自己的选项卡中打开每一对。
再次将以下内容保存在文件 (do2.sh) 中:

#!/bin/bash

files1=( file1.txt file2.txt file3.txt )
files2=( file1_.txt file2_.txt file3_.txt )

cmd="vim -c 'set diffopt=filler,vertical' -c 'edit ${files1[0]}' -c 'diffsplit ${files2[0]}' "
echo $cmd
for i in {1..2}; do
  cmd="${cmd} -c 'tabe ${files1[i]}' -c 'diffsplit ${files2[i]}' "
done

eval $cmd

执行时,它将在其自己的选项卡中打开这些对。

Here is another answer that opens each pair in it's own tab.
Save again the following in a file (do2.sh):

#!/bin/bash

files1=( file1.txt file2.txt file3.txt )
files2=( file1_.txt file2_.txt file3_.txt )

cmd="vim -c 'set diffopt=filler,vertical' -c 'edit ${files1[0]}' -c 'diffsplit ${files2[0]}' "
echo $cmd
for i in {1..2}; do
  cmd="${cmd} -c 'tabe ${files1[i]}' -c 'diffsplit ${files2[i]}' "
done

eval $cmd

when you execute it will open the pairs in their own tab.

枕花眠 2024-11-03 00:34:30

如果您想比较目录中的所有文件的所有组合,请按以下方法操作,并且仍然避免将两个文件对(或一个文件与其自身)进行比较:

for f1 in *; do 
  for f2 in *; do 
    [[ $f1 < $f2 ]] || vimdiff "$f1" "$f2"
  done
done

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

for f1 in *; do 
  for f2 in *; do 
    [[ $f1 < $f2 ]] || vimdiff "$f1" "$f2"
  done
done
心奴独伤 2024-11-03 00:34:30

通过全局设置所有 diffy 选项(以及一些自动命令,因为如果您尝试同时比较 8 个以上的文件,vim 会生气),这可以在没有任何 shell 恶作剧的情况下完成

vim -c 'windo set diff scrollbind cursorbind scrollopt+=hor nowrap foldmethod=diff foldcolumn=2 | au BufWinEnter * setlocal diff | au BufWinLeave * setlocal nodiff' -O2 your filenames here

。这将打开缓冲区中的所有文件,并将 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 会做正确的事情,

我从 帮助文件

在每个编辑的文件中设置这些选项:

'diff' on
“滚动绑定”开启
'cursorbind' 上
“scrollopt”包括“hor”
‘包裹’掉
'折叠方法'“差异”
'diffopt' 中的 'foldcolumn' 值,默认值为 2

这些选项设置在窗口本地。编辑另一个文件时,它们将重置为全局值。

并且只是根据经验发现了自动命令废话的必要性。

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)

vim -c 'windo set diff scrollbind cursorbind scrollopt+=hor nowrap foldmethod=diff foldcolumn=2 | au BufWinEnter * setlocal diff | au BufWinLeave * setlocal nodiff' -O2 your filenames here

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:

  • For A1 A2 B1 B2 C1 C2, :windo bn 2 will do the right thing
  • For A1 B1 C1 A2 B2 C2, you'll need to initially go to the A2 buffer, and then :windo bn 1 will do the right thing

I pulled the settings from the help file:

In each of the edited files these options are set:

'diff'    on
'scrollbind'  on
'cursorbind'  on
'scrollopt' includes "hor"
'wrap'    off
'foldmethod'  "diff"
'foldcolumn'  value from 'diffopt', default is 2

These options are set local to the window. When editing another file they are reset to the global value.

And only discovered the need for the autocommand nonsense empirically.

残月升风 2024-11-03 00:34:30

据我所知,你不能使用单个 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/

浅浅淡淡 2024-11-03 00:34:30

就像 StephenPaulger 所建议的那样,for 循环对于少量文件来说效果很好。
我这样做的方法是创建一个包含以下内容的小脚本(例如 do.sh):

#!/bin/bash

files1=( file1.txt file1_.txt )
files2=( file2.txt file2_.txt )
for i in {0..1} ; do
  vimdiff ${files1[i]} ${files2[i]}
done

一旦退出,这将允许您在对不同文件进行比较时不必在 shell 中键入任何内容一对文件的 diff 会立即显示另一个文件。

这里使用的另一个有用的技巧是将以下内容放入 .vimrc 中

if &diff
   map <f4> :qa<cr>
   map <f5> :wqa!<cr>
   map <f6> :qa!<cr>
 endif

,如果没有更改,则只需按 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:

#!/bin/bash

files1=( file1.txt file1_.txt )
files2=( file2.txt file2_.txt )
for i in {0..1} ; do
  vimdiff ${files1[i]} ${files2[i]}
done

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

if &diff
   map <f4> :qa<cr>
   map <f5> :wqa!<cr>
   map <f6> :qa!<cr>
 endif

then if there are no changes you just press f4 to exit, if there are changes you press f5.

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