此文针对 C/C++ Theme 插件内的主题进行自定义选择性优化。
最近喜欢浅色主题,但是找了很多主题,都没有让我完全满意的,比如说很多主题的结构体成员变量、enum类型、宏等的显示效果不好,无奈只能自己动手。我选择了 C/C++ Theme 内的 Light 主题作为母版,进行配色更改,这里记录下过程。
ctrl + shift + p
: 打开命令框
ctrl + k + t
: 切换主题,按↑↓键可直接进入相应主题的的预览。
对于主题文件,一般分散在这两个路径下:
C:\Users\xxx\.vscode\extensions\ms-vscode.cpptools-themes-2.0.0\themes
这里就是 C/C++ Theme 的主题配色文件。
这里有一些是VsCode自带的一些主题文件。
因为我修改的主题对应的文件是cpptools_light_vs.json
,所以要对配色的修改也主要是针对这个文件。
使用 ctrl + shift + p
打开命令框,键入 inspect edit editor tokens and scopes
,找到下面这个并点击。
以下面为例,这里侦测到函数所对应的作用域范围:
所以我们想更改函数配色的话,就需要以下面的方式写:
{
"scope": [
"entity.name.function.c",
],
"settings": {
"foreground": "#BD63C5" //更改颜色
}
},
这里推荐一个调色网址:
colorhexa
{
"$schema": "vscode://schemas/color-theme",
"name": "Visual Studio Light (C/C++)",
"colors": {
"editor.background": "#FFFFFF",
"editor.foreground": "#000000",
"editor.inactiveSelectionBackground": "#E5EBF1",
"editorIndentGuide.background": "#D3D3D3",
"editorIndentGuide.activeBackground": "#939393",
"editor.selectionHighlightBackground": "#ADD6FF80",
"editorSuggestWidget.background": "#F3F3F3",
"activityBarBadge.background": "#007ACC",
"sideBarTitle.foreground": "#6F6F6F",
"list.hoverBackground": "#E8E8E8",
"input.placeholderForeground": "#767676",
"searchEditor.textInputBorder": "#CECECE",
"settings.textInputBorder": "#CECECE",
"settings.numberInputBorder": "#CECECE",
"statusBarItem.remoteForeground": "#FFF",
"statusBarItem.remoteBackground": "#16825D",
"ports.iconRunningProcessForeground": "#369432",
"sideBarSectionHeader.background": "#0000",
"sideBarSectionHeader.border": "#61616130",
"tab.lastPinnedBorder": "#61616130",
"notebook.cellBorderColor": "#E8E8E8",
"notebook.selectedCellBackground": "#c8ddf150",
"statusBarItem.errorBackground": "#c72e0f",
"list.activeSelectionIconForeground": "#FFF",
"list.focusAndSelectionOutline": "#90C2F9",
"editorLineNumber.foreground": "#2b91af",
"editorLineNumber.activeForeground": "#2b91af",
"terminal.inactiveSelectionBackground": "#E5EBF1",
"editorWhitespace.foreground": "#2B91AF"
},
"semanticHighlighting": true,
"tokenColors": [
{
"scope": [
"meta.embedded",
"source.groovy.embedded",
"string meta.image.inline.markdown"
],
"settings": {
"foreground": "#000000ff"
}
},
{
"scope": "emphasis",
"settings": {
"fontStyle": "italic"
}
},
{
"scope": "strong",
"settings": {
"fontStyle": "bold"
}
},
{
"scope": "meta.diff.header",
"settings": {
"foreground": "#000080"
}
},
{
"scope": "comment",
"settings": {
"foreground": "#008000"
}
},
{
"scope": "constant.language",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": [
"constant.numeric",
"variable.other.enummember",
"keyword.operator.plus.exponent",
"keyword.operator.minus.exponent"
],
"settings": {
"foreground": "#098658"
}
},
{
"scope": "constant.regexp",
"settings": {
"foreground": "#811f3f"
}
},
{
"name": "css tags in selectors, xml tags",
"scope": "entity.name.tag",
"settings": {
"foreground": "#800000"
}
},
{
"scope": "entity.name.selector",
"settings": {
"foreground": "#800000"
}
},
{
"scope": "entity.other.attribute-name",
"settings": {
"foreground": "#ff0000"
}
},
{
"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": "#800000"
}
},
{
"scope": "invalid",
"settings": {
"foreground": "#cd3131"
}
},
{
"scope": "markup.underline",
"settings": {
"fontStyle": "underline"
}
},
{
"scope": "markup.bold",
"settings": {
"fontStyle": "bold",
"foreground": "#000080"
}
},
{
"scope": "markup.heading",
"settings": {
"fontStyle": "bold",
"foreground": "#800000"
}
},
{
"scope": "markup.italic",
"settings": {
"fontStyle": "italic"
}
},
{
"scope": "markup.strikethrough",
"settings": {
"fontStyle": "strikethrough"
}
},
{
"scope": "markup.inserted",
"settings": {
"foreground": "#098658"
}
},
{
"scope": "markup.deleted",
"settings": {
"foreground": "#a31515"
}
},
{
"scope": "markup.changed",
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": [
"punctuation.definition.quote.begin.markdown",
"punctuation.definition.list.begin.markdown"
],
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": "markup.inline.raw",
"settings": {
"foreground": "#800000"
}
},
{
"name": "brackets of XML/HTML tags",
"scope": "punctuation.definition.tag",
"settings": {
"foreground": "#800000"
}
},
{
"scope": [
"meta.preprocessor",
"entity.name.function.preprocessor"
],
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": [
"meta.preprocessor",
],
"settings": {
"foreground": "#BD63C5" //更改他的宏定义颜色
}
},
{
"scope": [
"entity.name.function"
],
"settings": {
"foreground": "#A31515" //我自己配的函数颜色
}
},
{
"scope": [
"variable.other.enummember.c"
],
"settings": {
"foreground": "#065639" //我自己配的枚举成员颜色
}
},
{
"scope": [
"variable.other.property.c"
],
"settings": {
"foreground": "#243f94" //我自己配的结构体成员变量
}
},
{
"scope": [
"variable.other.member.c"
],
"settings": {
"foreground": "#243f94" //我自己配的结构体成员变量1
}
},
{
"scope": [
"constant.numeric.decimal.c"
],
"settings": {
"foreground": "#098658" //我自己配的常量
}
},
{
"scope": [
"constant.other.placeholder.c"
],
"settings": {
"foreground": "#1F377F" //我自己配%d %f
}
},
{
"scope": [
"constant.character.escape.c"
],
"settings": {
"foreground": "#9676fb" //我自己配的 \r\n
}
},
{
"scope": "meta.preprocessor.string",
"settings": {
"foreground": "#a31515"
}
},
{
"scope": "meta.preprocessor.numeric",
"settings": {
"foreground": "#098658"
}
},
{
"scope": "meta.structure.dictionary.key.python",
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": "storage",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "storage.type",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": [
"storage.modifier",
"keyword.operator.noexcept"
],
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": [
"string",
"meta.embedded.assembly"
],
"settings": {
"foreground": "#a31515"
}
},
{
"scope": [
"string",
],
"settings": {
"foreground": "#6e4100" //更改字符串配色
}
},
{
"scope": [
"string.comment.buffered.block.pug",
"string.quoted.pug",
"string.interpolated.pug",
"string.unquoted.plain.in.yaml",
"string.unquoted.plain.out.yaml",
"string.unquoted.block.yaml",
"string.quoted.single.yaml",
"string.quoted.double.xml",
"string.quoted.single.xml",
"string.unquoted.cdata.xml",
"string.quoted.double.html",
"string.quoted.single.html",
"string.unquoted.html",
"string.quoted.single.handlebars",
"string.quoted.double.handlebars"
],
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "string.regexp",
"settings": {
"foreground": "#811f3f"
}
},
{
"name": "String interpolation",
"scope": [
"punctuation.definition.template-expression.begin",
"punctuation.definition.template-expression.end",
"punctuation.section.embedded"
],
"settings": {
"foreground": "#0000ff"
}
},
{
"name": "Reset JavaScript string interpolation expression",
"scope": [
"meta.template.expression"
],
"settings": {
"foreground": "#000000"
}
},
{
"scope": [
"support.constant.property-value",
"support.constant.font-name",
"support.constant.media-type",
"support.constant.media",
"constant.other.color.rgb-value",
"constant.other.rgb-value",
"support.constant.color"
],
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": [
"support.type.vendored.property-name",
"support.type.property-name",
"variable.css",
"variable.scss",
"variable.other.less",
"source.coffee.embedded"
],
"settings": {
"foreground": "#ff0000"
}
},
{
"scope": [
"support.type.property-name.json"
],
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": "keyword",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "keyword.control",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "keyword.operator",
"settings": {
"foreground": "#000000"
}
},
{
"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": "#0000ff"
}
},
{
"scope": "keyword.other.unit",
"settings": {
"foreground": "#098658"
}
},
{
"scope": [
"punctuation.section.embedded.begin.php",
"punctuation.section.embedded.end.php"
],
"settings": {
"foreground": "#800000"
}
},
{
"scope": "support.function.git-rebase",
"settings": {
"foreground": "#0451a5"
}
},
{
"scope": "constant.sha.git-rebase",
"settings": {
"foreground": "#098658"
}
},
{
"name": "coloring of the Java import and package identifiers",
"scope": [
"storage.modifier.import.java",
"variable.language.wildcard.java",
"storage.modifier.package.java"
],
"settings": {
"foreground": "#000000"
}
},
{
"name": "this.self",
"scope": "variable.language",
"settings": {
"foreground": "#0000ff"
}
},
{
"scope": "entity.name",
"settings": {
"foreground": "#000000"
}
},
{
"scope": "keyword.control.directive",
"settings": {
"foreground": "#808080"
}
},
{
"scope": "variable",
"settings": {
"foreground": "#000000"
}
},
{
"scope": "entity.name.function.operator",
"settings": {
"foreground": "#008080"
}
},
{
"scope": "entity.name.function.preprocessor",
"settings": {
"foreground": "#BD63C5"
}
},
{
"scope": "entity.name.namespace",
"settings": {
"foreground": "#000000"
}
},
{
"scope": [
"entity.name.type",
"entity.name.class"
],
"settings": {
"foreground": "#2B91AF"
}
},
{
"scope": "entity.name.operator.custom-literal.string",
"settings": {
"foreground": "#a31515"
}
},
{
"scope": [
"keyword.operator.new",
"keyword.operator.delete"
],
"settings": {
"foreground": "#0000FF"
}
},
{
"scope": "variable.other.enummember",
"settings": {
"foreground": "#2F4F4F"
}
},
{
"scope": "variable.parameter",
"settings": {
"foreground": "#808080"
}
}
],
"semanticTokenColors": {
"operatorOverload": "#008080",
"operatorOverloadMember": "#008080",
"newOperator": "#0000FF",
"stringLiteral": "#A31515"
}
}