svn diff 使用 vimdiff 作为差异比较工具

svn diff 使用 vimdiff 作为比较差异工具

引用的一篇文章说明

One of vim’s nice features is a powerful diff tool that can be used to easily tell the differences between multiple different files. This can be called up at any time by issuing the following:

vimdiff file1.xxx file2.xxx

Subversion’s default diff tool - while effective - lacks a lot of options. Firstly, it simply outputs the results of the diff to standard out. This is limiting for several reasons: you can’t edit the files you’re diffing, so quickly changing code is impossible. There’s also no color or syntax highlighting, so telling at a glance what’s changed is more difficult. Vimdiff solves all these problems, as it drops you into a full instance of vim allowing you to do anything.
Why use svn diff when we can seamlessly integrate vimdiff into the workflow in two simple steps? Let’s get started!

Step 1: The Script

The first thing that needs to be done is to create a simple bash script that will be the wrapper for svn diff. Create the following file on your system named diffwrap.sh:

#!/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
$DIFF $LEFT $RIGHT

You can either put it in a system wide folder (/usr/local/bin) or in your own folder. In any event, don’t forget to

chmod a+x diffwrap.sh

Step 2: Make Subversion Use It

Now that the script exists, we have to tell Subversion to use it for diff. Luckily that’s quite easy. Simply edit ~/.subversion/config and find the diff-cmd line inside the [helpers] section. Uncomment it and change it to something like this:

diff-cmd = /path/to/diffwrap.sh

Step 3: Profit!

You’re all done! To see it in action, change directory into a Subversion project with some local changes, and simply diff like normal:

svn diff

关于vimdiff的使用

vim -d a.txt b.txt
vimdiff a.txt b.txt

快捷键 说明
[c 跳转到上一个差异项
]c 跳转到下一个差异项
zo 展开折叠的相同代码
zc 重新折叠
dp 把当前处的差异项复制到另一个文件
do 将另一个文件的差异项复制到当前文件

作者 @AdvocateOS_CoderD
2015 年 02月 12日

你可能感兴趣的:(SVN,vim,vimdiff,svndiff)