Using vimdiff for svn diff?

1,416 views
Skip to first unread message

Richard Hartmann

unread,
Sep 13, 2007, 12:43:23 PM9/13/07
to vim...@googlegroups.com
Hi all,

I love vimdiff and would want to be able to somehow show the differences
between the repository and my local file(s) in vimdiff instead of plain
diff output on STDOUT.


Is anyone aware of a working solution to this problem? My initial hunch
would be to vimdiff the local file and the same file with the inverted
svn diff patch applied to it, but that is just ugly.


Richard

Yann Thomas-Gérard

unread,
Sep 13, 2007, 12:53:18 PM9/13/07
to vim...@googlegroups.com
Richard Hartmann a écrit :

I use svncommand.vim and the command :SVNVimDiff

http://www.vim.org/scripts/script.php?script_id=922

Tim Chase

unread,
Sep 13, 2007, 1:03:36 PM9/13/07
to vim...@googlegroups.com


Well, there are a number of vim-scripts that facilitate working
with svn/cvs/etc repositories:

http://www.vim.org/scripts/script_search_results.php?keywords=svn&order_by=rating&direction=descending

Particularly the vcscommand.vim, svncommand.vim, and svn-diff.vim
scripts look promising.

My guess would be that each offers something along the lines of

:vert new
:r! svn cat -rHEAD #
:0d
:diffthis
:wincmd p
:diffthis

-tim

Richard Hartmann

unread,
Sep 13, 2007, 1:11:22 PM9/13/07
to vim...@googlegroups.com
On 13/09/2007, Yann Thomas-Gérard <ya...@thomas-gerard.net> wrote:

> I use svncommand.vim and the command :SVNVimDiff
> http://www.vim.org/scripts/script.php?script_id=922


Thanks!


Richard

bartman

unread,
Sep 13, 2007, 2:27:24 PM9/13/07
to vim_use
Richard,

On Sep 13, 12:43 pm, "Richard Hartmann" <richih.mailingl...@gmail.com>
wrote:


> I love vimdiff and would want to be able to somehow show the differences
> between the repository and my local file(s) in vimdiff instead of plain
> diff output on STDOUT.

I use :SVNDiff -- that was already suggested -- when I am already in
vim. But I also have this function in my .bashrc and .zshrc ...

vv () {
$@ | vim -R -
}

...when there is any command output that I want to see in vim I just
prefix the command with 'vv'...

vv svn diff
vv svn log

The macro basically expands the above to

svn diff | vim -R -
svn log | vim -R -

I also have a 'v' macro that only invokes vim if the output is more
then a page. 'v' is a bit more complicated then 'vv', but you can see
it in this link...

http://www.jukie.net/~bart/conf/bash.d/S101_common_tools.sh
http://www.jukie.net/~bart/conf/zsh.d/S59_tools

-Bart


Richard Hartmann

unread,
Sep 13, 2007, 6:20:29 PM9/13/07
to vim...@googlegroups.com
On 13/09/2007, bartman <bart.tro...@gmail.com> wrote:

> vv () {
> $@ | vim -R -
> }

I don't know if you like to do it that way, but if you do

alias -g V='| vim -'

in you .zshrc , you can do

svn diff V

and look at the diff that way. In your case, you would probably
want to us VV, though. I use upper case so I can protect against
accidental hits of the global alias.


I will look through your shebangs, I always love to peek and steal :)


Richard

bartman

unread,
Sep 13, 2007, 8:19:22 PM9/13/07
to vim_use
On Sep 13, 6:20 pm, "Richard Hartmann" <richih.mailingl...@gmail.com>
wrote:

> alias -g V='| vim -'
>
> in you .zshrc , you can do

Not to steal the spotlight from the project this group is about... but
WOW, zsh surprises me all the time.

Thanks.

-Bart

Michael F. Lamb

unread,
Sep 14, 2007, 1:35:01 AM9/14/07
to vim...@googlegroups.com
> Is anyone aware of a working solution to this problem? My initial hunch
> would be to vimdiff the local file and the same file with the inverted
> svn diff patch applied to it, but that is just ugly.

The other solutions mentioned are likely to be more robust, but this
works for me:

The idea is to use 'svn diff' with the '--diff-cmd vimdiff' option. The
problem is that 'svn diff' always passes some options that vim dislikes,
namely '-u -L (name) -L (name)'. So, here's what I do to strip that bit
away.

In .bash_aliases or .bashrc or somesuch:

alias svngvimdiff="svn diff --diff-cmd gvimdiff-svn-wrapper"

An executable script named 'gvimdiff-svn-wrapper' somewhere in your $PATH:

#!/bin/bash
shift 5; /usr/bin/gvimdiff -f "$@"

From then on, 'svngvimdiff' will do what you want.

Richard Hartmann

unread,
Sep 14, 2007, 4:28:42 PM9/14/07
to vim...@googlegroups.com
On 14/09/2007, Michael F. Lamb <mi...@datagrok.org> wrote:

> alias svngvimdiff="svn diff --diff-cmd gvimdiff-svn-wrapper"

s/gvim/vim/g and I have _exactly_ what I wanted.


Thanks a lot!
Richard

Richard Hartmann

unread,
Sep 14, 2007, 7:47:52 PM9/14/07
to vim...@googlegroups.com
On 14/09/2007, Michael F. Lamb <mi...@datagrok.org> wrote:

> An executable script named 'gvimdiff-svn-wrapper' somewhere in your $PATH:

At first, I wondered why you needed to use a seperate shebang and tried to
make it work without one. Then, I gradually realized that, no matter what,

svn diff --diff-cmd

will try and execute the whole string it gets as a single command instead
of passing it onto a shell as it should, imo, do. This resulted in a
bug report [1]
against subversion. Let's see what comes from it.


Richard

[1] http://subversion.tigris.org/issues/show_bug.cgi?id=2930

Bill McCarthy

unread,
Sep 15, 2007, 5:10:43 PM9/15/07
to Vim List
On Thu 13-Sep-07 1:27pm -0600, bartman wrote:

> The macro basically expands the above to
>
> svn diff | vim -R -
> svn log | vim -R -

Using Windows, I get garbage when I do that. Although each
source line in the diff looks fine, the other svn output
ends with garbage (probably an LF instead of CR/LF).

Is this just a bug in svn? Is there a workaround?

Here's the output (only the bad lines) of:

svn diff -rPREV | gvim -

with the ctrl-M replaced by ^M:

Index: version.c^M
===================================================================^M
--- version.c (revision 522)^M
+++ version.c (working copy)^M
@@ -667,6 +667,8 @@^M
Index: ops.c^M
===================================================================^M
--- ops.c (revision 522)^M
+++ ops.c (working copy)^M
@@ -2477,7 +2477,7 @@^M
@@ -2534,7 +2534,9 @@^M
@@ -2579,7 +2581,9 @@^M
@@ -2598,13 +2602,22 @@^M

--
Best regards,
Bill

Noah

unread,
Sep 17, 2007, 4:41:45 PM9/17/07
to vim_use

On Sep 14, 1:28 pm, "Richard Hartmann" <richih.mailingl...@gmail.com>
wrote:
> On 14/09/2007, Michael F. Lamb <m...@datagrok.org> wrote:
> > alias svngvimdiff="svndiff--diff-cmd gvimdiff-svn-wrapper"

> s/gvim/vim/g and I have _exactly_ what I wanted.

Vim script 1797 is similar and a bit more robust. It works for me.

http://www.vim.org/scripts/script.php?script_id=1797

--
Noah


Reply all
Reply to author
Forward
0 new messages