让gVim的vimdiff忽略大小写

编程入门 行业动态 更新时间:2024-10-08 22:55:52
本文介绍了让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:

vimdoc.sourceforge/htmldoc/options.html #%27diffopt%27

更多推荐

让gVim的vimdiff忽略大小写

本文发布于:2023-11-11 08:30:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小写   gVim   vimdiff

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!