在Visual Studio代码中更改突出显示文本颜色

duy*_*yen 74 visual-studio-code

现在,它是一个微弱的灰色覆盖层,很难看到.有什么方法可以改变默认颜色?

在此输入图像描述

Jak*_*lak 207

"workbench.colorCustomizations": {
    "editor.selectionBackground": "#135564",
    "editor.selectionHighlightBackground": "#135564"
},
Run Code Online (Sandbox Code Playgroud)

有关更多选项,请参阅主题颜色参考

  • 这个答案应该标记为解决方案. (11认同)
  • 有什么办法可以改变文字颜色?否则,您必须找到一种与配色方案中的每种颜色配对时都能保持可读性的背景色。这是使我无法使用VS Code的两个问题之一... (3认同)
  • @BrunoBEly如果你打开`"workbench.colorCustomizations":{}`然后开始输入``editor.selection`,自动完成菜单会建议所有可能的键及其解释,包括选择前景. (3认同)
  • 对于终端: `"terminal.selectionBackground": "#f1eeb3a9",` (3认同)
  • @Tobia 感谢您的提示!我找到了,但可能做错了什么。我将背景和前景都设置为红色,但 [似乎只有背景有效](https://imgur.com/nCLnFyv)(我使用的是 VS Code 1.18.0) (2认同)
  • 这似乎不适用于 Python,设置 `selectionHighlightBackground` 似乎不会影响 vscode 在突出显示变量或函数的使用时使用的颜色(例如) (2认同)

css*_*hus 15

上面的答案涵盖了Selected textareas with same content as selection,但是错过了Current Search MatchOther Search Matches- 具有同样的问题

"workbench.colorCustomizations": {
    "editor.findMatchBackground": "#00cc44a8", //Current SEARCH MATCH
    "editor.findMatchHighlightBackground": "#ff7b00a1" //Other SEARCH MATCHES
}
Run Code Online (Sandbox Code Playgroud)

请注意,在使用“更改所有出现次数” CtrlF2 (一个超级有用的命令,它会 智能地 选择所有出现的字符串,将光标置于每个位置进行多实例编辑)时,上述设置也会影响颜色。


一个典型的设置文件示例,post mod:

    {
        “ git.enableSmartCommit”:是的,
        “ git.autofetch”:是的,
        “ breadcrumbs.enabled”:是的,
        “ git.confirmSync”:否,
        “ explorer.confirmDelete”:否,
        “ code-runner.saveFileBeforeRun”:是,
        “ code-runner.saveAllFilesBeforeRun”:是,
        “ workbench.activityBar.visible”:是,
        “ files.trimTrailingWhitespace”:是的,
        “ telemetry.enableTelemetry”:否,
        “ scm.providers.visible”:0,// 0允许手动调整源代码控制面板的大小
        “ workbench.colorCustomizations”:{
            “ editor.selectionBackground”:“#e788ff7c”,//当前选择的文本
            “ editor.selectionHighlightBackground”:“#ff00005b”,//内容与选择相同
            “ editor.findMatchBackground”:“#00cc44a8”,//当前的搜索匹配
            “ editor.findMatchHighlightBackground”:“#ff7b00a1” //其他搜索匹配
        }
    }


在哪里可以找到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
Run Code Online (Sandbox Code Playgroud)

ALTERNATE方法打开settings.json文件:

  1. Ctrl +,(逗号)打开“设置”

  2. 工作台

  3. 设定编辑器

  4. 在顶部的搜索框中,粘贴 workbench.colorCustomizations

  5. 在左侧,单击Workbench,然后Appearance

  6. 单击右侧的链接: 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

https://code.visualstudio.com/docs/getstarted/settings

  • 我发现这些与这个答案结合起来也很有用,可以一目了然地找到匹配项。请注意对 RGBA 的支持(在我的使用中,颜色值末尾的 75 alpha 设置:```"editor.wordHighlightBorder": "#00ff0075", "editor.findMatchHighlightBorder": "#00ff0075"``` (2认同)

Fuj*_*ale 14

If anyone finds this and, like me, was unable to get the above config working try doing this.

  1. go to file > Preferences > settings
  2. type in the search Editor token color customizations
  3. under the Editor token color customizations header
  4. click on edit in settings.json
  5. on the right hand column select user settings
  6. paste this into the json object

Be sure to replace the #'s with colors you want to see.

"workbench.colorCustomizations": {
    "editor.lineHighlightBackground": "#<color1>",
    "editor.selectionBackground": "#<color2>",
    "editor.wordHighlightBackground": "#<color3>",
    "editorCursor.foreground": "#<color4>"
},
Run Code Online (Sandbox Code Playgroud)

My understanding of the above config.

editor.lineHighlightBackground - when you click on a line this is the color the line background will be.

"editor.selectionBackground" - This is the background of matched selections elsewhere in the buffer. Think of a variable named foo and it's used all over a file. You then highlight that text and all the other foos on the page will be this color.

"editor.wordHighlightBackground" - This is the color of selected text if the default highlight word on click does not take effect. I've only seen this value make a difference if you click on a word that does not auto-select.

editorCursor.foreground - this is the color of your cursor.

  • 这应该是答案。这些是VSCode 1.3+版中使用的设置 (2认同)

Riz*_*izo 12

您可以通过以下方式将其更改为您喜欢的颜色:

脚步

  1. 打开可视化代码
  2. 转到文件菜单
  3. 首选项 -> 设置

打开设置后,您将更新右侧栏中的设置,将此代码复制并粘贴到主括号内 { ... }

"workbench.colorCustomizations": {
    "editor.selectionBackground": "#f00", // red hexadecimal code
    "editor.selectionHighlightBackground": "#fff" // white hex code
},
Run Code Online (Sandbox Code Playgroud)

  • VS Code --&gt; 文件 --&gt; 首选项 --&gt; 设置,然后搜索“workbench.colorCustomizations”...复制、粘贴,完成! (3认同)

Mat*_*ner 10

更新 请参阅@JakubZawiślak对VScode 1.12+的回答


老答案

Visual Studio Code调用此选项突出显示,不幸的是,我认为当前颜色不可定制.主题可以控制"选择"颜色,但"选择突出显示"颜色是硬编码的.

请参阅此问题,跟踪可能的解决方案:https://github.com/Microsoft/vscode/issues/1636

(作为旁注,您可以使用editor.selectionHighlight设置切换此功能或/关闭.)

  • ***已过时***。 (3认同)
  • 更新以参考JakubZawiślak对现代版VSCode的回答 (3认同)

hen*_*zhu 5

正如我测试过的那样,设置边框颜色比设置背景颜色更容易阅读,这是Sublime Text的作用。

例如,将这些行添加到settings.json

"workbench.colorCustomizations": {
    "editor.selectionHighlightBorder": "#FFFA",
},
Run Code Online (Sandbox Code Playgroud)

所选单词将显示为:

在此处输入图片说明


sta*_*all 5

This Q&A seems to have evolved into a canonical and the information here is quite scattered and incomplete (there are several different types of highlighting in VS Code!). This is an attempt to defragment/unify/fill.

\n

In general, use subproperties of the workbench.colorCustomizations setting in a settings.json file. You can write colours in the following forms:

\n
"workbench.colorCustomizations": {\n    "[Theme Name Goes Here]": { // apply to specific theme. remove this wrapper object to apply to all themes\n        // (using the colour red as an example)\n        // "selection.background": "#f00",      // #RGB      (red, green, blue)\n        // "selection.background": "#ff0000",   // #RRGGBB   (red, green, blue)\n        // "selection.background": "#f008",     // #RGBA     (red, green, blue, alpha/opacity)\n        // "selection.background": "#ff000080", // #RRGGBBAA (red, green, blue, alpha/opacity)\n    },\n},\n
Run Code Online (Sandbox Code Playgroud)\n

To make something transparent, set the opacity to zero.

\n

I\'ll generally only list the "Background" customization point, but know that for many of these, there is a corresponding "Foreground" customization point to change the colour of the text itself, and sometimes even a customization point for borders. Note that you can find most of these yourself by triggering suggestions after typing "highlight.background" in a settings.json file inside the workbench.colorCustomizations object where a new object key should go.

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Colour Customization Point IDDescription (quoting from tooltip description)Additional Notes
selection.backgroundThe background color of text selections in the workbench (e.g. for input fields or text areas). Note that this does not apply to selections within the editor.
\xe2\xad\x90 editor.lineHighlightBackgroundBackground color for the highlight of line at the cursor position.See also the editor.renderLineHighlight and editor.renderLineHighlightOnlyWhenFocus settings.
editor.rangeHighlightBackgroundBackground color of highlighted ranges, like by quick open and find features. The color must not be opaque so as not to hide underlying decorations.
editor.selectionForegroundColor of the selected text for high contrast.
\xe2\xad\x90 editor.selectionBackgroundColor of the editor selection.
\xe2\xad\x90 editor.selectionHighlightBackgroundColor for regions with the same content as the selection. The color must not be opaque so as not to hide underlying decorations.See also the editor.selectionHighlight setting
\xe2\xad\x90 editor.wordHighlightBackgroundBackground color of a symbol during read-access, like reading a variable. The color must not be opaque so as not to hide underlying decorations.See also the editor.occurrencesHighlight setting
editor.wordHighlightStrongBackgroundBackground color of a symbol during write-access, like writing to a variable. The color must not be opaque so as not to hide underlying decorations.
editor.hoverHighlightBackgroundHighlight below the word for which a hover is shown. The color must not be opaque so as not to hide underlying decorations.
\xe2\xad\x90 editor.findMatchBackgroundColor of the current search match.
\xe2\xad\x90 editor.findMatchHighlightBackgroundColor of the other search matches. The color must not be opaque so as not to hide underlying decorations.Applies for editor find widget and Search View matches, and also to highlighting list items in the Search View
editor.findRangeHighlightBackground限制搜索范围的颜色。颜色不能是不透明的,以免隐藏下面的装饰。
terminal.findMatchBackground终端中当前搜索匹配的颜色。颜色不能是不透明的,以免隐藏底层的终端内容。
terminal.findMatchHighlightBackground终端中其他搜索匹配的颜色。颜色不能是不透明的,以免隐藏底层的终端内容。
terminal.hoverHighlightBackground终端中其他搜索匹配的边框颜色。
searchEditor.findMatchBackground搜索编辑器查询匹配的颜色。什么是搜索编辑器?
editor.symbolHighlightBackground突出显示符号的背景颜色,例如转到定义或转到下一个/上一个符号。颜色不能是不透明的,以免隐藏下面的装饰。
editor.wordHighlightTextBackground符号文本出现的背景颜色。颜色不能是不透明的,以免隐藏下面的装饰。
notebook.symbolHighlightBackground突出显示单元格的背景颜色
peekViewEditor.matchHighlightBackground在预览视图编辑器中匹配突出显示颜色。
peekViewResult.matchHighlightBackground匹配速览视图结果列表中的突出显示颜色。
editorBracketMatch.background匹配括号后面的背景颜色
editorUnicodeHighlight.background用于突出显示 unicode 字符的背景颜色。
\n
\n

如果你想复制粘贴骨架:

\n
"workbench.colorCustomizations": {\n    // "selection.background": "#ff000040",\n    "editor.lineHighlightBackground": "#ff000040",\n    // "editor.rangeHighlightBackground": "#ff000040",\n    // "editor.selectionForeground": "#ff000040",\n    "editor.selectionBackground": "#ff000040",\n    "editor.selectionHighlightBackground": "#ff000040",\n    "editor.wordHighlightBackground": "#ff000040",\n    // "editor.wordHighlightStrongBackground": "#ff000040",\n    // "editor.hoverHighlightBackground": "#ff000040",\n    "editor.findMatchBackground": "#ff000040",\n    "editor.findMatchHighlightBackground": "#ff000040",\n    // "editor.findRangeHighlightBackground": "#ff000040",\n    // "terminal.findMatchBackground": "#ff000040",\n    // "terminal.findMatchHighlightBackground": "#ff000040",\n    // "terminal.hoverHighlightBackground": "#ff000040",\n    // "searchEditor.findMatchBackground": "#ff000040",\n    // "editor.symbolHighlightBackground": "#ff000040",\n    // "editor.wordHighlightTextBackground": "#ff000040",\n    // "notebook.symbolHighlightBackground": "#ff000040",\n    // "peekViewEditor.matchHighlightBackground": "#ff000040",\n    // "peekViewResult.matchHighlightBackground": "#ff000040",\n    // "editorBracketMatch.background": "#ff000040",\n    // "editorUnicodeHighlight.background": "#ff000040",\n},\n
Run Code Online (Sandbox Code Playgroud)\n