微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法配置vimdiff忽略所有空白?

我使用vim -d file1 file2为了看到他们之间的差异。这工作正常,但我想忽略空白更改 – 它们与源代码文件无关。

Vim帮助说明以下命令会做的魔法:

set diffopt+=iwhite

但不幸的是,此命令只添加-b到diff工具命令行,并且只会忽略结尾的空格。 diff的正确命令行键应为-w,以忽略所有空格更改。但我找不到如何直接从Vim修改diff命令行。当然我可以编译一个自定义diff,或者用diff.sh替换diff,但是看起来有点丑陋:(。

有没有更好的方法修改Vim如何与差异工具进行交互以显示文件差异?

是。像你一样设置iwhite选项,但另外,使diffexpr为空。

vim docs的相关部分:

iwhite

Ignore changes in amount of white space. Adds
the “-b” flag to the “diff” command if
‘diffexpr’ is empty. Check the documentation
of the “diff” command for what this does
exactly. It should ignore adding trailing
white space,but not leading white space.

还要注意,您可以通过设置diffexpr提供一个自定义diff命令行。参见关于vimdiff man page的讨论,特别是:

The ‘diffexpr’ option can be set to use something else than the standard
“diff” program to compare two files and find the differences.

When ‘diffexpr’ is empty,Vim uses this command to find the differences
between file1 and file2:

06000

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐