Am 20.03.2011 06:52, schrieb Ben Schmidt:
> 
> No, I don't think you can. Late in that thread there is a workaround for
> that, which basically works by using 'diffexpr' to 'intercept' the files
> on their way to diff and remove the parts of the lines you don't want to
> compare (in your case, everything after the timestamp).
>

I knew I'd feel stupid. I was just wrong why :-)

Ok, thanks. I still have a little trouble getting my diffexpr right.
Here is what I have done.

Based on vim's diffexpr in my installation (vim 7.3 on Windows 7 64-bit)
and after some experiments I came up with this:

set diffexpr=LogDiff()
function! LogDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif

  if !exists("s:call_count")
    let s:call_count = 0
  endif
  let s:call_count = s:call_count + 1

  execute "split " . arg1
  " %s/^\(.\{3}\).*$/\1/
  write
  execute "write! diff_in" . "_" . s:call_count
  bwipeout

  execute "split " . arg2
  " %s/^\(.\{3}\).*$/\1/
  write
  execute "write! diff_new" . "_" . s:call_count
  bwipeout

  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' .
arg3 . eq
endfunction

My "vim diff test" files vdt0, vdt1, and vdt2 look like this:

vdt0                 vdt1                 vdt2

000 0 random text    000 0 random text    000 0 random text
001 0 random text    000 1 random text    000 1 random text
002 0 random text    001 0 random text    000 2 random text
003 0 random text    001 1 random text    001 0 random text
004 0 random text    002 0 random text    001 1 random text
005 0 random text    002 1 random text    001 2 random text
006 0 random text    003 0 random text    002 0 random text
007 0 random text    003 1 random text    002 1 random text
008 0 random text    004 0 random text    002 2 random text
009 0 random text    004 1 random text    003 0 random text
...                  ...                  ...

The counter in the first column goes up to 99 in all three test files,
i.e. vdt0 has 100 lines and vdt2 has 300 lines. 'random text' is
actually random text...

Now, if I open vim on vdt0 and vdt1 and do :windo diffthis with the
substite command commented out, then
 - a Windows shell window pops up twice (!) with the call to cmd.exe and
briefly prints 'shell returned 1' before closing
 - I get four (!) output files: diff_in_1 and diff_new_1 only contain
one line, 'line1' and 'line2' respectively. diff_in_2 and diff_new_2
have the same contents as vdt0 and vdt1
 - vim shows the differences between vdt0 and vdt1. Due to the random
text, there is plenty of it - more than I would like to see highlighted
in my log files, really

But when I uncomment the substitute commands
 - there is no 'shell returned 1'
 - I only get two output file diff_in_1 and diff_new_1, both containing
just one line 'lin'
 - vim warns me that it can't create a difference ("E97 Kann keine
Differenz erstellen")
 - the text in both vim buffers is folded (100 lines in the first, 200
lines in the second buffer), no difference, no timestamp scrolling

There are probably many things I still have to learn about vim and vim
scripting. E.g, where do the one-line output files come from? What's
wrong with the substitutions?

Thanks,
Malte

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to