vscode 插件 分享-Highlight 高亮任意代码

vscode 插件 分享-Highlight 高亮任意代码

插件链接

Advanced text highlighter based on regexes. Useful for todos, annotations, colors etc.

适合用于标记某些代码, 或者自定义高亮代码.

与其他类似的插件(TODO Highlight, Better Comments, Todo+)等相比, Highlight为正则匹配, 更具有灵活性.

安装

点此链接 –> Install

或 运行以下命令行

ext install fabiospampinato.vscode-highlight

使用规则

不同的正则需要写在配置文件里(settings.json)

  1. Regexes need to be double-escaped, once for JSON and the second time for the regex itself.
  2. All characters of the matched string must be wrapped in a capturing group.
  3. For each capturing group a decorations options object must be provided (empty decorations are allowed: {}), otherwise the actual decorations will be misaligned.
  4. Nested capturing groups are not supported.
  5. If you want to match the start/end of a line make sure the regex has the “m” (multiline) flag.

大致意思:

  1. 正则需要双转义才能正确匹配到. 如匹配(需要写成 \\(
  2. 匹配串必须是捕获状态. 如匹配“.*TODO”, 需要写成 (.*TODO), 即用()包裹
  3. 每个捕获组都需要提供装饰参数. 也就是说有几个()捕获组, “decorations”字段的长度就是几
  4. 不支持嵌套捕获组
  5. 如果使用^$匹配行首或行尾, 需要开启多行标记: m flag

“decorations”装饰参数可以见VS Code API

演示示例

"highlight.regexes": {
  "(// ?TODO:?)(.*)": [
    {
      "overviewRulerColor": "#ffcc00",
      "backgroundColor": "#ffcc00",
      "color": "#1f1f1f",
      "fontWeight": "bold"
    },
    {
      "backgroundColor": "#d9ad00",
      "color": "#1f1f1f"
    }
  ],
  "(// ?FIXME:?)(.*)": [
    {
      "overviewRulerColor": "#ff0000",
      "backgroundColor": "#ff0000",
      "color": "#1f1f1f",
      "fontWeight": "bold"
    },
    {
      "backgroundColor": "#d90000",
      "color": "#1f1f1f"
    }
  ],
  "(// )(@\\w+)": [
    {},
    {
      "color": "#4de0ff"
    }
  ]
}

效果请添加图片描述
请添加图片描述

应用

rust语言为例. rust 代码中有一些方法是unstable的, 这些方法需要弄night版才能正确使用. 我们可以把#[unstable]所在行全部高亮, 这样在使用方法时可以快速避开这些方法.

"(.*#\\[)(unstable)(\\(.*?\\)])": {
    "filterLanguageRegex": "rust",
    "decorations": [
        {
            "overviewRulerColor": "#D32F2F",
            "backgroundColor": "#FF5722",
            "color": "#FAFAFA",
        },
        {
            "backgroundColor": "#D32F2F",
            "color": "#FAFAFA",
            "fontWeight": "bold"
        },
        {
            "backgroundColor": "#FF5722",
            "color": "#FAFAFA",
        }
    ]
},

效果:

在这里插入图片描述

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值