I often have to compare two files with nearly identical
contents.
There two two kinds of changes, though:
There are tags, which are named after the name of the file.
And there are "true changes", which i am interested in.
Is it possible to instruct vim that way to not to mark
all lines which only differ in the tag's name?
Thank you very much in advance for any help!
Best regards,
mcc
It is not really Vim that needs to be instructed to do this, but diff.
Then you simply instruct Vim to pass the relevant option to diff using
diffexpr. On my system, diff supports an -I option which instructs it to
ignore changes to lines which match a particular pattern, so I would use
that, e.g.
set diffexpr=MyDiff()
function MyDiff()
let opt = "-I tagpattern"
if &diffopt =~ "icase"
let opt = opt . "-i "
endif
if &diffopt =~ "iwhite"
let opt = opt . "-b "
endif
silent execute "!diff -a --binary " .
\ opt . v:fname_in . " " . v:fname_new .
\ " > " . v:fname_out
endfunction
(Adapted from :help diff-diffexpr. It probably doesn't work with
filenames with spaces in them as it stands; it should have some
shellescape() calls in there or something, probably.)
HTH,
Ben.
Hi Ben,
thank you for the script and your help.
What can I do under WIN, where there is no diff?
Unfortunately I am not allowed to install cygwin on my
PC at work (or install anything)....
At home I will use your hint at once !
As I understand, now all lines are skipped, which contain
"tag" but what happens with those lines including a "real"
difference AND the "tag"?
Best regards,
mcc
Hi Ben,
...I ever thought, that there are two vimdiffs (intern + external)
as with grep.
I will check it out! Thank you :)
Best regards,
mcc
That's awkward.
I think, though, that Vim only parses the 'headers' of the diff output,
and doesn't actually look at the content. So one way you could deal with
this would be to remove all the tags before diffing them, and as long as
the line numbers don't change, it would still work. I think v:fname_in
and v:fname_new are always temporarly files when Vim uses 'diffexpr', so
you could even just alter these files in-place. (You'd better check
this, though!) Something like:
set diffexpr=MyDiff()
function MyDiff()
execute "split " . v:fname_in
s/tagpattern//
w
bwipeout
execute "split " . v:fname_new
s/tagpattern//
w
bwipeout
silent execute "!diff -a --binary " .
\ opt . v:fname_in . " " . v:fname_new .
\ "> " . v:fname_out
endfunction
It might work. But, of course, it will break if any one of my
assumptions above is incorrect, and most particularly, it will be
dangerous if I'm wrong about 'diffexpr' always using temporary files. So
tread carefully.
Ben.
Hi Ben,
thank you very much for your help!
I will check that out -- it will help me a lot! :)
Have a nice weekend!
Best regards,
mcc
If you are unable to install additional comparison utilities and still
need to compare files in a detailed fashion, there are a few
possibilities.
1. Open a CMD.EXE window, use the "fc" command. Works best on ascii files.
In the example below, "7" is deleted from file two, and 11 is added to it.
fc /l /n one two
Comparing files one and TWO
***** one
6: 6
7: 7
8: 8
***** TWO
6: 6
7: 8
*****
***** one
***** TWO
10: 11
*****
2. Although we'd rather use VIM and open source tools, on the subject
Windows machine where no additional software can be installed,
Microsoft Word is able to compare files and show differences at the
character level, if that is installed. Look for "Compare Documents"
in online Help.
Hopefully, you'll be able to install open source tools at some point.
If possible, Cygwin and PuttyCYG is a great combination.
========Keith