How to use vimdiff as the subversion diff tool

vimdiff is fantastic. Follow these instructions to make subversion use vimdiff when you run svn diff.

Get this diffwrap.sh script and save it anywhere. I saved mine in my $HOME/bin directory. Make sure to make it executable! I’m showing it below:

#!/bin/sh

# Configure your favorite diff program here.
DIFF="/usr/bin/vimdiff"

# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}

# Call the diff command (change the following line to make sense for
# your merge program).
$DIFF $LEFT $RIGHT

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

Then change your $HOME/.subversion/config file to point at that script:

[helpers]
diff-cmd = /home/matt/bin/diffwrap.sh

Then go diff a file!

See this section of the svn book for all the details.

24 thoughts on “How to use vimdiff as the subversion diff tool

  1. Pingback: lojic.com » Blog Archive » Use vimdiff to display subversion diffs

  2. great, but, any ideas on how to get the right pane to save changes over the top of your file if you move something from the repository version into your version? :\

  3. Hi Joel, Yeah, I’ve wondered that myself too. I have no suggestions other than using :w to write out stuff to the file you want.

    Let me know if you figure it out!

  4. I've made an improved version of this wrapper script, which gives friendly names to the Vim buffers, and also makes Vim's syntax highlighting work (it breaks because the temporary files “svn diff” creates do not have the appropriate extension).
    http://carlo-notes.blogspot.co

  5. Nice post! One question: how can I stop viewing diff files without the need for “:qa” until the last file changed? Thanks.

  6. You're asking how to quit out of vim without having to close every single buffer, one by one?

    I think you can use the :qall! thing to jump out quick. Not really sure about that. I have my F5 key mapped to :bd (buffer delete) so I just bang on F5 until I'm out.

    Thanks for the feedback!

  7. Thanks you man. It helped. All I want to add that inside ~/.subversion/config file character `~` is not expanded to $HOME. It is recommended to pass the full path of the script or to keep the script in $PATH.

  8. Is there a way to make this automatically switch to the old spew-the-diff-to-the-terminal mode when piping or redirecting the output to a file? That’d be really nice for patch creation (rather than having to do `svn diff –diff-cmd=…` every time for that).

  9. I ran into that problem plenty too! I created these two aliases in my ~/.bashrc file:

    alias boringdiff=’svn diff –diff-cmd=/usr/bin/diff’
    alias prettydiff=’svn diff –diff-cmd=$HOME/bin/diffwrap.sh’

    Then I commented out the line in the .subversion/config file.

    I hope that helps!

  10. The right side of the diff is the not the editable file but some temp file . Need help !!

Comments are closed.