SVN and VIMDIFF – Now Play Nice

I use svn quite frequently however, the standard diff tool built in with svn leaves a lot to be desired.  Its output reminiscent of a command line patch.  Personally, I love vimdiff (or vim -d if you prefer) when it comes to comparing files.  Recently I hooked vimdiff into svn diff, now I get all the power and love of vimdiff by executing “svn diff …”.  Here’s how I did it.

First create a wrapper file called “svndiff”.  You’re going to want to do this so you can ensure everything gets displayed the way you want it to.  I created mine in the home directory.

touch /home/godlikemouse/svndiff

Next let’s edit the file and tell it what to do with the information that will be passed to it from svn.



/usr/bin/vimdiff ${7} ${6}


I like to have my local working copy displayed on the left and the remote or svn copy on the right.  If you like yours the other way around, just reverse the last two parameters to: ${6} ${7}.

Next we need to make the script executable.

chmod a+x /home/godlikemouse/svndiff

Lastly, we need to tell svn to use this file instead of its own built in diff.  To do so, edit the “.subversion/config” file located in your home directory (ie. /home/godlikemouse/.subversion/config).

Find the section labelled [helpers] and add the following command:

diff-cmd = /home/godlikemouse/svndiff

That’s pretty much all there is to it, now when you execute a command like “svn diff index.php” it will use vimdiff or whatever diff program you prefer.

Just as an enhancement, I like to have my terminal title set to the working copy and revision of the file respectively.  If you would like the same, add the following to your svndiff file:


TITLE="${5} - ${3}"
TITLE=`echo ${TITLE//(/\\(}`
TITLE=`echo ${TITLE//)/\\)}`
TITLE=`echo ${TITLE// /\\ }`
TITLE=`echo ${TITLE//-/\\-}`
/usr/bin/vimdiff -c "set title titlestring=$TITLE" ${7} ${6}


There we go, nice and clean.  Now the title shows up perfectly showing the working copy of the file and the revision.  Party.

Leave a Reply

Your email address will not be published. Required fields are marked *