有没有一种方法可以将vimdiff配置为忽略所有空格? [英] Is there a way to configure vimdiff to ignore ALL whitespaces?

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

问题描述

我正在使用vim -d 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帮助指出以下命令将起到神奇作用:

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

set diffopt+=iwhite

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

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 :(.

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

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

推荐答案

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

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

vim文档的相关部分中:

From the relevant section of the vim docs:

iwhite

iwhite

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

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手册页上的讨论,尤其是:

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

可以将'diffexpr'选项设置为使用非标准选项 "diff"程序比较两个文件并查找差异.

The 'diffexpr' option can be set to use something else than the standard "diff" program to compare two files and find the differences.

'diffexpr'为空时,Vim使用此命令查找差异 在file1和file2之间:

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

diff file1 file2 > outfile

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

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