码迷,mamicode.com
首页 > 系统相关 > 详细

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

时间:2015-02-12 18:35:28      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:vimdiff   svndiff   svn   vim   

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 diff 使用 vimdiff 作为差异比较工具

标签:vimdiff   svndiff   svn   vim   

原文地址:http://blog.csdn.net/jncpp/article/details/43764071

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!