Getting gVim's vimdiff to ignore case

微笑、不失礼 提交于 2019-12-04 01:26:18

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

Following works well for me:

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