Question

In my project regression settings, output file have statement like

    "diff between foo.txt and bar.txt found" 

Now I need to take vimdiff between foo.txt and bar.txt. Can I do it from output file opened in vim only?

currently I need to first open my output file in vim. Then I need to select line specifying diff found. after it return to shell. then take vimdiff b/w this files.

Was it helpful?

Solution

If you had no file opened or an unmodified buffer:

 :edit file1.txt
 :vert diffsplit file2.txt

To open diffs in a new tab,

 :tabedit file1.txt
 :vert diffsplit file2.txt

would be very convenient


To get things automated, I'd consider

diffprogram | grep -w '^diff between' | grep 'found$' | 
while read diff between file1 and file2 found;
do
    gvim -d "$file1" "$file2"
done

Notes:

  • doesn't work for filenames with speciall characters (notably whitespace)
  • To open all these vims simultaneously, just add &: gvim -d "$file1" "$file2"&

You can also get all diffs to open in separate tabs in a single vim:

    gvim --servername GVIM --remote-silent +"tabedit $file1" +"vert diffsplit $file2"

OTHER TIPS

You can do it without opening any new vim instance using the following function:

function s:OpenDiff()
    let line=getline('.')
    let match=matchlist(line, '\v^\ {4}\"diff\ between\ (.{-})\ and\ (.{-})\ found\"\ $')[1:2]
    if empty(match)
        throw 'Incorrect line:' line
    endif
    execute 'tabedit'   fnameescape(match[0])
    execute 'diffsplit' fnameescape(match[1])
endfunction
nnoremap ,od :<C-u>call <SID>OpenDiff()<CR>

If you add set bufhidden=wipe after each of execute statements you will be able to get rid of opened buffers by running :tabclose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top