4

When diffing two files in vim (e.g. vim -d file1 file2), I want all whitespace to be ignored.

I almost achieved this by following the advice of Adam Katz in this question: Is there a way to configure vimdiff to ignore ALL whitespaces?

That advice causes the diff command to get the -w option, so that it doesn't include lines with only whitespace differences in the results.

If there's a line with both whitespace differences and non-whitespaces differences, then these are correctly returned by diff. But vim highlights the whitespace as a difference too.

E.g. If the two lines being diffed are:

File 1: a,b,c,d
File 2: a, b, c, e

Then the highlighted diff will be b, c, e instead of my desired e.

Is there any way to tell vim to ignore whitespace in its highlighting process?

I'm using vim 7.3 (gvim).

Community
  • 1
  • 1
Bjorn
  • 43
  • 1
  • 3

2 Answers2

2

diff operates on lines, not characters or words, so -b and -w determine which lines to ignore. If a line is not ignored, which is the case whenever non-whitespace changes are involved (unless you ignore case or explicitly ignore lines matching some regex), diff will always output something like this:

1c1
< a,b,c,d
---
> a, b, c, e

Altering diffopt or even diffexpr only affects how Vim invokes diff, not how it then processes the diff it receives. Since neither -b nor -w will change the above diff, Vim will consequently display the same result. Thus what you're looking for is a way to change how exactly Vim highlights the diff it receives, which I don't believe is possible.

Nikita Kouevda
  • 5,508
  • 3
  • 27
  • 43
  • I guess you're right that this isn't possible. At least not in the current version of Vim. Thanks – Bjorn Aug 28 '13 at 11:52
0

File 1 = f1, File 2 = f2

What about removing the whitespace in another tempfile?

vim -c "s/\s//g" -c "wq! f2.tmp" f2

then

vimdiff f1 f2.tmp
Kevin Lee
  • 718
  • 6
  • 19
  • This is an interesting workaround. It might work well in some cases, but would make reading / understanding the context of the change more difficult. Thanks! – Bjorn Aug 02 '13 at 09:14