When working with TypeScript or other languages in Visual Studio, I often find it useful to quickly navigate between matching braces, parentheses, or brackets. Visual Studio has a built-in shortcut that makes this incredibly easy.
Thank me by sharing on Twitter 🙏
My Stackoverflow answer on this topic here.
Steps to Quickly Navigate Between Matching Braces
- First, place your cursor either right before or after the brace, depending on your preference.
- Then, press Ctrl + ]. Visual Studio will automatically jump to the matching brace. Whether you’re working with parentheses
()
, brackets[]
, or braces{}
, this shortcut works consistently. - Additionally, if you need to select the code block between those matching braces, just hold down
Shift
while using the shortcut. This comes in handy when refactoring or copying code segments.
macOS Users
For those using Visual Studio on a Mac, the equivalent shortcut is Cmd + Shift +
\.
Customizing the Shortcut
If you find that the default shortcut isn’t working, or you prefer using a different key combination, it’s easy to customize:
- Navigate to
Tools -> Options -> Environment -> Keyboard
. - In the search box, look for
Edit.GotoBrace
. - Here, you can see the current key combination assigned and change it if needed.
This customization is especially useful if there’s a conflict with the default keybinding or if you have a specific workflow in mind.