Samer Atiani
Samer Atiani

Reputation: 695

How to get vimdiff to display output from cvs diff --side-by-side

CVS diff has the option to display revisions side by side and denote diffs with usual patch symbols like:

import zlib                                        import zlib
                                                 > import time
import traceback                                   import traceback

import cElementTree as ElementTree                 import cElementTree as ElementTree

from util import infopage                          from util import infopage
                                                 > from util.timeout import Timeout

Is there anyway to pipe that output to vimdiff so that it displays those two columns in two side-by-side buffers along with all the diff-highlighting goodness of vimdiff?

I'm aware of tools like cvsvimdiff.vim and the like, but the problem with those is that they only work on one file at a time, whereas the cvs diff output lists multiple files.

Upvotes: 1

Views: 2439

Answers (2)

sud03r
sud03r

Reputation: 19759

I would write a script say : vimdiff_cvs file.cc which does this:

  1. Store diff of file.cc locally, delete it, update to repository. Now copy it as ~/.vimdiff/file.cc.repo.
  2. Restorefile.cc by applying the patch
  3. Call vimdiff file.cc ~/.vimdiff/file.cc.repo.

Upvotes: 0

Brian Carper
Brian Carper

Reputation: 72926

Once you have that text in a Vim buffer, you can easily split it into two buffers yourself. Looks like your sample input does the split at 50 characters.

So use <C-v> to visual-block highlight half of the diff, cut it, paste it in a new buffer, remove trailing whitespace and the > separator characters, and there you go. Or write a function to do it, something like this (which assumes the split is always at 50):

function! SplitCVSDiff()
    exe "norm gg_\<C-v>51\<Bar>Gd:vnew\<CR>p"
    silent! %s/\v\s+(\> )?$//
endfunction

Might have to be made more robust, I'm not familiar with the exact style of output CVS uses. Shouldn't be hard though.

Upvotes: 1

Related Questions