强制diff/vimdiff调整行比较

Force diff/vimdiff to adjust line comparison

我正在使用 vimdiff 比较几个文件的差异。在这种情况下,一个文件有 11 行描述该文件的注释,而另一个文件没有注释行。我很惊讶 vimdiff (而不是底层 'diff' )没有准确地分配要比较的行,所以每一行都是不同的。在这种情况下,第一个文件的第 12 行应该与第二个文件的第 1 行进行比较。

问题:有没有办法调整vimdiff(或基础diff)比较的行(例如,向下移动12),不修改文件?

非常感谢您的帮助。

以下是文件的初始行:

文件 1(包括评论)

# This table shows the intersection of dark by MAPQ regions by a gene annotation gff3, showing where dark by MAPQ regions fall within gene body
# chrom : Chromosome of dark by MAPQ region
# region_start : start position of dark by MAPQ region within gene-body element
# region_end : end position of dark by MAPQ region within gene-body element
# gene_body_id : ID of gene body element that contains this dark by MAPQ region
# region_type : genebody element type (e.g. exon, intron, UTR, etc.)
# biotype : GENCODE biotype of gene that contains this dark by MAPQ reigon
# gene_body_chrom : Chromosome of the genebody element
# gene_body_start : start position of the genebody element
# gene_body_end : end position of the genebody element
#chrom  start   end gene_body_id    region_type biotype gene_body_chrom gene_body_start gene_body_end
1   11869   12227   DDX11L1_1   exon    transcribed_unprocessed_pseudogene  1   11869   12227
1   12228   12611   DDX11L1_intron_1    intron  transcribed_unprocessed_pseudogene  1   12228   12611
1   12612   12721   DDX11L1_2   exon    transcribed_unprocessed_pseudogene  1   12612   12721
1   12722   12751   DDX11L1_intron_2    intron  transcribed_unprocessed_pseudogene  1   12722   12973
1   12861   12973   DDX11L1_intron_2    intron  transcribed_unprocessed_pseudogene  1   12722   12973
1   13191   13219   DDX11L1_intron_3    intron  transcribed_unprocessed_pseudogene  1   13053   13219

文件 2(不包括注释)

chr1    11869   12227   DDX11L1_1   exon    transcribed_unprocessed_pseudogene  chr1    11869   12227
chr1    12228   12611   DDX11L1_intron_1    intron  transcribed_unprocessed_pseudogene  chr1    12228   12611
chr1    12612   12721   DDX11L1_2   exon    transcribed_unprocessed_pseudogene  chr1    12612   12721
chr1    12722   12752   DDX11L1_intron_2    intron  transcribed_unprocessed_pseudogene  chr1    12722   12973
chr1    12861   12973   DDX11L1_intron_2    intron  transcribed_unprocessed_pseudogene  chr1    12722   12973
chr1    13191   13219   DDX11L1_intron_3    intron  transcribed_unprocessed_pseudogene  chr1    13053   13219

VimDiff 结果

我使用 tail 想出了针对这种情况的解决方案,但我希望能够直接在 vimdiff 中修改它的解决方案。

# Skip the first 12 lines from file_1
vimdiff <(tail -n +12 file_1) file_2

我也遇到了同样的问题所以开发了https://github.com/rickhowe/spotdiff.vim。您必须指定行范围,但可以部分比较 2 个文件之间甚至单个文件中的任何行。您还可以select可视区域和文本对象进行比较。