使用vim在两列中查看“cvs diff”输出

时间:2013-03-26 08:31:46

标签: vim diff cvs side-by-side vimdiff

我以统一的diff格式输出“cvs diff”(对于项目中的所有文件)。 格式可以是这样的:

Index: somefile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/somefile.cpp,v
retrieving revision 1.19
diff -r1.19 somefile.cpp
31c31
<       return "Read line four times";
---
>       return "Read line five times";
36c36
<       return "Make a bad thing";
---
>       return "Make a good thing";
Index: otherfile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/otherfile.cpp,v
retrieving revision 1.19
<       ........
---
>       ........

甚至是这样:

Index: somefile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/somefile.cpp,v
retrieving revision 1.19
diff -u -r1.19 somefile.cpp
--- somefile.cpp 13 Mar 2013 08:45:18 -0000      1.19
+++ somefile.cpp 26 Mar 2013 08:10:33 -0000
@@ -28,12 +28,12 @@
 //---------------------------------------------------------------------------
 extern "C" char *FuncGetSomeText()
 {
-       return "Read line four times";
+       return "Read line five times";
 }
 //---------------------------------------------------------------------------
 extern "C" char *FuncGetAwesomeText()
 {
-       return "Make a bad thing";
+       return "Make a good thing";
 }
 //---------------------------------------------------------------------------
Index: otherfile.cpp
===================================================================
RCS file: /CVS_repo/SomeProject/otherfile.cpp,v
retrieving revision 1.19
diff -u -r1.19 otherfile.cpp
--- otherfile.cpp 13 Mar 2013 08:45:18 -0000      1.19
+++ otherfile.cpp 26 Mar 2013 08:10:33 -0000
@@ -28,12 +28,12 @@
 //---------------------------------------------------------------------------
 extern "C" char *Func()
 {
-       .......
+       .......
 }
 //---------------------------------------------------------------------------

有没有办法与vim并排查看此文本? 或者也许可以将cvs中的默认diff工具更改为vimdiff?

1 个答案:

答案 0 :(得分:0)

一些sed魔法帮助我:

\cvs -n diff -u > ~diff.tmp; vim -O <(sed -r -e 's/^\+[^\+]+.*$//g;s/^\+$//g' ~diff.tmp) <(sed -r -e 's/^-[^-]+.*$//g;s/^-$//g' ~diff.tmp) +'set scb | set nowrap | wincmd w | set scb | set nowrap'

这不是完美的解决方案,但总比没有好。这个脚本在这里做什么:

\cvs -n diff -u > ~diff.tmp; 

将统一格式(-u选项)的CVS diff输出写入临时文件~diff.tmp。 '\'char阻止使用“cvs”命令的别名。

(sed -r -e 's/^\+[^\+]+.*$//g;s/^\+$//g' ~diff.tmp)
(sed -r -e 's/^-[^-]+.*$//g;s/^-$//g' ~diff.tmp)

此命令从~diff.tmp输出文本,用空行代替以'+'和' - '符号开头的行。

vim -O <(sed...) <(sed...) +'set scb | set nowrap | wincmd w | set scb | set nowrap'

打开两个窗口(-O选项),每个窗口都有sed的输出。命令跟随'+'设置srollbind on nowrap为第一个窗口,然后切换到第二个窗口('wincmd w')并做同样的事情