vimdiff: how to ignore all same lines and show ONLY diff lines?

5,634 views
Skip to first unread message

ping

unread,
Dec 7, 2012, 11:50:17 PM12/7/12
to vim...@googlegroups.com
exports:
by default vimdiff will not only show the diff lines, but also show a
couple of same lines to give you a sense of context.
how to suppress all same lines and display only those diff lines?

regards
ping

Tony Mechelynck

unread,
Dec 8, 2012, 12:14:17 AM12/8/12
to vim...@googlegroups.com
see
:help 'diffopt' " context:{n}
:help fold-diff


Best regards,
Tony.
--
If you push the "extra ice" button on the soft drink vending machine,
you won't get any ice. If you push the "no ice" button, you'll get
ice, but no cup.

Roy Fulbright

unread,
Dec 8, 2012, 12:20:22 AM12/8/12
to Vim User Group
> Date: Fri, 7 Dec 2012 23:50:17 -0500
> From: songpi...@gmail.com
> To: vim...@googlegroups.com
> Subject: vimdiff: how to ignore all same lines and show ONLY diff lines?
> --
> 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

Add the following line to .vimrc:
set diffopt=filler,context:0
 

ping

unread,
Dec 8, 2012, 12:58:09 AM12/8/12
to vim...@googlegroups.com, Roy Fulbright
thanks Roy (and Tony), that really works!

now I still feel that is a big weak comparing to what I wanted achieve:

say I have these 2 captures from the devices:

  Multicast routing enabled               Multicast routing enabled                                                   
  Use Framed Routes = disabled                    Use Framed Routes = disabled                                                

  In Received Packets 10, Bytes 1000              In Received Packets 15, Bytes 150                                           
    Unicast Packets 10, Bytes 1000                  Unicast Packets 15, Bytes 150                                             
    Multicast Packets 0, Bytes 0                    Multicast Packets 1, Bytes 54                                             
  In Policed Packets 0, Bytes 0                   In Policed Packets 0, Bytes 0                                               
  In Error Packets 0                              In Error Packets 0                                                          
  In Invalid Source Address Packets 0             In Invalid Source Address Packets 0                                         
  In Discarded Packets 0                          In Discarded Packets 0                                                      
  Out Forwarded Packets 100, Bytes 10000          Out Forwarded Packets 150, Bytes 15000                                      
    Unicast Packets 100, Bytes 10000                Unicast Packets 150, Bytes 15000                                          
    Multicast Routed Packets 0, Bytes 0             Multicast Routed Packets 0, Bytes 0                                       
  Out Scheduler Dropped Packets 0, Bytes 0        Out Scheduler Dropped Packets 0, Bytes 0                                    
  Out Policed Packets 0, Bytes 0                  Out Policed Packets 0, Bytes 0                                              
  Out Discarded Packets 0                         Out Discarded Packets 0                                                     



with above solution now I can focus on lines with an increased counter(s).
But quite often I need to manually calculate the "delta" amount of those counters.
so instead of just mark the diff lines, ideally if I can have the 2nd diff window displaying only the delta of those counters whenever there is any difference

29   In Received Packets 10, Bytes 1000          29   In Received Packets 5, Bytes 500         
30     Unicast Packets 10, Bytes 1000                   30     Unicast Packets 5, Bytes 500           
31     Multicast Packets 0, Bytes 0                     31     Multicast Packets 1, Bytes 54          
32 +--  4 lines: In Policed Packets 0, Bytes 0          32 +--  4 lines: In Policed Packets 0, Bytes 0
36   Out Forwarded Packets 100, Bytes 10000             36   Out Forwarded Packets 50, Bytes 5000     
37     Unicast Packets 100, Bytes 10000                 37     Unicast Packets 50, Bytes 5000         

I don't find existing functions/scripts (say script 3745 or 3075) can do that for me,
is that possible ?


Roy Fulbright

unread,
Dec 8, 2012, 2:01:55 AM12/8/12
to Vim User Group

Date: Sat, 8 Dec 2012 00:58:09 -0500
From: songpi...@gmail.com
To: vim...@googlegroups.com
CC: rful...@hotmail.com
Subject: Re: vimdiff: how to calculate "delta" for digits in different lines?
The easiest way I found to calculate and display the delta of lines that differ is to write a short Perl program:
 
#!/usr/bin/perl
use strict;
use warnings;
my $file1 = "diff1.txt";
my $file2 = "diff2.txt";
open(my $fh1,'<', $file1) or die "Error opening $file1: $!\n";
open(my $fh2,'<', $file2) or die "Error opening $file2: $!\n";
while ( !eof($fh1) && !eof($fh2) ) {
    my $t1 = <$fh1>;
    my $t2 = <$fh2>;
    chomp $t1;
    chomp $t2;
    if ($t1 ne $t2) {
        my ($p1,$b1) = $t1 =~ /(\d+).*?(\d+)/;
        my ($p2,$b2) = $t2 =~ /(\d+).*?(\d+)/;
        my $pdelta = $p2 - $p1;
        my $bdelta = $b2 - $b1;
        print pack("A42",$t1), pack("A42",$t2), "$pdelta  $bdelta\n";
    }
}


ping

unread,
Dec 8, 2012, 10:47:19 AM12/8/12
to vim...@googlegroups.com, Roy Fulbright
On 12/8/2012 2:01 AM, Roy Fulbright wrote:
> The easiest way I found to calculate and display the delta of lines
> that differ is to write a short Perl program:
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my $file1 = "diff1.txt";
> my $file2 = "diff2.txt";
> open(my $fh1,'<', $file1) or die "Error opening $file1: $!\n";
> open(my $fh2,'<', $file2) or die "Error opening $file2: $!\n";
> while ( !eof($fh1) && !eof($fh2) ) {
> my $t1 = <$fh1>;
> my $t2 = <$fh2>;
> chomp $t1;
> chomp $t2;
> if ($t1 ne $t2) {
> my ($p1,$b1) = $t1 =~ /(\d+).*?(\d+)/;
> my ($p2,$b2) = $t2 =~ /(\d+).*?(\d+)/;
> my $pdelta = $p2 - $p1;
> my $bdelta = $b2 - $b1;
> print pack("A42",$t1), pack("A42",$t2), "$pdelta $bdelta\n";
> }
> }
Many thanks Roy!
this remind me that external tool can be used/created here but still
called from inside vim if one (I) is not capable of making complex vim
script...

regards
ping

Gary Johnson

unread,
Dec 9, 2012, 3:09:45 AM12/9/12
to vim...@googlegroups.com
On 2012-12-08, ping wrote:
> On 12/8/2012 2:01 AM, Roy Fulbright wrote:
> >The easiest way I found to calculate and display the delta of lines
> >that differ is to write a short Perl program:

> Many thanks Roy!
> this remind me that external tool can be used/created here but still
> called from inside vim if one (I) is not capable of making complex
> vim script...

Using a Vim script is not always the best solution, even if you are
a Vim expert. In this case, I think that an external script written
some language such as Perl or awk that is designed for such tasks is
a better choice than a Vim script.

Regards,
Gary

Reply all
Reply to author
Forward
0 new messages