You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改monaco-editor中的行号颜色?

修改Monaco Editor行号颜色的方法

要修改行号颜色,直接在你定义主题的colors配置中添加对应的颜色属性即可:

  • 普通行号颜色:使用editorLineNumber.foreground
  • 当前选中行的行号颜色:使用editorLineNumber.activeForeground

修改后的主题代码如下:

monaco.editor.defineTheme('my-dark', {
    base: 'vs-dark',
    inherit: true,
    rules: [
        { token: 'global', foreground: '84d6f7', fontStyle: "bold" },
        { token: 'keyword', foreground: 'f86d7c', fontStyle: "bold" },
        { token: 'comment', foreground: '666666' },
        { token: 'number', foreground: 'fcc600' },
        { token: 'string', foreground: 'ffc43a' },
    ],
    colors: {
        "editor.background": '#191919',
        // 设置普通行号颜色
        "editorLineNumber.foreground": '#888888',
        // 设置当前选中行的行号颜色
        "editorLineNumber.activeForeground": '#ffffff'
    }
});

你可以根据需求替换上面的十六进制颜色值,保存后重新加载主题就能看到行号颜色的变化。

内容的提问来源于stack exchange,提问作者RodrigerScroge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 06:09:25