Is there a way to configure vimdiff to ignore whitespace on lines that have a non-whitespace diff?

StackOverflow https://stackoverflow.com/questions/17997108

  •  04-06-2022
  •  | 
  •  

Domanda

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).

È stato utile?

Soluzione

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.

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top