When dealing with deeply nested brackets in Visual Studio, it can be hard to figure out which brackets match and which do not. For people with color blindness or other optic maladies, the problem can be even worse. By color-coding bracket pairs, we’re making this much easier.
Various IDE’s and editors offer this feature today – usually done through extensions. For example, the Viasfora extension for Visual Studio has provided this feature for many years. What’s interesting about all these implementations is how they all do things a bit differently. Granted, they all colorize bracket pairs, but the way they do it differs and a lot of them provide additional features and options.
A feature request on the Visual Studio Developer Community is also now gaining steam asking for colorized bracket pairs, so please vote and comment if you agree.
So, with increased interest and multiple viable solutions, what would the right implementation look like for Visual Studio users?
Let’s do an experiment to find out.
The experiment
We’re starting out with an extension to kick off the experiment. We call it Rainbow Braces and the first iteration adds basic colorization to curly brackets, square brackets, and parentheses (see image above).
Figure 1: Colorized bracket pairs in both light and dark theme
It has four unique colors that it will cycle through and repeat for as many levels deep as needed. The colors work equally well for both light and dark themes and can be customized in the Fonts and Colors options page.
You can easily toggle the colorization on and off from the Edit -> Advanced top-level menu. Or use the keyboard shortcut Ctrl+Shift+9 to execute the Toggle Rainbow Braces command.
Next steps
If this feature is interesting to you, please install the Rainbow Braces extensions and take it for a ride. Make sure to share any ideas and bugs on the GitHub issue tracker, and feel free to send pull requests too. The feature request ticket is a suitable place to share your comments and thoughts, so make sure to vote and comment there as well.
Do you like the idea of community experiments like this one? Let us know in the comments below.
It’s cool extension, thanks Mads! But I left only parentheses to highlight (because it’s the one case when you need help) As an option, it could be nice to see some UNDERLINE between paired parentheses (to easier catch what portion of expression is bracketed).
Advice #2: I made first color to highlight as BLACK, so when you have only single brackets, they look like normal code. No need to convert code into parrot sh***t. 🙂
One of the top and certainly my most requested features is coloring the angular brackets, that’s the used for deeply nested C++ templates when doing meta-programming magic. I think of a naive implementation based of textual analysis is quite difficult so none of the extensions provide this feature. Microsoft please make it happen!
Visual Studio has always had the feature where highlighting one brace highlights the matching brace. (Its a little flaky on my install, but mostly works).
So: if the coder highlights a brace, why not show a context menu to add this colouring – and turn it off when no longer needed. That should keep everyone happy.
Speaking as a colorblind individual. It actually made my condition worse. I only see brightness/contrast with very little color. The darker the color the more dim it becomes fading into gray. I can see color in the green to bright orange range but reds and deep blues are either not there (red) or black (deep blues). I turned it off, at least black and white work for me.
this would simplify reading code extensively!! hope to be able to use soon!
Very useful for parenthesis nesting.
Have to agree that the default colors aren't great, but they are easy enough to change. Switched to a more visually distinct set with more contrast between levels and it's much easier to parse.
Will be glad to see this as a supported feature. Once angle brackets and the vertical markers for code blocks get added to the feature list, it should cover any use cases I have. Definitely plan to...
From namespace to function via class three bracket pairs will be used defaults
Four levels are insufficient. seven levels are Ok
or just start from level four?
I used it for some days and I definitely like it, except the default red color was too much and I changed it to a soft blue.
Would that be soft dome ish?
They forgot something, add colorization options for both < and > in generic types.
I think this is a great idea. Though I think the default colors you guys picked are too similar. 3 of the 4 are reddish in tone (orange, red, pink). Better defaults are definitely needed.