tags:

views:

743

answers:

1

Hello.

I'm using vim -d file1 file2 in order to see they difference. All works fine, but i want to ignore whitespace changes - they are irrelevant for source code files. vim help states that following command will do the magic:

set diffopt+=iwhite

But, unfortunately, this command only adds '-b' to diff tool command line, that only ignores trailing white spaces. The correct command line key for diff must be '-w' that ignores all white space changes. But i can't find how to modify diff command line directly from vim. Of course i can compile custom diff or replace diff with diff.sh/diff.but, but that looks kinda ugly :(. Is i a more correct way to modify how vim interacts with diff tool for displaying file difference?

+5  A: 

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
ire_and_curses