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" } }
        ]
    }
}
相关推荐
JAVA面经实录9173 天前
Java开发工程基础完整手册(企业实战完整版)
java·开发语言·git·ci/cd·svn·github·intellij idea
掉头发的王富贵6 天前
如何自己开发一个IDEA插件
后端·intellij idea
月明水寒9 天前
IDEA2026.1 vue文件报错
前端·javascript·vue.js·intellij-idea·idea·intellij idea
·你好·10 天前
mybatis sql 日志问号替换
intellij idea·idea插件
殷紫川12 天前
IDEA Claude Code 插件封神指南:让 AI 成为你的结对编程伙伴
后端·ai编程·intellij idea
golang学习记13 天前
☕️➡️🚀 Java 一键转 Kotlin?VS Code 这个新插件太香了!
intellij idea·visual studio code
用户65317803136917 天前
吃透IDEA Debug:从基础到高级,开发必备调试技巧
intellij idea
golang学习记17 天前
IDEA官宣:终于可以爽用Junie CLI了!
intellij idea
其实是白羊18 天前
我用 Vibe Coding 搓了一个 IDEA 插件,复制URI 再也不用手动拼了
后端·intellij idea
殷紫川1 个月前
IDEA 集成 GitHub Copilot 指南:解锁 10 倍编码效率的全链路实战
github·intellij idea·github copilot