vscode 配置代码颜色风格类似idea

VSCode Java 语法高亮配置 - 仿 IDEA Darcula 主题

在 VSCode 中实现接近 IntelliJ IDEA Darcula 主题的 Java 语法高亮效果。

依赖:

  • JetBrains Mono 字体
  • Better Comments 插件(可选,用于 TODO 高亮)

特性:

  • 静态成员斜体显示
  • Javadoc /** */ 与内容统一绿色
  • TODO/FIXME 独立高亮
  • 完整的 Semantic Token + TextMate 双层配置

配置如下

json 复制代码
{
    "java.compile.nullAnalysis.mode": "automatic",
    "editor.fontSize": 14,
    "editor.fontWeight": 400,
    "editor.fontFamily": "JetBrains Mono",

    // Better Comments 插件配置 (需安装插件)
    "better-comments.tags": [
        { "tag": "TODO", "color": "#A8C023", "strikethrough": false, "underline": false, "bold": false, "italic": false },
        { "tag": "FIXME", "color": "#FF6B68", "strikethrough": false, "underline": false, "bold": false, "italic": false }
    ],

    // Semantic Token 颜色 (语义级别,优先级高于 TextMate)
    "editor.semanticTokenColorCustomizations": {
        "enabled": true,
        "rules": {
            "class": "#A9B7C6",              // 类名
            "interface": "#A9B7C6",          // 接口名
            "enum": "#A9B7C6",               // 枚举名
            "typeParameter": "#A9B7C6",      // 泛型参数
            "type": "#A9B7C6",               // 类型
            "namespace": "#A9B7C6",          // 命名空间
            "function": "#FFC66D",           // 函数
            "method": "#FFC66D",             // 方法
            "function.static": { "foreground": "#FFC66D", "fontStyle": "italic" },
            "method.static": { "foreground": "#FFC66D", "fontStyle": "italic" },
            "variable": "#A9B7C6",           // 变量
            "variable.readonly": { "foreground": "#9876AA", "fontStyle": "italic" },
            "parameter": "#A9B7C6",          // 参数
            "property": "#9876AA",           // 属性/字段
            "property.static": { "foreground": "#9876AA", "fontStyle": "italic" },
            "enumMember": { "foreground": "#9876AA", "fontStyle": "italic" },
            "keyword": "#CC7832",            // 关键字
            "string": "#6A8759",             // 字符串
            "number": "#6897BB",             // 数字
            "comment": "#808080",            // 注释
            "regexp": "#6A8759",             // 正则
            "decorator": "#BBB529",          // 装饰器
            "annotation": "#BBB529"          // 注解
        }
    },

    // TextMate 规则 (词法级别)
    "editor.tokenColorCustomizations": {
        "textMateRules": [
            // 普通注释 (灰色)
            { "scope": ["comment", "comment.line", "comment.block"], "settings": { "foreground": "#808080" } },
            // TODO/FIXME 标记 (嫩绿)
            { "scope": "keyword.codetag.notation", "settings": { "foreground": "#A8C023" } },
            // Javadoc 注释 (绿色斜体,包含 /** 和 */)
            {
                "scope": [
                    "comment.block.documentation",
                    "comment.block.javadoc",
                    "comment.block.documentation.java",
                    "comment.block.documentation.java punctuation.definition.comment.java",
                    "comment.block.javadoc punctuation.definition.comment.java"
                ],
                "settings": { "foreground": "#629755", "fontStyle": "italic" }
            },
            // 关键字 (橙色)
            { "scope": ["keyword", "keyword.control", "keyword.operator.new", "storage.modifier"], "settings": { "foreground": "#CC7832" } },
            // 字符串 (绿色)
            { "scope": ["string", "string.quoted"], "settings": { "foreground": "#6A8759" } },
            // 转义字符 (橙色)
            { "scope": "constant.character.escape", "settings": { "foreground": "#CC7832" } },
            // 数字 (蓝色)
            { "scope": "constant.numeric", "settings": { "foreground": "#6897BB" } },
            // 函数/方法名 (黄色)
            { "scope": ["entity.name.function", "support.function"], "settings": { "foreground": "#FFC66D" } },
            // 类型名 (浅灰)
            { "scope": ["entity.name.type", "entity.name.type.class", "entity.name.type.interface"], "settings": { "foreground": "#A9B7C6" } },
            // 常量/枚举成员 (紫色斜体)
            { "scope": ["variable.other.constant", "variable.other.enummember"], "settings": { "foreground": "#9876AA", "fontStyle": "italic" } },
            // 属性 (紫色)
            { "scope": "variable.other.property", "settings": { "foreground": "#9876AA" } },
            // 注解 (黄色)
            { "scope": ["meta.annotation", "punctuation.definition.annotation"], "settings": { "foreground": "#BBB529" } },
            // XML/HTML 标签 (黄色)
            { "scope": "entity.name.tag", "settings": { "foreground": "#E8BF6A" } },
            // 属性名 (浅灰)
            { "scope": "entity.other.attribute-name", "settings": { "foreground": "#A9B7C6" } },
            // JSON 属性名 (紫色)
            { "scope": "support.type.property-name", "settings": { "foreground": "#9876AA" } },
            // 标点符号 (浅灰)
            { "scope": "punctuation", "settings": { "foreground": "#A9B7C6" } },
            // 无效代码 (红色)
            { "scope": "invalid", "settings": { "foreground": "#FF6B68" } }
        ]
    }
}
相关推荐
CaracalTiger4 天前
什么是Clawdbot?Clawdbot下载、安装、配置教程(最新版Moltbot)
python·编辑器·aigc·idea·ai编程·intellij idea·agi
逍遥德6 天前
如何提高代码可读性
java·开发语言·性能优化·intellij idea·代码规范
SamRol6 天前
达梦数据库指令 及 在Spring Boot + MyBatis-Plus上的使用
java·数据库·spring boot·mybatis·达梦·intellij idea
韩立学长19 天前
【开题答辩实录分享】以《兴趣班预约管理系统的设计与实现》为例进行选题答辩实录分享
java·mysql·intellij idea
0和1的舞者19 天前
《#{} vs ${}:MyBatis 里这俩符号,藏着性能与安全的 “生死局”》
java·数据库·学习·mybatis·intellij idea·mybatis操作
黎雁·泠崖21 天前
Java入门篇之吃透基础语法(二):变量全解析(进制+数据类型+键盘录入)
java·开发语言·intellij-idea·intellij idea
黎雁·泠崖21 天前
Java入门之吃透基础语法:注释+关键字+字面量+变量全解析
java·开发语言·intellij-idea·intellij idea
黎雁·泠崖22 天前
Java入门篇之吃透基础语法(一):注释+关键字+字面量全解析
java·开发语言·intellij-idea·intellij idea
zhanglb1224 天前
Gradle 全局配置使用
gradle·android studio·intellij idea