Erik's Weblog 2.0

February 14, 2006 +2 more...


Subversion diff with vim

Once in a while I have to use Subversion on a Linux box. Not a big deal, except for diffs. The standard svn diff output is not the most readable. Vim, or more exactly vimdiff, does a terrific job at displaying differences between files side-by-side. Here's a little Bourne shell script I wrote that uses vimdiff to view the differences between a local file and the latest revision in the repository:
Nothing too fancy. It uses svn cat to get the latest rev, saves it to a temporary file, and opens both files in vimdiff:
The temp file is deleted as soon as vimdiff is quit.

I also just found svncommand.vim, a nifty Subversion integration plugin.


Marius Scurtescu

Feb 15, 2006 at 17:20

There is a really nice Linux tool for visual diffs, it is called meld (

Give it a try, it does understand Subversion and all you have to do is:
$ meld <your_file>

It can also show diffs for a whole folder structure, just use a folder name instead of a file name.

Fernando Brucher

Apr 3, 2006 at 09:20

Your script works better if the extension of the temporary file is the same as for the original file.
That way syntax highlighting works also for the temporary file. I modified the temp file name generation in your script like so:


Thanks for creating you script. It works great. And I'm happy to be able to use vimdiff, which I'm familiar with.


May 11, 2006 at 03:27

Good tip!

I've found it has problems using directories (ie, 'svndiff lib/foo.php') but it works if you change temp file name with this:

TEMP=/tmp/tmp.$$.`basename $1`

fREW Schmidt

Nov 25, 2006 at 20:36

Hi Erik,
I don't know if you actually do any editing when you use this script.  I personally don't so I found it useful to do the following:

vimdiff -R $TEMP $1

Only because I tend to leave files open in vim in between commits and I got sick of the error message and whatnot.

Balbir Singh

Apr 6, 2007 at 20:01

I would suggest a trap in the begining to make sure the temp file is removed no matter how the script exits.


trap 'rm -f $tempfile' 0 1 2 15

Thanks for the idea.


Jan 16, 2011 at 09:53

I've made a script with the same purpose. It's intended as an argument to the --diff-cmd option, which is usually achieved via a ~/.subversion/config entry. The advantage is that you have all the options of "svn diff" available, such as --summarize.
It also gives friendly names to the Vim buffers -- Subversion passes these as additional parameters.
Furthermore, it ensures Vim syntax highlighting does not break, in the vein of Francesc's suggestion.

Erik C. Thauvin

Jan 18, 2011 at 04:59

Nice script, Carlo. Too bad I don't have gVim to use on my servers.

BTW, I just checked in a new version of the script incorporating all of the suggestions posted here.



Post a comment

Comment Preview