10

I'm trying to configure brackets highlighting in Visual Studio 2017 (version 15.6.6, using the "Light" theme), but I can't get it to work, and I don't understand whether I am doing it wrong or the feature is buggy.

I'd simply like Visual Studio to make matching brackets turn red, instead of the default setting of having a grey background.

By going to Tools -> Options -> Environment -> Fonts and Colors, I find three settings:

  • Brace Matching
  • Brace Matching (Highlight)
  • Brace Matching (Rectangle)

Apparently, the first two do... Nothing. I've tried setting the foreground and background to different colors, but I see no change, even after a restart. The only setting that does something is the third one, where I can change the color of the background rectangle as expected. But that isn't what I want.

Why don't the first two settings do anything? Is it a bug? How can I make matching brackets become red?

I've found other questions about Visual Studio 2013 and Visual Studio 2015. They don't help, and the latter turned out to be a bug. Is this another one?

  • Any installed extension that could block or ignore the new color? – Lord_Curdin Apr 23 '18 at 05:26
  • I don't think so. I think these settings were working until some time ago, and it could be that they stopped when I installed Clang for Visual Studio. But that should be completely unrelated! – Fabio says Reinstate Monica Apr 23 '18 at 21:55
  • 1
    Reason can be resharper, if you are using it. Resharper -> Options -> Editor -> Editor Appearance -> Hightlight matching delimeters when caret is. Uncheck it and then visual studio settings will not get ignored. – Ademar Sep 11 '18 at 10:06
  • @Ademar What you commented was an answer for me, it worked, thanks (Post an answer if you want) – Antoine Pelletier Jan 28 '19 at 18:58

6 Answers6

16

Somehow, off topic. I would warmly recommend you to make use of the (free) Viasfora extension for Visual Studio.

It comes with plenty of goodies that will make you forget the need to click the bracket to get its match.

Example: It colors the brackets with a different color for each statement.

enter image description here

From Visual Studio Marketplace: https://marketplace.visualstudio.com/items?itemName=TomasRestrepo.Viasfora#overview

George
  • 653
  • 6
  • 18
6

Tools > Options > Environment > Fonts and Colors > Brace Matching > Item Background set that to your color.

Here are all the Brace Matching settings I am using:

  • Brace Matching: Item foreground: Green, Item background: Green, Bold: checked
  • Brace Matching (Highlight): Item foreground: Green, Bold: checked

  • Brace Matching (Rectangle): Item foreground: appears disabled,
    Item background: Automatic, Custom, Bold: checked

Visual Studio Community 2017

HTH

pdschuller
  • 584
  • 6
  • 26
0

Its the Brace Matching (Rectangle) color to override the bracket highlighting color. custom color Bracket

Lord_Curdin
  • 957
  • 1
  • 14
  • 27
  • I don't understand what you mean. Are you saying that the "Brace Matching (Rectangle)" setting is cancelling the effect of the other two? But it looks like there's no way to disable it. – Fabio says Reinstate Monica Apr 23 '18 at 21:53
0

When you're using ReSharper, you have to also set the color for ReSharper Matched Brace (it's in the same list as all Visual Studio color settings)

user963935
  • 493
  • 4
  • 20
0

Go to File/Preference/ Setting

on the setting click on the Extension, then BracketPair(you must download this extension first to show up here). In the BracketPair setting page, get you mouse hover on Bracket Pair Colorizer: Color Mode option, and a setting icon will appear, click on that, and choose the Copy Setting as JSON.Bracket Setting

From the drop-down you can choose either Consecutive or Independent. Click on the Edit in setting.json link below Bracket Pair Colors, and it will open a tab with JSON options to be edited. Based on your choice, you will see different JSON options. Keep in mind that you can change these options in User Setting and Workspace Seettings. In the User Setting tab, if you click on the Edit in setting.json link, the setting.JSON look like following:

{
"workbench.iconTheme": "material-icon-theme",
"http.proxyStrictSSL": false,
"editor.tabSize": 2,
"editor.detectIndentation": false,
"liveServer.settings.donotShowInfoMsg": true,
"workbench.colorTheme": "Solarized Light",
"editor.accessibilitySupport": "off",
"editor.colorDecorators": false,
"editor.highlightActiveIndentGuide": false

}

now you can paste the "Copy Setting as JSON" that you copied before, at the end of the last line of the JSON and your JSON shoul look like the following:

{
"workbench.iconTheme": "material-icon-theme",
"http.proxyStrictSSL": false,
"editor.tabSize": 2,
"editor.detectIndentation": false,
"liveServer.settings.donotShowInfoMsg": true,
"workbench.colorTheme": "Solarized Light",
"editor.accessibilitySupport": "off",
"editor.colorDecorators": false,
"editor.highlightActiveIndentGuide": false,
"bracketPairColorizer.consecutivePairColors": [
  [
    "()",
    [
      "Green",
      "Orchid",
      "LightSkyBlue"
    ],
    "Red"
  ],
  [
    "[]",
    [
      "Blue",
      "Orchid",
      "LightSkyBlue"
    ],
    "Red"
  ],
  [
    "{}",
    [
      "Red",
      "Orchid",
      "LightSkyBlue"
    ],
    "Red"
  ]
]

}

I changed all the Gold color, to Green, Blue and Red.

Note that, I change the key name on "bracketPairColorizer.independentPairColors", this was the default value on my VS Code Setting, to "bracketPairColorizer.consecutivePairColors" to reflect the option on Bracket Pair Colorizer drop-down. If you end you choosing the Independent, just remember to have it in the key name as independentPairColors.

To apply this setting in the Workspace Settings tab, when you click on the linkWorkSpace Settings and it will Open up a settings.json. in there you have the following:

{  "bracketPairColorizer.independentPairColors": [
[
  "()",
  [
    "Blue",
    "Orchid",
    "LightSkyBlue"
  ],
  "Red"
],
[
  "[]",
  [
    "Blue",
    "Orchid",
    "LightSkyBlue"
  ],
  "Red"
],
[
  "{}",
  [
    "Blue",
    "Orchid",
    "LightSkyBlue"
  ],
  "Red"
]

] }

Just keep in mind that you need to change the key name, "bracketPairColorizer.independentPairColors", based on the option you chose on drop-down, Consecutive or Independent

rodvind
  • 17
  • 2
  • 6
    Thanks, but my question is about [Visual Studio](https://visualstudio.microsoft.com/vs/), not [Visual Studio Code](https://code.visualstudio.com/)! They are very different, despite the similar name. – Fabio says Reinstate Monica Mar 07 '19 at 21:14
  • Thank you @rodvind your solution helped me fixing the same thing in `VSCode` :) – Tony Jun 07 '19 at 09:36
-4

Bracket pair colorization became a native VS Code feature with the latest update. In your settings.json file you can change the colours.

{
  "editor.bracketPairColorization.enabled": true,
  "workbench.colorCustomizations": {
  "editorBracketHighlight.foreground1": "#5caeef",
  "editorBracketHighlight.foreground2": "#dfb976",
  "editorBracketHighlight.foreground3": "#c172d9",
  "editorBracketHighlight.foreground4": "#4fb1bc",
  "editorBracketHighlight.foreground5": "#97c26c",
  "editorBracketHighlight.foreground6": "#abb2c0",
  "editorBracketHighlight.unexpectedBracket.foreground": "#db6165"
},
}
Ajay Singh
  • 150
  • 2
  • 14
  • 3
    Thanks, but my question is about [Visual Studio](https://visualstudio.microsoft.com/), not [Visual Studio Code](https://code.visualstudio.com/)! They are very different, despite the similar name. – Fabio says Reinstate Monica Oct 19 '21 at 08:07
  • Agree! the name looks similar, can't you open your visual studio projects in vscode? to enjoy this latest native support – Ajay Singh Oct 19 '21 at 10:52