有没有办法配置 vimdiff 以忽略所有空格? [英] Is there a way to configure vimdiff to ignore ALL whitespaces?

查看:36
本文介绍了有没有办法配置 vimdiff 以忽略所有空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 vim -d file1 file2 以查看它们之间的差异.这工作正常,但我想忽略空格更改 - 它们与源代码文件无关.

Vim 帮助说明以下命令将发挥作用:

set diffopt+=iwhite

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

是否有更好的方法来修改 Vim 与用于显示文件差异的 diff 工具的交互方式?

解决方案

是的.像您一样设置 iwhite 选项,但另外,将 diffexpr 设为空.

来自 vim 文档的相关部分:<块引用>

白色

忽略空白量的变化.添加-b"标志到diff"命令,如果'diffexpr' 为空.检查文档diff"命令的作用确切地.它应该忽略添加尾随空格,但不是前导空格.

另请注意,您可以通过设置 diffexpr 来提供自定义 diff 命令行.请参阅 vimdiff 手册页 上的讨论,特别是:

<块引用>

'diffexpr' 选项可以设置为使用标准之外的其他东西比较两个文件并找出差异的diff"程序.

当 'diffexpr' 为空时,Vim 使用此命令查找差异在文件 1 和文件 2 之间:

diff file1 file2 >输出文件

I'm using vim -d file1 file2 in order to see the differences between them. This works fine, but I want to ignore whitespace changes - they are irrelevant for source code files.

Vim help states that the following command will do the magic:

set diffopt+=iwhite

But unfortunately, this command only adds -b to diff tool command line, and that only ignores trailing whitespaces. The correct command line key for diff should be -w, to ignore all whitespace changes. But I can't find how to modify the diff command line directly from Vim. Of course I can compile a custom diff, or replace diff with diff.sh, but that looks kinda ugly :(.

Is there a better way to modify how Vim interacts with the diff tool for displaying file differences?

解决方案

Yes. Set the iwhite option as you did, but additionally, make diffexpr empty.

From the relevant section of the 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.

Note also that you can provide a custom diff command line by setting diffexpr. See the discussion on the vimdiff man page, in particular:

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:

diff file1 file2 > outfile

这篇关于有没有办法配置 vimdiff 以忽略所有空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆