Getting gVim's vimdiff to ignore case

社会主义新天地 提交于 2019-12-05 16:42:20

问题


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

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

Why? What can I do?

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

回答1:


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.

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




回答2:


Following works well for me:

vimdiff +"set diffopt+=icase"  file_1.txt file_2.txt


来源:https://stackoverflow.com/questions/4830171/getting-gvims-vimdiff-to-ignore-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!