"workbench.colorCustomizations": {
"editor.selectionBackground": "#135564",
"editor.selectionHighlightBackground": "#135564"
},
请查看主题颜色参考获取更多选项。
"workbench.colorCustomizations": {}
,然后开始输入 "editor.selection"
,自动完成菜单将建议所有可能的键及其说明,包括选择前景。 - Tobia"terminal.selectionBackground": "#f1eeb3a9",
表示终端文本被选中时的背景颜色为淡黄色。 - JinSnowselectionHighlightBackground
不会影响vscode在突出显示变量或函数使用时使用的颜色(例如)。 - jrh上面的答案涵盖了选定文本
和与所选内容相同的区域
,但它们忽略了当前搜索匹配项
和其他搜索匹配项
- 这些也存在同样的问题。
"workbench.colorCustomizations": {
"editor.findMatchBackground": "#00cc44a8", //Current SEARCH MATCH
"editor.findMatchHighlightBackground": "#ff7b00a1" //Other SEARCH MATCHES
}
请注意,上面的设置也会影响使用“更改所有出现”CtrlF2命令时的颜色 (这是一个非常有用的命令,可以智能地选择所有字符串的出现位置,并在每个位置放置光标以进行多实例编辑)。
更新:
对于那些使用流行扩展Numbered Bookmarks的人来说,您现在可以更改书签行的背景颜色 - 这使得它们易于注意到。 (您是否曾经想过一种方法来暂时标记代码中的行,就像在纸上使用荧光笔一样?)将此行添加到您的设置.json文件中(也在工作台.colorCustomizations下):
"numberedBookmarks.lineBackground": "#007700"
不要错过Henry Zhu在这里的有用提示。我将Henry的技巧添加到上面的设置中,并发现整体效果得到了改善。(Henry的提示未包含在此答案中-请单击链接阅读Henry的其他提示)
Tom Mai通过评论补充道:
确保
editor.findMatchBackground
和editor.findMatchHighlightBackground
两种颜色都具有透明度(或者具有一些alpha值),以便editor.selectionBackground
和editor.selectionHighlightBackground
显示搜索结果。你可以将editor.selectionBackground
和editor.selectionHighlightBackground
的两种颜色都保持非透明状态(没有alpha值),并且它可以完美地工作
一个典型设置文件的示例,修改后如下:
{"git.enableSmartCommit":true,"git.autofetch":true,"breadcrumbs.enabled":true,"git.confirmSync":false,"explorer.confirmDelete":false,"code-runner.saveFileBeforeRun":true,"code-runner.saveAllFilesBeforeRun":true,"workbench.activityBar.visible":true,"files.trimTrailingWhitespace":true,"telemetry.enableTelemetry":false,"scm.providers.visible":0,"editor.renameOnType":true,"workbench.colorCustomizations":{"editor.selectionBackground":"#e788ff7c","editor.selectionHighlightBackground":"#ff00005b","editor.findMatchBackground":"#00cc44a8","editor.findMatchHighlightBackground":"#ff7b00a1","numberedBookmarks.lineBackground":"#007700"}}
如何查找settings.json文件:
Depending on your platform, the user settings file is located here:
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
打开settings.json文件的另一种方法:
按下Ctrl + , (逗号)来打开Settings
选择“Workbench”
选择“Settings Editor”
在顶部的搜索框中粘贴 workbench.colorCustomizations
在左侧选择“Workbench”,然后选择“Appearance”
单击右侧的链接:Edit in settings.json
参考:
https://code.visualstudio.com/api/references/theme-color#editor-colors
https://code.visualstudio.com/docs/getstarted/themes#_customize-a-color-theme
"editor.findMatchHighlightBorder": "#00ff0075"```
- Neil Gaetano Lindbergeditor.findMatchBackground
,而是使用了 editor.findMatchBorder
,并将其设置为 #ff0000
(红色)。 - Tahir Hassaneditor.findMatchBackground
和 editor.findMatchHighlightBackground
都具有透明度(或某些 alpha 值),以便 editor.selectionBackground
和 editor.selectionHighlightBackground
可以穿过搜索显示。您可以在一定程度上使 editor.selectionBackground
和 editor.selectionHighlightBackground
保持不透明(没有 alpha 值),它可以完美地工作。 - tom_mai78101如果有人发现这篇文章并且和我一样无法使上述配置工作,请尝试以下步骤:
请确保用您想要看到的颜色替换 #'s。
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#<color1>",
"editor.selectionBackground": "#<color2>",
"editor.selectionHighlightBackground": "#<color3>",
"editor.wordHighlightBackground": "#<color4>",
"editorCursor.foreground": "#<color5>"
},
我对以上配置的理解:
editor.lineHighlightBackground - 点击一行时,该行的背景颜色。
"editor.selectionBackground" - 使用光标选择单词的背景颜色。
"editor.selectionHighlightBackground" - 文件中其他与用光标选择的单词匹配的选定文本的背景颜色。想象一个名为foo的变量在文件中各处都被使用。然后你用光标选择其中一个'foo',页面上所有其他的'foo'将会是此变量中指定的颜色。
"editor.wordHighlightBackground" - 如果默认的单击高亮单词不起作用,则选择文本的颜色。我只看到这个值在你点击一个不自动选择的单词时才有所区别。
editorCursor.foreground - 光标的颜色。
你可以通过以下步骤将其更改为您喜欢的颜色:
步骤
在打开设置后,您将在右侧栏中更新设置,将此代码复制并粘贴到主要方括号{ ... }
中。
"workbench.colorCustomizations": {
"editor.selectionBackground": "#f00", // red hexadecimal code
"editor.selectionHighlightBackground": "#fff" // white hex code
},
red
或 white
作为值。 - giovannipdsred
和white
是网页颜色,这可能会让人们感到困惑。 - giovannipds更新 请参考Jakub Zawiślak的回答,适用于VScode 1.12及以上版本
旧回答
Visual Studio Code将此称为选择高亮,并且不幸的是,我认为当前无法自定义颜色。主题可以控制“选择”颜色,但“选择高亮”颜色是硬编码的。
请参阅此问题以追踪可能的解决方案:https://github.com/Microsoft/vscode/issues/1636
(作为附注,您可以使用editor.selectionHighlight
设置切换此功能的打开或关闭。)
{
// Is git enabled
"git.enabled": true,
// Path to the git executable
"git.path": "C:\\Users\\t606964\\AppData\\Local\\Programs\\Git\\mingw64\\bin\\git.exe",
"workbench.startupEditor": "newUntitledFile",
// other settings
//
"editor.fontSize": 12,
"editor.tabSize": 2,
"git.confirmSync": false,
"workbench.colorTheme": "Monokai",
"editor.fontWeight": "bold",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"workbench.iconTheme": "vscode-icons",
"explorer.confirmDelete": false,
"files.autoSave": "off",
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#f00",
"editor.selectionBackground": "#0f0",
"editor.wordHighlightBackground": "#00f",
"editorCursor.foreground": "#ff0"
}
}
请注意缩进和逗号的使用,并删除其答案中的双引号(我必须进行调整才能正确理解,这并不是从答案中很清楚)。无需重新启动vscode,但值得一试的是打开文件>自动保存
,看看是否开始出现主要颜色的高亮显示,然后选择更好的颜色来突出显示。
您还可以通过粘贴内容到工作区设置
使其生效。
"workbench.colorCustomizations": {
"editor.lineHighlightBackground": "#f00",
"editor.selectionBackground": "#0f0",
"editor.wordHighlightBackground": "#00f",
"editorCursor.foreground": "#ff0"
}
在右侧设置面板中,现有的 {}
之间。
您还可以更改选择/搜索的边框,请参见以下配置,其中包含本主题中已经找到的其他值:
"workbench.colorCustomizations": {
"editor.selectionBackground": "#e788ff7c",
"editor.selectionHighlightBackground": "#ff00005b",
"editor.selectionHighlightBorder": "#fbf300e0", ##border when you select
"editor.findMatchBackground": "#f352fe8f",
"editor.findMatchHighlightBackground": "#8e52fe9e",
"editor.findMatchHighlightBorder": "#fbf300e0" ##border when you search for something
}
补充:
用户还可以为特定主题进行设置。请参阅官方文档中关于主题自定义的内容。
如果您经常在暗色和亮色主题之间切换,并且希望分别设置不同的边框颜色,则此功能非常实用。
例如,对于暗色主题,您想要设置更亮的背景或边框颜色,而对于亮色主题,您想要设置深色,您还可以使用通配符来匹配所有暗色主题(或至少那些名称中包含“dark”的主题):
"workbench.colorCustomizations": {
"[Visual Studio Dark]": { "editor.selectionHighlightBorder": "#ffffff" },
"[Visual Studio Light]": { "editor.selectionHighlightBorder": "#000000" },
"[*dark*]": { "editor.selectionHighlightBorder": "#ffffff" }
}
虽然我不确定通配符是否区分大小写,现在也适用于“Dark”,你可以试试。
另一个例子来自文档:
"workbench.colorCustomizations": {
"[Abyss][Red]": {
"activityBar.background": "#ff0000"
},
"[Monokai*]": {
"activityBar.background": "#ff0000"
}
}