Rainbow Braces for Visual Studio makes it easier for developers to figure out which brackets match each other. Many IDE’s provide this feature via extensions, and a feature request on the Visual Studio Developer Community is gaining traction. This feature has been added to the Visual Studio roadmap. There is, however, an extension you can use today to try out colorized braces in Visual Studio.
Not quite what you were looking for? Try these links instead.
- Required Properties in C# 11
- Code Optimization using Span<T> : An Introduction
- Static Abstract Interface Members in C#11
- Rate Limiting in .NET 7
Rainbow Braces Visual Studio Extension
This is a free extension available for Visual Studio 2022 and is available on the Visual Studio Marketplace.
Installing Rainbow Braces
To use this extension, you will first need to install it. In Visual Studio 2022, go to the Extensions menu and click on Manage Extensions.
From the Manage Extensions window, search for Rainbow Braces to download and install it for Visual Studio 2022. After clicking on Download, close Visual Studio and the VSIX Installer will launch, installing the extension for Visual Studio 2022. Once Visual Studio has been restarted, the extension will be active and your code will display colorized matching braces.
Personally, I do not really like the color orange. Luckily for me, I can configure Rainbow Braces to suit my color preferences.
Configuring Rainbow Braces
To change the color of the braces, head over to Tools and click on the Options menu. Under Environment, click on Fonts and Colors and scroll down until you see Rainbow Braces.
Here I have changed the brace color for second level braces to Magenta and made the braces bold. I also changed the color of the third level to Teal.
The result is immediately applied to my code and the second-level and third-level braces are colorized as per my settings earlier.
You can also choose exactly what to colorize. By default, Rainbow Braces will colorize curly braces, parenthesis, and square brackets.
To switch off the colorization of parenthesis, for example, in the same Options window, click on Rainbow Braces under Fonts and Colors. Here you can choose which sections of code get colorized.
You can also toggle this extension on or off by holding down Ctrl+Shift+9 or by going to Edit, Advanced, and toggling the checkbox next to the Show Rainbow Braces option.
Rainbow Bracket Colors for Visual Studio 2019
Viasfora is a Visual Studio extension that has provided bracket colors for years. The current version only supports Visual Studio 2022. Still, if you need to add rainbow braces for older versions of Visual Studio, you can get an older release from the releases page.
Bracket Colorization for Visual Studio Code
Ah, good old Visual Studio Code. The great news is that bracket colorization is now native to Visual Studio Code. Just make sure that you have Visual Studio Code updated to the latest version and then open your settings by going to File and clicking on Preferences and then Settings.
You can then search for the setting by typing Bracket Pair Colorization and the setting should be displayed. This is enabled by default. You can then use the Workbench: Color Customizations to change the default bracket colors.
The colorized brackets also look really great with a dark theme enabled. Just be sure to uninstall any other Visual Studio Code extensions that perform bracket colorization. There have been several excellent bracket pair colorizer extensions developed, most notably, by a user called CoenraadS that have now been depreciated. You can read more about what was done to make the bracket colorization feature in Visual Studio Code much, much faster by reading the blog post: Bracket pair colorization 10,000x faster by Henning Dieterichs.
Bracket colorization is a useful feature in Visual Studio and Visual Studio Code. Highlighting the matching braces in different colors allows developers to easily see how code is structured and will allow them to identify mismatched braces.
I hope this blog post has been helpful in getting you started with colorizing braces in Visual Studio 2022. If you have any questions or comments, please feel free to leave them below. Happy coding!