vscode c/c++ 主題 DIY
啟用自己的主題(最后步驟)
重啟生效
文件–>首選項–>主題–>顏色主題:
也可以在插件里找到哈
手把手教你制作
在C:\Users\jlh.vscode\extensions下自己創建一個文件夾
里面有兩個文件和一個文件夾
具體內容:
package.json:
{"name":"theme-jlh","displayName":"%displayName%","description":"%description%","version":"1.0.0","icon": "x.png",//自己準備一張圖片128x128"publisher":"vscode","license":"MIT","engines":{"vscode":"*"},"categories":["Themes"],"contributes":{"themes":[{"id":"JLH","label":"%themeLabel%","uiTheme":"vs-dark","path":"./themes/jlh-color-theme.json"}]},"repository":{"type":"git","url":"https://github.com/microsoft/vscode.git"}
}
package.nls.json:
{"displayName":"JLH Theme","description":"JLH theme for Visual Studio Code","themeLabel":"JLH"
}
themes/jlh-color-theme.json
DIY請重點關注397-592行,帶注解的,自行修改:(函數,注釋,枚舉,....自定義顏色樣式)
高級教程: 如果你想弄清楚,xxx的語法是yyy,是怎么來的(見文章最后),比如:宏的語法是 "scope": "entity.name.function.preprocessor.c",
{"$schema": "vscode://schemas/color-theme","name": "jlh diy theme(c/c++)","colors": {"editor.background": "#1E1E1E","editor.foreground": "#DADADA","editor.inactiveSelectionBackground": "#3A3D41","editorIndentGuide.background": "#404040","editorIndentGuide.activeBackground": "#707070","editor.selectionHighlightBackground": "#ADD6FF26","list.dropBackground": "#383B3D","activityBarBadge.background": "#007ACC","sideBarTitle.foreground": "#BBBBBB","input.placeholderForeground": "#A6A6A6","menu.background": "#303031","menu.foreground": "#CCCCCC","statusBarItem.remoteForeground": "#FFF","statusBarItem.remoteBackground": "#16825D","ports.iconRunningProcessForeground": "#369432","sideBarSectionHeader.background": "#0000","sideBarSectionHeader.border": "#ccc3","tab.lastPinnedBorder": "#ccc3","list.activeSelectionIconForeground": "#FFF","editorLineNumber.foreground": "#2b91af","editorLineNumber.activeForeground": "#2b91af","terminal.inactiveSelectionBackground": "#3A3D41","editorInlayHint.background": "#3E3E3E","editorInlayHint.foreground": "#A9A8A7"},"tokenColors": [{"scope": ["meta.embedded","source.groovy.embedded","string meta.image.inline.markdown",],"settings": {"foreground": "#D4D4D4"}},{"scope": "emphasis","settings": {"fontStyle": "italic"}},{"scope": "strong","settings": {"fontStyle": "bold"}},{"scope": "header","settings": {"foreground": "#000080"}},{"scope": "comment","settings": {"foreground": "#6A9955"}},{"scope": "constant.language","settings": {"foreground": "#569cd6"}},{"scope": ["constant.numeric","variable.other.enummember","keyword.operator.plus.exponent","keyword.operator.minus.exponent"],"settings": {"foreground": "#b5cea8"}},{"scope": "constant.regexp","settings": {"foreground": "#646695"}},{"scope": "entity.name.tag","settings": {"foreground": "#569cd6"}},{"scope": "entity.name.tag.css","settings": {"foreground": "#d7ba7d"}},{"scope": "entity.other.attribute-name","settings": {"foreground": "#9cdcfe"}},{"scope": ["entity.other.attribute-name.class.css","entity.other.attribute-name.class.mixin.css","entity.other.attribute-name.id.css","entity.other.attribute-name.parent-selector.css","entity.other.attribute-name.pseudo-class.css","entity.other.attribute-name.pseudo-element.css","source.css.less entity.other.attribute-name.id","entity.other.attribute-name.scss"],"settings": {"foreground": "#d7ba7d"}},{"scope": "invalid","settings": {"foreground": "#f44747"}},{"scope": "markup.underline","settings": {"fontStyle": "underline"}},{"scope": "markup.bold","settings": {"fontStyle": "bold","foreground": "#569cd6"}},{"scope": "markup.heading","settings": {"fontStyle": "bold","foreground": "#569cd6"}},{"scope": "markup.italic","settings": {"fontStyle": "italic"}},{"scope": "markup.strikethrough","settings": {"fontStyle": "strikethrough"}},{"scope": "markup.inserted","settings": {"foreground": "#b5cea8"}},{"scope": "markup.deleted","settings": {"foreground": "#ce9178"}},{"scope": "markup.changed","settings": {"foreground": "#569cd6"}},{"scope": "punctuation.definition.quote.begin.markdown","settings": {"foreground": "#6A9955"}},{"scope": "punctuation.definition.list.begin.markdown","settings": {"foreground": "#6796e6"}},{"scope": "markup.inline.raw","settings": {"foreground": "#ce9178"}},{"name": "brackets of XML/HTML tags","scope": "punctuation.definition.tag","settings": {"foreground": "#808080"}},{"scope": ["meta.preprocessor","entity.name.function.preprocessor"],"settings": {"foreground": "#569cd6"}},{"scope": "meta.preprocessor.string","settings": {"foreground": "#ce9178"}},{"scope": "meta.preprocessor.numeric","settings": {"foreground": "#b5cea8"}},{"scope": "meta.structure.dictionary.key.python","settings": {"foreground": "#9cdcfe"}},{"scope": "meta.diff.header","settings": {"foreground": "#569cd6"}},{"scope": "storage","settings": {"foreground": "#569cd6"}},{"scope": "storage.type","settings": {"foreground": "#569cd6"}},{"scope": ["storage.modifier","keyword.operator.noexcept"],"settings": {"foreground": "#569cd6"}},{"scope": ["string","meta.embedded.assembly"],"settings": {"foreground": "#ce9178"}},{"scope": "string.tag","settings": {"foreground": "#ce9178"}},{"scope": "string.value","settings": {"foreground": "#ce9178"}},{"scope": "string.regexp","settings": {"foreground": "#d16969"}},{"name": "String interpolation","scope": ["punctuation.definition.template-expression.begin","punctuation.definition.template-expression.end","punctuation.section.embedded"],"settings": {"foreground": "#569cd6"}},{"name": "Reset JavaScript string interpolation expression","scope": ["meta.template.expression"],"settings": {"foreground": "#d4d4d4"}},{"scope": ["support.type.vendored.property-name","support.type.property-name","variable.css","variable.scss","variable.other.less","source.coffee.embedded"],"settings": {"foreground": "#9cdcfe"}},{"scope": "keyword","settings": {"foreground": "#569cd6"}},{"scope": "keyword.control","settings": {"foreground": "#569cd6"}},{"scope": "keyword.operator","settings": {"foreground": "#d4d4d4"}},{"scope": ["keyword.operator.new","keyword.operator.expression","keyword.operator.cast","keyword.operator.sizeof","keyword.operator.alignof","keyword.operator.typeid","keyword.operator.alignas","keyword.operator.instanceof","keyword.operator.logical.python","keyword.operator.wordlike"],"settings": {"foreground": "#569cd6"}},{"scope": "keyword.other.unit","settings": {"foreground": "#b5cea8"}},{"scope": ["punctuation.section.embedded.begin.php","punctuation.section.embedded.end.php"],"settings": {"foreground": "#569cd6"}},{"scope": "support.function.git-rebase","settings": {"foreground": "#9cdcfe"}},{"scope": "constant.sha.git-rebase","settings": {"foreground": "#b5cea8"}},{"name": "coloring of the Java import and package identifiers","scope": ["storage.modifier.import.java","variable.language.wildcard.java","storage.modifier.package.java"],"settings": {"foreground": "#d4d4d4"}},{"name": "this.self","scope": "variable.language","settings": {"foreground": "#569cd6"}},//===================關鍵字================={"scope": "keyword.control.c","settings": {"foreground": "#2b71f1" // 控制語句關鍵字(如 if、else、for 等)}},{"scope": "keyword.control.cpp","settings": {"foreground": "#2b71f1" // C++ 控制語句關鍵字}},{"scope": "keyword.operator.word.c","settings": {"foreground": "#2b71f1" // 操作符關鍵字(如 sizeof、typedef 等)}},{"scope": "keyword.operator.logical.c","settings": {"foreground": "#ff0000" // 邏輯操作符關鍵字(如 &&、|| 等)}},//===================字符串================={"scope": "string.quoted.double.cpp","settings": {"foreground": "#44e9ff" // 雙引號字符串}},{"scope": "string.quoted.single.cpp","settings": {"foreground": "#7bf0ff" // 單引號字符串}},{"scope": "string.quoted.other.cpp","settings": {"foreground": "#44e9ff" // 其他類型的字符串}},//===================函數================={"scope": "entity.name.function.c","settings": {"foreground": "#fcff54" // C 函數名}},{"scope": "entity.name.function.cpp","settings": {"foreground": "#fcff54" // C++ 函數名}},{"scope": "meta.function-call.c","settings": {"foreground": "#d580f7" // 函數調用名}},{"scope": "variable.parameter","settings": {"foreground": "#ffd588" // 函數參數}},//=================== 宏 ================={"scope": "keyword.other.macro.c","settings": {"foreground": "#ff0000" // 宏定義}},{"scope": "keyword.other.macro.cpp","settings": {"foreground": "#ec0f0f" // C++ 宏定義}},//===================注釋================={"scope": "comment.line.double-slash.c","settings": {"foreground": "#5acf5a7e" // 單行注釋}},{"scope": "comment.block.c","settings": {"foreground": "#5acf5a7e" // 多行注釋}},//===================枚舉================={"scope": "entity.name.type.enum.c","settings": {"foreground": "#2b71f1" // 枚舉類型名}},{"scope": "constant.other.enum-member.c","settings": {"foreground": "#f0d08c" // 枚舉成員}},//===================指針運算符================={"scope": "storage.modifier.pointer.c","settings": {"foreground": "#e28df3" // 指針運算符(* 和 &)}},//===================class================={"scope": "entity.name.type.class.cpp","settings": {"foreground": "#2b71f1" // C++ 類名}},{"scope": "entity.name.type.struct.c","settings": {"foreground": "#2b71f1" // C 結構體名}},{"scope": "entity.name.type.struct.cpp","settings": {"foreground": "#2b71f1" // C++ 結構體名}},//===================變量================={"scope": "storage.type.c","settings": {"foreground": "#21c937" // 類型關鍵字(如 int、float 等)}},{"scope": "variable.other.readwrite.c","settings": {"foreground": "#bbd1fa" // 普通變量}},//===================運算符================={"scope": "keyword.operator.arithmetic.c","settings": {"foreground": "#f7f3f3" // 算術運算符(如 +、-、*、/ 等)}},{"scope": "keyword.operator.comparison.c","settings": {"foreground": "#f7f3f3" // 比較運算符(如 ==、!=、<、> 等)}},{"scope": "keyword.operator.assignment.c","settings": {"foreground": "#f7f3f3" // 賦值運算符(如 =、+=、-= 等)}},//===================常量================={"scope": "constant.numeric.integer.c","settings": {"foreground": "#B5CEA8" // 整數常量}},{"scope": "constant.numeric.float.c","settings": {"foreground": "#B5CEA8" // 浮點數常量}},{"scope": "constant.character.escape.c","settings": {"foreground": "#CE9178" // 字符串中的轉義字符}}],"semanticHighlighting": true,"semanticTokenColors": {"newOperator": "#569CD6","stringLiteral": "#ce9178","customLiteral": "#DCDCAA","numberLiteral": "#b5cea8"//數字顏色},
/*"editor.semanticTokenColorCustomizations": {"rules": {"namespace": {"foreground": "#569CD6" // 命名空間},"class": {"foreground": "#4EC9B0" // 類},"interface": {"foreground": "#4EC9B0" // 接口},"enum": {"foreground": "#4EC9B0" // 枚舉},"enumMember": {"foreground": "#569CD6" // 枚舉成員},"struct": {"foreground": "#4EC9B0" // 結構體},"typeParameter": {"foreground": "#9CDCFE" // 類型參數},"function": {"foreground": "#DCDCAA" // 函數},"method": {"foreground": "#569CD6" // 方法},"variable": {"foreground": "#9CDCFE" // 變量},"parameter": {"foreground": "#9CDCFE" // 參數},"property": {"foreground": "#9CDCFE" // 屬性},"macro": {"foreground": "#FFD700" // 宏}}}*/
}
字體加粗/下劃線/斜體
"editor.tokenColorCustomizations": {"textMateRules": [{"scope": "keyword.control.c","settings": {"foreground": "#0000FF","fontStyle": "bold" // 加粗關鍵字}}]
}
"editor.tokenColorCustomizations": {"textMateRules": [{"scope": "variable.parameter","settings": {"foreground": "#FF00FF","fontStyle": "underline" // 函數參數加下劃線}}]
}
"editor.tokenColorCustomizations": {"textMateRules": [{"scope": "comment.line.double-slash.c","settings": {"foreground": "#008000","fontStyle": "italic" // 注釋文字斜體}}]
}
"editor.tokenColorCustomizations": {"textMateRules": [{"scope": "keyword.other.macro.c","settings": {"foreground": "#FFD700","fontStyle": "bold italic" // 宏定義加粗且斜體}}]
}
問題,發現有的配置不生效?(語法規則自查)
比如我實現的宏keyword.other.macro.c,沒用生效.
檢查作用域:
1 按 Ctrl+Shift+P 打開命令面板。
2 輸入并執行 Developer: Inspect Editor Tokens and Scopes。
3 將光標放在宏定義上(如 #define),查看實際的作用域
修改:
{"scope": "entity.name.function.preprocessor.c","settings": {"foreground": "#ff0000" // 宏定義}},{"scope": "entity.name.function.preprocessor","settings": {"foreground": "#ec0f0f" // C++ 宏定義}},
具體問題,具體分析.
其他:也可能是插件沖突,或者被vscode默認主題覆蓋