让gVim的vimdiff忽略大小写

让gVim的vimdiff忽略大小写

本文介绍了让gVim的vimdiff忽略大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较两个汇编文件,其中一个用大写字母写,另一个用小写字母写.直到大小写和空白为止,许多行都是相同的.

I am trying to compare two assembly files where one was written all caps and the other in lowercase. Many lines are identical up to case and whitespace.

我尝试了以下操作,而两个缓冲区处于差异模式:

I tried the following, while two buffers in diff mode:

:set diffopt+=icase
:set diffopt+=iwhite
:diffupdate

空白事物似乎工作良好,但忽略大小写则无法正常工作.例如,在以下两行中:

The whitespace thing seems to work well, but the ignore case does not do its work. For example, in the following two lines:

            I0=R0;              // ADDRESS OF INPUT ARRAY

    i0 = r0;            // address of input array

[第一行以12个空格开头,第二行以单个制表符]

[the first line begins with 12 spaces, the second with a single tab]

为什么?我该怎么办?

更新:只是注意到这两行中的所有差异都被忽略了,好吧:

UPDATE: just noticed that in these two lines all differences were ignored OK:

                                // MULTIPLY R1 BY 4 TO FETCH DATA OF WORD LENGTH
                        // multiply r1 by 4 to fetch data of word length

推荐答案

您的比较失败的原因是空格,而不是大小写.发生这种情况的原因是,当您使用iwhite选项时,在后台,vimdiff正在执行diff -b,这比起您要查找的内容对空白比较方式的限制更多.更具体地说,-b选项仅忽略空白处已经存在空白处的差异.在您的示例中,i0 = r0;被标记为与I0=R0;不同,因为一个字符之间包含空格,而另一个字符之间不包含空格.

Your comparison is failing because of the whitespace, not because of the case. This is happening because when you use the iwhite option, in the background, vimdiff is executing a diff -b which is more restrictive about how it compares whitespace than what you're looking for. More specifically, the -b option only ignores differences in the amount of whitespace where there already is whitespace. In your example, i0 = r0; is being flagged as different than I0=R0; because one contains whitespace between the characters and the other doesn't.

根据vimdiff文档,可以通过将diffexpr设置为非空值来覆盖iwhite选项的默认行为.您感兴趣的diff标志是--ignore-all-space,它在空白方面更加灵活.您可以在vimdiff中将diffexpr更改为使用此选项,而不是默认的-b选项,如下所示:

According to the vimdiff documentation, you can override the default behavior of the iwhite option by setting diffexpr to a non-empty value. The diff flag that you're interested in is --ignore-all-space, which is more flexible about whitespace. You can change the diffexpr in vimdiff to use this option instead of the default -b option as follows:

set diffexpr=MyDiff()
function MyDiff()
   let opt = ""
   if &diffopt =~ "icase"
     let opt = opt . "-i "
   endif
   if &diffopt =~ "iwhite"
     let opt = opt . "--ignore-all-space "
   endif
   silent execute "!diff -a --binary " . opt . v:fname_in . " " . v:fname_new .
    \  " > " . v:fname_out
endfunction

有关更多详细信息,请参阅文档:

See the documentation for more details:

http://vimdoc.sourceforge.net/htmldoc/options.html #%27diffopt%27

这篇关于让gVim的vimdiff忽略大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:28