3

When comparing two files with same content but with line endings, vim diff does not detect the difference. Is there a way to make vimdiff show the difference.

smbatpetrosyan
  • 609
  • 1
  • 6
  • 11
  • https://unix.stackexchange.com/questions/45711/diff-reports-two-files-differ-although-they-are-the-same here some solutions for diff tool are suggested, but I'd like to do the same with vimdiff – smbatpetrosyan Jan 16 '19 at 09:05

1 Answers1

9

When file(s) have inconsistent (dos vs. unix) line endings, Vim will detect them as unix, and lines will show trailing CR (^M), also in a diff.

What you describe (no changes detected) happens when one file consistently uses dos, and the other consistently uses unix line endings. Vim then "abstracts away" the consistent line endings in the :help 'fileformat' option value.

Some users put the 'fileformat' value into the 'statusline', and use that to notice the discrepancy. (I do this with a conditional to only show it if it differs from the platform's default.)

If you want to show line ending differences inside the diff itself, you can force the 'fileformat' to unix, either when starting:

$ vimdiff --cmd 'set fileformats=unix' file1 file2

or inside Vim:

:windo e! ++ff=unix
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • 2
    The vimdiff command line is the first hard argument (I experienced) for "never put `set nocompatible` into your `vimrc`". – Ralf Jan 16 '19 at 13:00
  • 2
    @user7369280: That's right; that indeed would revert settings like `'fileformats'`. If a vimrc exists, Vim will switch to nocompatible, anyway. Despite this, people (often out of superstition or ignorance) put this in. – Ingo Karkat Jan 16 '19 at 15:33