diff-cmd = svndiff_helper
[helpers]section of your
We pass the sixth and seventh parameters to gvimdiff because that's where
gvimdiff -f "$6" "$7"
svn diffpasses us the names of the files to diff. Incidentally, the -f parameter is needed to prevent Vim from forking on startup, since svn would then delete the temporary files too quickly.
So what do the other parameters contain? Let's find out:
$ echo 'for a in "$@"; do echo "$a"; done' >pargs $ chmod +x pargs $ ls -A aa rand readme .svn $ svn diff -r1 --diff-cmd=./pargs readme Index: readme =================================================================== -u -L readme (.../readme) (revision 1) -L readme (.../branches/mybranch/readme) (working copy) .svn/tmp/tempfile.tmp readme
Interesting – svn gives us a nice textual description of both files in arguments three and five respectively. How about we use those to name the buffers in gvimdiff?
With this script, you can. There are a few tricks to it:
- I use the --cmd option to Vim to make it run a command on startup.
- Specifically, I set up autocommands (
autocmd, abbreviated to
au) to change both buffer names as appropriate when the BufReadPost event is triggered, which happens when the files are read.
- I use the
:filecommand (abbreviated to just
f) to change the buffer name. Unfortunately, Vim doesn't handle tabs in the name very well, so I replace those by spaces. Those in turn I have to escape in order for the
:filecommand to accept them.
- Vim also gets confused if the buffer name contains a slash, so I replace those by backslashes.