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" } }
        ]
    }
}
相关推荐
黎雁·泠崖21 小时前
Java入门篇之吃透基础语法(二):变量全解析(进制+数据类型+键盘录入)
java·开发语言·intellij-idea·intellij idea
黎雁·泠崖1 天前
Java入门之吃透基础语法:注释+关键字+字面量+变量全解析
java·开发语言·intellij-idea·intellij idea
黎雁·泠崖2 天前
Java入门篇之吃透基础语法(一):注释+关键字+字面量全解析
java·开发语言·intellij-idea·intellij idea
zhanglb124 天前
Gradle 全局配置使用
gradle·android studio·intellij idea
齐鲁大虾4 天前
IDEA如何使用 Swing 构建用户界面
idea·intellij idea
PPPHUANG5 天前
Switch2Antigravity: 让 IntelliJ IDEA 与 Antigravity 无缝协作
程序员·intellij idea·vibecoding
我命由我1234515 天前
Java 开发 - 含有 null 值字段的对象排序(自定义 Comparator、使用 Comparator、使用 Stream API)
java·开发语言·学习·java-ee·intellij-idea·学习方法·intellij idea
『六哥』16 天前
IntelliJ IDEA 安装教程
java·ide·intellij-idea·intellij idea
邵伯正在输入20 天前
如何同时管理GitLab/GitHub的SSH密钥
ssh·gitlab·github·intellij idea