Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio code goto matching bracket from bottom to top

I know there is a shortcut for cmd + shift + \ to go to matching bracket

this is also documented here https://code.visualstudio.com/shortcuts/keyboard-shortcuts-macos.pdf

But this only works when the cursor is at the opening bracket and you want to jump at closing bracket. So its not really matching...its actually closing.

But if you have a class like

object Foo {
....
}

and you take the cursor to the closing bracket and now you press cmd + shift + \ then vscode does nothing.

So it only works from opening to closing .... but how to go from closing to opening?

Similarly, when you take the cursor to the opening bracket, visual studio code will highlight the closing bracket. but if you take the cursor to the closing bracket, vscode will do nothing. now it will not highlight the opening bracket.

How can I have it both ways.

like image 265
Knows Not Much Avatar asked Feb 11 '18 22:02

Knows Not Much


People also ask

How do you match braces in Visual Studio?

Go to matching brace in Visual Studio with Ctrl+} shortcut To move the caret to the matching brace of the one it's currently on press Ctrl+}. This is very handy for navigating code which might have multiple levels of if/else block nesting, although do try and avoid this kind of code by using guard clauses if you can.

How do I enable native bracket matching VSCode?

The feature can be enabled by adding the setting "editor. bracketPairColorization. enabled": true .


1 Answers

I'm not sure what the situation was at the time of this question, but as of the latest version of Visual Studio Code, CtrlShift\ toggles between both the opening and closing bracket of a code block.

I personally find the default key binding a bit awkward, so I remapped it to CtrlAlt\ by going to File > Preferences > Settings, clicking the curly braces icon to edit the settings.json file directly, and adding the following code inside of the square brackets:

{ 
    "key": "ctrl+alt+oem_5",
    "command": "editor.action.jumpToBracket",
    "when": "editorTextFocus" 
},
like image 95
Hashim Aziz Avatar answered Oct 18 '22 02:10

Hashim Aziz