2013-03-26 31 views
2

我有統一比較格式的「cvs diff」輸出(對於項目中的所有文件)。 格式可能是這樣的:用vim查看「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中的默認差異工具更改爲vimdiff?

+1

http://stackoverflow.com/questions/26195/vimdiff-and-cvs - 集成 – 2013-03-26 12:41:48

+0

謝謝,但是這個解決方案對我不起作用。我的vim在6.3.71版本中已經過時了。他未知的winsave()函數失敗。我評論winsave/winrestore函數,但是我的vim窗口中沒有任何內容:D vim命令。 – Avega 2013-03-27 06:47:46

+0

你應該回答你自己的問題作爲答案。 – 2013-04-11 16:52:27

回答

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.tmp。 '\'字符阻止取得「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')並做同樣的事情