Vim Tips Wiki

Combining vimdiff with cvs diff

Redirected from VimTip390

1,624pages on
this wiki
Add New Page
Talk0 Share
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)


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: Direct link to the script:

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".

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki