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.

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

  • http://lojic.com/blog/ Brian Adkins

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

  • http://tplus1.com matt

    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!

  • http://www.uk-cheapest.co.uk Domain Name Registration

    Thanks

  • EshwarPravar

    i added this to my article site.

    Thanks
    kailis
    ______________________________________________
    Colorado home loan | maui lodging | best e-cigarette

  • Majiert

    I think a few pictures might help this blog

    regards
    marshel
    ______________________________________________
    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

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

  • Edward890

    I subscribed to your blog when is the next post

    respect
    poly banger
    ______________________________________________
    Polywood | dog stroller | easy candy recipe

  • http://www.colonytire.com/ brake service nc

    I posted your blog to my facebook group

    Thanks
    Davin saha
    ______________________________________________

  • http://chic123456.wordpress.com/ fashion blog

    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).
    http://carlo-notes.blogspot.co

  • http://blog.tplus1.com Matt Wilson

    Wow — nice work!

  • http://viettelonline.com/ ThuanTM

    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.

  • http://blog.tplus1.com Matt Wilson

    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!

  • http://gazel.la/ Frank Smith

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

  • http://blog.tplus1.com Matt Wilson

    Glad to hear it helped!

  • Alexander Bird

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

  • http://blog.tplus1.com Matt Wilson

    That’s great! Glad it helped.