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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With