Highlight enclosing bracket in Visual Studio Code - visual-studio-code

Is there a way to highlight brackets when the cursor is anywhere within the enclosing brackets? Default settings highlight it only when I place the cursor near the brackets.

Yes, there is now a way by default, in VSCode 1.40 (October 2019):
Improvements to bracket matching
Previously, VS Code would only highlight matching brackets when the cursor was next to a bracket character.
Now VS Code will always highlight enclosing brackets if they exist.
We have also adjusted our Go to Bracket and Select to Bracket actions to use enclosing brackets.
It is improved and supported natively with VSCode 1.60 (Aug. 2021):
Bracket pair colorization can be enabled by setting "editor.bracketPairColorization.enabled": true.
All colors are themeable and up to six colors can be configured.

VS Code only supports bracket matching when the cursor is near the opening or closing bracket. Maybe an extension would help highlight the enclosing brackets wherever you are in the code but I haven't been able to find one.
If you just want to quickly find matching brackets, braces, parens, etc. you could try Bracket Pair Colorizer or Rainbow Brackets.

Also maybe you will like VSCode extension "Blockman", it highlights nested code blocks. (I am the author of Blockman)

With release 1.60 (September 2021), VS Code now has bracket pair colorization built in, indicating all matching brackets by color.
This feature can be enabled by adding this line to settings.json:
"editor.bracketPairColorization.enabled": true

I am using Version: 1.63.2(MacOS). Default bracket highlight feature was not working for me. In case, someone face similar issue, set it true.
"editor.matchBrackets": true,

Related

How to set matching bracket color in vscode?

I would like matching brackets in vscode to be colored instead of given a border/background. What is the correct property for it in setting? Currently I have this:
{
"workbench.colorCustomizations": {
"editorBracketMatch.border": "#000",
"editorBracketMatch.background": "#000"
}
}
How should I modify this to get the desired result?
VSCode 1.60, Aug. 2021 will support that directly:
High performance bracket pair colorization
The editor now supports native bracket pair colorization:
Bracket pair colorization can be enabled by setting "editor.bracketPairColorization.enabled": true.
All colors are themeable and up to six colors can be configured.
We implemented this feature to address performance issues of the famous Bracket Pair Colorizer extension by CoenraadS.
In the settings, you can set colors from foreground1 to foreground6:
colorCustomizations:
{
"workbench.colorCustomizations": {
"editorBracketHighlight.foreground1": "#3700ff",
"editorBracketHighlight.foreground2": "#66ff00",
"editorBracketHighlight.unexpectedBracket.foreground": "#ff0000",
}
}
VSCode 1.66 (Feb. 2022) will port over a feature from Bracket Pair Colorizer 2:
"bracket-pair-colorizer-2.colorMode"
Consecutive brackets share a color pool for all bracket types
Independent brackets allow each bracket type to use its own color pool
See commit d54c705 and setting editor.bracketPairColorization.useIndependentColorPoolPerBracketType.
See also "Custom brace highlighting in Visual Studio Code" with VSCode 1.76, Feb. 2023, where you can configure highlights for a subset of brackets.

Highlighted Indent Guides VS CODE

How to change like the images above?
Try using Bracket Pair Colorizer extension, it will generate colorized brackets like this :

How to disable angle bracket highlighting in Visual Studio Code?

I just want to disable the character highlighting that happens on angle brackets, as I find the square box to be annoying. Is there a way to turn it off?
You can search keyword highlight in setting, and you change Editor:Match Bracket to never, like this:
You can use the following:
// Highlight matching brackets when one of them is selected.
"editor.matchBrackets": false, however it disables highlighting all the brackets not only the angle brackets.
You can always make the bracket border color transparent with these settings:
"workbench.colorCustomizations": {
"editorBracketMatch.border": "#0000",
"editorBracketMatch.background": "#000"
}
This will make the border transparent and the bracket's background black - or just make it something less obtrusive given your editor background. But again, this will apply to all brackets, not just angle brackets.
Unfortunately it's still unconfigurable. Maybe they will improved it.
Here is my ticket in VSCode repo that you can watch - https://github.com/microsoft/vscode/issues/73521.
As long as they do not improve, you have two ways
Solution with addon:
Disable native bracket matching: "editor.matchBrackets": false,
Install addon from https://marketplace.visualstudio.com/items?itemName=rafamel.subtle-brackets
Customize it for better visuality, example:
"subtleBrackets.style": {
"borderStyle": "solid",
"borderColor": "#CC7832",
"borderRadius": "3px",
}
Native solution without addon:
You can disable bracket matching highlight only for specific language:
"[html]": {
"editor.matchBrackets": false
}
Note that this is not a perfect solution, because when using html in php files, angle brackets are still highlighted
You can add this
{
"editor.matchBrackets": "near"
}
somewhere in ~/.config/Code/User/settings.json. This means that all projects inherit behavior.
This way, only when you move the cursor over a bracket, the corresponding one is shown.
Yaa. there is a solution for hiding the annoying marking I just found. go to the setting button in left bottom side then write- angle bracket -in the search option and search as well. Then press the "text editor", a selecting option will come in the top named "Editor:Match Brackets". Select "Never" and your work is done here. See the attached picture if needed.

Custom brace highlighting in Visual Studio Code

Is it possible to customize the brace highlighting in Visual Studio Code? It seems just about everything else is customizable through user and workspace settings, as well as textmate themes. Regardless of the syntax highlighting you employ, the braces always have the same light gray outline/rectangle around them. I don't see an existing user/workspace setting or a textmate scope that addresses this specific feature.
Ultimately I'd like to have a solid color highlight of matching braces, similar to what you would get with the default dark theme in Visual Studio 2013 and 2015.
For future reference, vscode now has the option to change the color of bracket highlighting by adding this to settings.json:
"workbench.colorCustomizations" : {
"editorBracketMatch.background": "#f008",
"editorBracketMatch.border": "#f00"
}
Formats supported are #RGB, #RGBA, #RRGGBB, #RRGGBBAA. The rgba(255,255,255,1) format that seems to work in other places in the settings file appears to not work here.
Only feature that is still missing regarding this subject is bracket highlighting when the cursor is between brackets. They only highlight when one of the brackets is selected. I did not find a current solution searching trough the Settings or workbench.colorCustomizations.
Update 2018.04.21
There is now a plugin called Bracket Pair Colorizer that does shows the current brackets besides the line number no matter where the cursor is placed within the brakes. But on slower hardware (3nd generation i5 laptop) i encountered slowdowns with it when editing large files (3000+ line php file). And alternate plugin that performs well on the same file and highlights the current indentation is Guides.
Update 2019.11.10
VSCode 1.40 now highlights the brackets enclosing the cursor.
Update 2021.08.09
as #desilicius mentioned in the comments Bracket Pair colorizer is no longer maintained by the author. He offers as an alternative Blockman - Highlight Nested Code Blocks which has the same functionality but has a totally different look and Highlight Matching Tag which is a great plugin but only works on html (and jsx) tags as the name implies.
Update 2021.08.13
The VSCode team decided to add bracket pair colorization as a built in feature. It is worked on right now with improvements of 10k x the speed of BPC2. The discussion can be found here
You can try Bracket Pair Colorizer 2 Extension.
Highlighting and changing colors of brackets in VS Code is now possible.
You can try this extension Subtle Brackets by modifying the following the default values in the .json settings of VS Code:
I changed it like this:
"subtleBrackets.bracketPairs": [
"{}",
"[]",
"()",
"<>"
],
"subtleBrackets.styles": {
"global": {
"color": "yellow",
"borderWidth": "1px",
"borderStyle": "none none solid none"
}
}
Don't forget to set to "false" the value of .matchbrackets of VS Code.
"editor.matchBrackets": false
Update September 2021: The "Bracket pair colorization" feature is now available in VS Code as of the August 2021 (version 1.60) update.
Add this to your settings.json file:
"editor.bracketPairColorization.enabled": true
After saving the file, brackets should instantly be colorized.
Also maybe you will like VSCode extension "Blockman", it highlights nested code blocks. (I am the author of Blockman).
The VSCode extension "Blockman" is a new approach of dealing with brackets, well, it does not highlight brackets themselves, but it renders blocks based on the brackets (curly/square/round brackets/braces), and I think it is a better visual helper for our eyes to perceive code structure more easily, to understand code structure more quickly and more comfortably.
If you want to remove brackets color and border, you can use hex colors with 0 opacity in your settings.json:
"workbench.colorCustomizations": {
"editorBracketMatch.border": "#ffffff00",
"editorBracketMatch.background": "#ffffff00",
}
You can overwrite any theme:
"workbench.colorCustomizations": {
"[*]": {
"editorBracketMatch.border": "#ffffff00",
"editorBracketMatch.background": "#ffffff00",
}
}
In order to target a specific theme, replace the glob character, *, with the theme name.
Custom brace highlighting will be even more precise with VSCode 1.76 (Feb. 2022), with issue 170497 and PR 172758: it brings support for coloring a subset of the matched bracket.
Example:
"[plaintext]": {
"editor.language.brackets": [
["{", "}"],
["(", ")"],
["[", "]"]
],
"editor.language.colorizedBracketPairs": [
["{", "}"],
["<", ">"]
]
},
Gives:
This is available with VSCode Insiders today.

Autoclose brackets and quotes in IPython

Is there a way to autoclose brackets and quotes in IPython.
Just like in RStudio when you type an opening bracket like [ it automatically types the closing bracket ] and moves the cursor inside the brackets. Same thing with quotes.
Possible, probably not too hard, but not trivial. Might need to update the underlying library (in progress), and to dig in CodeMirror doc to see if there is already such an option. If you are interested in diving in the code/submit Patch I would suggest asking for directions on the ML / on github.