【问题标题】:vim alternate color/shade of rows/lines based on grouping criteriavim 基于分组标准的行/行的交替颜色/阴影
【发布时间】:2014-10-14 11:36:09
【问题描述】:

我有一个类似于 md5sum 输出的文件,即它包含以下形式的行/行:

9803f392bb3f89f1c20bbc9baec8483a /some/path/file1
9803f392bb3f89f1c20bbc9baec8483a /some/other/path/file1
4ca001c5586eb0744e3174bc75c6fba8 /a/certain/path/file2
4ca001c5586eb0744e3174bc75c6fba8 /another/path/file2
4ca001c5586eb0744e3174bc75c6fba8 /some/different/path/file2withadifferentname
78753e869231cc1417a92eebaa076718 /and/so/on/file3
78753e869231cc1417a92eebaa076718 /and/so/forth/file
78753e869231cc1417a92eebaa076718 /something/like/that

假设文件按照 md5sums 排序(即前 32 个字符)。我想在 vim 中查看此文件,并使用其他颜色的线条,以便将相同的颜色分配给具有相同 md5sum 的文件。

这可以被认为是基于某些条件对行进行分组的特殊情况(在这种情况下,与前一行相比,前 32 个字符中的条件是相同的字符串)。

我怎样才能做到这一点?

【问题讨论】:

    标签: vim colors highlighting


    【解决方案1】:

    多行匹配的语法高亮可能会很昂贵并且会显着降低 Vim 的速度;另外,我不知道如何获得这种交替效果。但是很容易定义具有相同校验和的行的折叠:

    :setlocal foldmethod=expr foldexpr=matchstr(getline(v:lnum),'^\\x\\+')==matchstr(getline(v:lnum+1),'^\\x\\+')?1:'<1'
    

    详情请见:h fold-expr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2015-07-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 2010-10-09
      相关资源
      最近更新 更多