vimdiff:强制逐行比较(忽略据说丢失/增加的行) [英] vimdiff: force line-by-line comparison (ignore supposedly missing/additional lines)

查看:290
本文介绍了vimdiff:强制逐行比较(忽略据说丢失/增加的行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制vimdiff始终逐行比较两个文件,而不标识添加或删除的行?

问题是,如果两个文件之间的差异很大,但偶然情况下文件中的两行匹配,vimdiff认为这些行是相同的,只是将其余行视为已添加或已删除的行,因此得出的差异为完全无法使用.就我而言,file1中的第i行始终与file2中的第i行相对应,因此vimdiff不会发现添加或删除行.

以下是一个小示例,其中有两个文件,每个文件包含两个变量的值,每次三个. Vimdiff错误地将file1/line1与file2/line3匹配,并认为它周围的某些行已添加或删除.差异(减去颜色)如下所示:

              |  1 foo 8.1047  < del/new
              |  2 bar 6.2343  < del/new
1 foo 0.0000  |  3 foo 0.0000  < match
2 bar 5.3124  |  4 bar 1.4452  < wrong
3 foo 4.5621  |                < new/del
4 bar 6.3914  |                < new/del
5 foo 1.0000  |  5 foo 1.0000  < match
6 bar 6.3212  |  6 bar 7.2321  < wrong

但是,我想要的是以下内容,除匹配的第5行外,所有行均标记为错误:

1 foo 0.0000  |  1 foo 8.1047 < wrong
2 bar 5.3124  |  2 bar 6.2343 < wrong
3 foo 4.5621  |  3 foo 0.0000 < wrong
4 bar 6.3914  |  4 bar 1.4452 < wrong
5 foo 1.0000  |  5 foo 1.0000 < match
6 bar 6.3212  |  6 bar 7.2321 < wrong

解决方案

如何使用 diffchar.vim 插件?它在非差异模式下逐行比较.请在2个窗口中打开2个文件,然后按F7键.默认情况下,它会尝试按行中的字符查找差异,但是您可以更改差异单位,单词或其他内容.

How do I force vimdiff to always compare two files line-by-line without identifying added or deleted lines?

The problem is that if the diff between two files is large, but by chance two lines in the file match up, vimdiff thinks these lines are the same and just treats the rest as added or deleted lines, and the resulting diff is totally unusable. In my case, line i in file1 always corresponds to line i in file2, so vimdiff has no business finding added or deleted lines.

Following is a small example with two files containing the values of two variables three times each. Vimdiff erroneously matches up file1/line1 with file2/line3 and thinks some lines around it have been added or deleted. The diff (minus colors) then looks like this:

              |  1 foo 8.1047  < del/new
              |  2 bar 6.2343  < del/new
1 foo 0.0000  |  3 foo 0.0000  < match
2 bar 5.3124  |  4 bar 1.4452  < wrong
3 foo 4.5621  |                < new/del
4 bar 6.3914  |                < new/del
5 foo 1.0000  |  5 foo 1.0000  < match
6 bar 6.3212  |  6 bar 7.2321  < wrong

What I want, however, is the following, with all lines marked as wrong except for the matching lines 5:

1 foo 0.0000  |  1 foo 8.1047 < wrong
2 bar 5.3124  |  2 bar 6.2343 < wrong
3 foo 4.5621  |  3 foo 0.0000 < wrong
4 bar 6.3914  |  4 bar 1.4452 < wrong
5 foo 1.0000  |  5 foo 1.0000 < match
6 bar 6.3212  |  6 bar 7.2321 < wrong

解决方案

How about using diffchar.vim plugin? It compares line-by-line in non-diff mode. Please open 2 files on 2 windows and then just press F7. By default, it tries to find the differences by characters in a line, but you can change the difference units, words or something.

这篇关于vimdiff:强制逐行比较(忽略据说丢失/增加的行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆