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

调整VS Code中Rust可变变量下划线的位置

解决VS Code中Rust可变变量下划线干扰问题

调整下划线位置

可以通过VS Code的自定义令牌颜色配置,修改可变变量下划线的偏移量,避免和下一行内容重叠:

  1. 打开VS Code设置界面(快捷键Ctrl+,或Cmd+,)
  2. 点击界面右上角的{}图标,打开settings.json文件
  3. 添加以下配置,根据需求调整text-underline-offset的数值(负数表示向上偏移):
"editor.tokenColorCustomizations": {
    "[你的主题名称]": { // 示例:"[One Dark Pro]",留空则应用到所有主题
        "textMateRules": [
            {
                "scope": "variable.other.mutable.rust",
                "settings": {
                    "textDecoration": "underline; text-underline-offset: -2px;"
                }
            }
        ]
    }
}

提示:当前主题名称可在设置中搜索workbench.colorTheme查看。

替换为其他高亮样式

如果调整位置效果不理想,也可以将下划线替换为加粗、背景高亮或斜体:

加粗+斜体

"editor.tokenColorCustomizations": {
    "[你的主题名称]": {
        "textMateRules": [
            {
                "scope": "variable.other.mutable.rust",
                "settings": {
                    "fontStyle": "bold italic"
                }
            }
        ]
    }
}

背景高亮

"editor.tokenColorCustomizations": {
    "[你的主题名称]": {
        "textMateRules": [
            {
                "scope": "variable.other.mutable.rust",
                "settings": {
                    "background": "#ffeb3b33" // 半透明黄色,可自行调整颜色值
                }
            }
        ]
    }
}

仅加粗

"editor.tokenColorCustomizations": {
    "[你的主题名称]": {
        "textMateRules": [
            {
                "scope": "variable.other.mutable.rust",
                "settings": {
                    "fontStyle": "bold"
                }
            }
        ]
    }
}

注意:若variable.other.mutable.rust这个文本范围不生效,可按下Ctrl+Shift+P(或Cmd+Shift+P)执行「Developer: Inspect Editor Tokens and Scopes」,点击可变变量查看准确的scope值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 12:25:41