Wikia

Vim Tips Wiki

Changes: Combining vimdiff with cvs diff

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 15: Line 15:
   
 
<pre>
 
<pre>
command -nargs=1 CVSdiff silent call CVSdiff("%", "&lt;args&gt;")
+
command -nargs=1 CVSdiff silent call CVSdiff("%", "<args>")
 
function! CVSdiff(filename, cvsversion)
 
function! CVSdiff(filename, cvsversion)
 
" append a:filename to keep extension and therefore highlighting mode
 
" append a:filename to keep extension and therefore highlighting mode
Line 21: Line 21:
 
let tempname = tempname() . a:filename
 
let tempname = tempname() . a:filename
 
let newname = tempname() . a:filename
 
let newname = tempname() . a:filename
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " &gt; " . patch
+
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch
 
execute "!cp " . a:filename . " " . tempname
 
execute "!cp " . a:filename . " " . tempname
execute "!patch -R -o " . newname . " " . tempname . " &lt; " . patchname
+
execute "!patch -R -o " . newname . " " . tempname . " < " . patchname
 
execute "vertical diffsplit " . newname
 
execute "vertical diffsplit " . newname
 
call delete(patchname)
 
call delete(patchname)
Line 41: Line 41:
   
 
line 7:
 
line 7:
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " &gt; " . patch
+
execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch
   
 
'patch' should be corrected to 'patchname'.
 
'patch' should be corrected to 'patchname'.

Latest revision as of 05:43, September 29, 2008

Tip 390 Printable Monobook Previous Next

created December 18, 2002 · complexity basic · author Jens Finkhäuser · version 6.0


I like using vim's diff mode for comparing different revisions of source code files. usually older versions do not live in the directory structure with the current versions, but in a cvs repository. the command below, CVSdiff, can compare the current file to any given revision number in the cvs repository. please note that in case a revision number does not exist, empty files will be displayed, as the below script does not do any error checking (yep, i'm lazy, and this works for me). a vertical split is performed on the current file and its given previous revision.

command -nargs=1 CVSdiff silent call CVSdiff("%", "<args>")
function! CVSdiff(filename, cvsversion)
  " append a:filename to keep extension and therefore highlighting mode
  let patchname = tempname() . a:filename
  let tempname = tempname() . a:filename
  let newname = tempname() . a:filename
  execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch
  execute "!cp " . a:filename . " " . tempname
  execute "!patch -R -o " . newname . " " . tempname . " < " . patchname
  execute "vertical diffsplit " . newname
  call delete(patchname)
  call delete(tempname)
  call delete(newname)
endfunction

CommentsEdit

See script#58. It is very useful.


I use script#90 (cvscommand.vim).


There is a little error of this tip, and I believe it is just a typo.

line 7:

execute "!cvs diff -a -r " . a:cvsversion . " " . a:filename . " > " . patch

'patch' should be corrected to 'patchname'.


I've written a shellscript "cvsvimdiff", it is available here: http://www.bononia.it/~zack/myprograms.en.html Direct link to the script: http://www.bononia.it/~zack/stuff/cvsvimdiff

It can be used as you use "cvs diff", but it spawns a vimdiff process to examine the differences.

Same idea of this tip, but I find it more handy since you usually need to review diffs during a shell session, just after "cvs update".


Around Wikia's network

Random Wiki