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 script and save it anywhere. I saved mine in my $HOME/bin directory. Make sure to make it executable! I’m showing it below:


# Configure your favorite diff program here.

# Subversion provides the paths we need as the sixth and seventh
# parameters.

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

# 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:

diff-cmd = /home/matt/bin/

Then go diff a file!

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

  • Pingback: » Blog Archive » Use vimdiff to display subversion diffs()

  • Just what I was looking for – thanks for the tip!

  • joel

    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? :\

  • 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!

  • Thanks

  • EshwarPravar

    i added this to my article site.

    Colorado home loan | maui lodging | best e-cigarette

  • Majiert

    I think a few pictures might help this blog

    debt consolidation firm | Prada Purses | Photo to portrait

  • LawsonOrtauy8

    Hello Mate, I would like to know more on this when is the next post comming

    harsel gibs
    Provo Homes | best bangkok hotel | medical billing software

  • Edward890

    I subscribed to your blog when is the next post

    poly banger
    Polywood | dog stroller | easy candy recipe

  • I posted your blog to my facebook group

    Davin saha

  • Thanks for taking the time to discuss this,would you mind updating your blog with additional information? It is extremely helpful for me.

  • Carlo

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

  • Wow — nice work!

  • Oh thanks, i appriciate that!

  • Leandro Freitas

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

  • 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!

  • Thanks man! I changed /usr/bin/vimdiff to /usr/bin/env vimdiff because I compiled vim locally.

  • Glad to hear it helped!

  • Alexander Bird

    Awesome! I was able to set it up without any hiccups, it works like a charm. Thanks!

  • That’s great! Glad it helped.

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

  • jroelofs

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

  • 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/’

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

    I hope that helps!

  • Suresh Iyer

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