598

Is there a way in Visual Studio 2008 to go from a closing brace to its opening brace? I've found a fair amount of stuff about highlighting the brace, but nothing about moving the cursor to it.

(VB.NET version of this Question: Keyboard shortcut for Jumping between "If/End If")

Walter Stabosz
  • 7,447
  • 5
  • 43
  • 75
thepocketwade
  • 6,436
  • 5
  • 22
  • 25
  • 1
    incredibly, this seems to not work (2019) for .js files on Mac Visual Studio. WTH ?! – Fattie Sep 17 '19 at 16:33
  • @Fattie, It doesn't work in Windows 10 for .cs files either. I am pretty confident this is an across-the-board thing for VS 2019 so I made a new question: https://stackoverflow.com/q/59183422/1739000 – NH. Dec 04 '19 at 19:31
  • Instead of trying to CTRL+F this page for whatever language keyboard you are using, use [this answer](https://stackoverflow.com/a/6309463) to figure it out in Visual Studio settings. – General Grievance Dec 29 '21 at 15:37
  • 2
    Since you might be here about VS Code, here is the question for that instead: https://stackoverflow.com/questions/30097634/how-do-i-jump-to-a-closing-bracket-in-visual-studio-code – General Grievance Dec 29 '21 at 22:14
  • here's a little nit that's been driving me nuts. if you go to a matching brace in c++ and it's above your current position, it will put the carat on the matching brace and it will be the first line on the screen, you then have to arrow up to see what it's a brace for. is there any way to have to match and be a few lines down or in the middle of the screen? I know it's an edge case, but I run into this constantly. – stu Mar 02 '23 at 19:53

28 Answers28

808

I found this for you: Jump between braces in Visual Studio:

Put your cursor before or after the brace (your choice) and then press CTRL + ]. It works with parentheses ( ), brackets [ ] and braces { }. From now on you don’t need to play Where’s Waldo? to find that brace.

With the above shortcut, you can also hold SHIFT to select.

On MacOS, use CMD + SHIFT + \ .

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Tim Santeford
  • 27,385
  • 16
  • 74
  • 101
  • 56
    Just for information, on a Norwegian keyboard the short-cut for this is `Ctrl`+`Å` (same as for Danish keyboard mentioned in an answer below). – Julian Nov 24 '10 at 09:37
  • 13
    On Belgian azerty it seems to be `ctrl`+`^`, which is, oddly, on the key which also has the `[` bracket (which needs `AltGr` to be typed). – Nyerguds Oct 29 '12 at 10:29
  • 5
    Icelandic keyboard CTRL + Ð – Ingó Vals Apr 29 '14 at 11:18
  • 2
    For Czech QWERTZ keyboard it's CTRL + ). Exactly same position, where English keyboard has ] key. Just above Enter. – Tomas Tintera Nov 03 '16 at 12:39
  • @Ian The main answer applies to British keyboards, CTRL + ] – pauloya Aug 01 '17 at 12:21
  • 1
    If you're working in a `.sql` file, `CTRL` + `]` will toggle between `BEGIN` and `END` pairs. (VS 2015) – Walter Stabosz Apr 17 '18 at 15:12
  • Brazilian portuguese `abnt-2` keyboard: `Ctrl` + `Shift` + `]`. There is no shortcut for "select to bracket" by default. – Marc.2377 Dec 05 '18 at 17:41
  • In my Dvorak keyboard mapping on my Mac, this turned out to be CTRL + =, which is bound to ] in the Dvorak mapping. – pohl Oct 04 '19 at 16:29
  • otherwise there is an extension that add the support for " and ' too https://marketplace.visualstudio.com/items?itemName=chunsen.bracket-select with a simple shorcut alt+ a, for mac it is better because it selects whileCMD + SHIFT + \ don't select – bormat Nov 06 '19 at 15:43
  • I wasn't able to find the shortcut combination in Mac, at the end I use: `CTRL` + `SHIFT` + `CMD` + `LEFT ARROW` or `RIGHT ARROW` after the bracket `{` – Edenshaw Feb 03 '20 at 14:12
  • 1
    German keyboard: `Strg` + `´` – Cerno Mar 03 '22 at 17:16
  • Swiss German Keyboard : `Ctrl` + `Shift` + `à` or with "Atom Keymap" extension : `Ctrl` + `M` – Jasmin Apr 20 '23 at 07:35
123

I use Visual Studio 2008, and you can customize what you want this shortcut to be.

Click menu Tools -> Options -> Environment -> Keyboard. Then look for Edit.GotoBrace.

This will tell you what key combination is currently assigned for this. I think you can change this if you want, but it's useful if the Ctrl + ] doesn't work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
funkymushroom
  • 2,079
  • 2
  • 26
  • 39
  • 7
    This is very useful to find keybindings for other languages' keyboards. – Afonso Matos Jul 01 '16 at 12:32
  • 1
    Yes, we should always respond to command questions with the command name in case the keyboard is different or the default shortcut has been removed. Also check out Edit.GotoBraceExtend, if you map Ctrl+[something] to Edit.GotoBrace, you'll probably want to map Ctrl+Shift+[something] to Edit.GotoBraceExtend. – hsandt Nov 09 '18 at 17:19
  • 1
    This was useful for me because it wasn't set for me at all in VS 2017. – Mmm Dec 13 '18 at 23:54
115

Use CTRL + ] to switch between them. Place the cursor at one of the braces when using it.

Ahmad Mageed
  • 94,561
  • 19
  • 163
  • 174
26

If for some reason this is NOT working for you, something may have messed up your keyboard bindings (it didn't work for me). You can re-enable the binding easy enough though - at least so I thought:

I tried this procedure:

  • Go to menu Tools -> Options -> Environment -> Keyboard
  • Scroll to, or search for the command Edit.GotoBrace
  • Assign the desired shortcut (mine was empty, so I put in CTRL    + ])
  • Be sure to click the "Assign Button"

I tried it, and it still didn't work. I restarted Visual Studio, and it still didn't work - well it ONLY worked for .cs files, but I need it to work for .vb files and text files, and...well ALL files!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Paul Gorbas
  • 1,694
  • 20
  • 16
26

Note: It also works for #if / #elif / #endif matching. The caret must be on the #.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pierre
  • 4,114
  • 2
  • 34
  • 39
22

On my French keyboard, it's CTRL + ^.

Matthieu Rouget
  • 3,289
  • 18
  • 23
  • Thanks it works but where did you found it ? In my french version of Visual Studio, I did not found any equivalent to Edit.GotoBrace in Outils -> Options -> Environnement -> Clavier (proposed by other answers). – kingsjester Aug 07 '23 at 09:36
20

On a German keyboard it's Ctrl + ´.

Baldewin
  • 1,613
  • 2
  • 16
  • 23
  • 1
    For me this works on a German keyboard: 1. `Strg`+`´` : hightlights a span included by parentheses/braces/brackets. 2. `Left` or `Right` arrow key to jump to the begin or end of the highlighted span (and turns of the highlighting). – VCSEL Oct 20 '22 at 14:36
13

And Ctrl + Shift + ] will select all of the text.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
JCS in Tampa
  • 131
  • 1
  • 2
13

On a Spanish keyboard it is CTRL + ¿ (or CTRL + ¡).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Keith
  • 375
  • 2
  • 7
13

On a Turkish keyboard, it is Ctrl + ü.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Turkdogan Tasdelen
  • 898
  • 1
  • 11
  • 25
12

On my Danish keyboard it's CTRL + Å.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Raymond
  • 121
  • 1
  • 2
11

For completeness sake, on a Swedish keyboard it's CTRL + å .

Also, I guess logical, but worth mentioning CTRL + shift + å (for capital Å), selects everything inside the braces and goes to the matching one.

Ola Karlsson
  • 9,011
  • 7
  • 27
  • 37
10

On my Portuguese keyboard and SO with EN VS, it's CTRL + « to navigate to matching brace and CTRL + SHIFT + « if you intend to select the inner code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
9

On my Italian keyboard, it's CTRL + ^.

j0k
  • 22,600
  • 28
  • 79
  • 90
Peppe
  • 91
  • 1
  • 1
9

On my pt-BR (Brazilian Portuguese) keyboard it is actually CTRL + [.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
karlphillip
  • 92,053
  • 36
  • 243
  • 426
8

On my Slovenian keyboard it is ALT    + Đ

Simon Dugré
  • 17,980
  • 11
  • 57
  • 73
skz
  • 81
  • 1
  • 1
7

For Visual Studio Code (as seen in their documentation), use Ctrl+Shift+\.

The setting can be found in:

File/Preferences/Keyboard Shortcut

I am using Visual Studio Code 1.8.0 . Note Visual Studio Code may behave differently for international keyboards (as seen in this answer re: German keyboard)

Hope this helps someone.

Nate Anderson
  • 18,334
  • 18
  • 100
  • 135
Claudiu Hardalau
  • 167
  • 1
  • 11
  • Note: this is for Visual Studio __Code__. The question is about Visual Studio. There is a [separate question](https://stackoverflow.com/questions/30097634/how-do-i-jump-to-a-closing-bracket-in-visual-studio-code) for VS Code. – General Grievance Dec 29 '21 at 22:16
7

On a Mac use command+shift+\.

Source: a comment on this answer: https://stackoverflow.com/a/37877082/3345085. Tested in Visual Studio Code version 1.10.2.

Community
  • 1
  • 1
Logan
  • 1,575
  • 1
  • 17
  • 26
  • 1
    Note: this is for Visual Studio __Code__. The question is about Visual Studio. There is a [separate question](https://stackoverflow.com/questions/30097634/how-do-i-jump-to-a-closing-bracket-in-visual-studio-code) for VS Code. – General Grievance Dec 29 '21 at 22:15
6

Details that can benefit everyone (Linux/Win/Mac)

The command in the keyboard shortcuts menu/editor is editor.action.jumpToBracket there you can set it to whatever you like. There is also one called editor.action.selectToBracket which has no shortcut by default (at least on Mac).

Etc.

On the Mac editor.action.jumpToBracket starts out as Cmd+Shift+\ and I changed it to Ctrl+] to be in line with what others say here. I did so in the hopes that I could use Ctrl+Shift+] to "Extend selection to matching bracket". That is what lead me to discover the details above. I set editor.action.selectToBracket to Ctrl+Shift+] and got exactly the behavior I wanted.

Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149
6

On my Dutch (Belgian) keyboard, it's CTRL + ^.

Jasper
  • 2,166
  • 4
  • 30
  • 50
Ward Coessens
  • 61
  • 1
  • 1
6

Goto Tools > Options > Environment > Fonts and Colors, select the "Brace Matching (Rectangle)" and change the "Item Background" to e.g. Yellow. This worked for the C# parentheses () {} and [].

animuson
  • 53,861
  • 28
  • 137
  • 147
  • Yes helpful & 'Display Name' text box of Fonts & Colors is where Brace Matching Rectangle is located. – Catto Oct 07 '14 at 15:26
  • If you have the dark theme like I do, cyan instead of yellow will also make the bracket itself more visible. – Bora Apr 08 '15 at 07:41
5

On a Hungarian keyboard it is Ctrl + ú.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zéiksz
  • 688
  • 1
  • 11
  • 25
4

A bit relevant, but for HTML tags: (since there is no built-in solution, Ctrl + J doesn't work for HTML tags : )

Here is the answer as a macro which I've built which does it (toggle), including go to focus:

Here is the demo:

Enter image description here

And here is the code. Enjoy!

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Windows.Forms

Public Module Module2
    Sub beginToEnd()

        'Place the cursor somewhere in the beginning tag, run the macro, to select from beginning to end tag

        DTE.ActiveDocument.Selection.SelectLine()
        Dim objSel As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint As TextPoint = objSel.TopPoint
        Dim lTopLine As Long = topPoint.Line
        objSel.GotoLine(lTopLine, False)
        '  DTE.ActiveDocument.Selection.StartOfLine()
        DTE.ActiveDocument.Selection.SelectLine()
        Dim line1 As String = DTE.ActiveDocument.Selection.Text()

        If InStr(line1, "/") Then

            ' MsgBox(line1)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
            objSel.GotoLine(lTopLine, False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        Else
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine(False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        End If

        DTE.ActiveDocument.Selection.SelectLine()
        Dim line2 As String = DTE.ActiveDocument.Selection.Text()
        Dim objSel3 As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint3 As TextPoint = objSel3.TopPoint
        Dim lTopLine3 As Long = topPoint3.Line
        objSel.GotoLine(lTopLine3, False)
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, False)
    End Sub
End Module
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
3

In Visual Studio Code on german keyboard it's ctrl+shift+^

But you have to open a file with correct extension - it's not working in new unsaved files for example.

Markus
  • 1,360
  • 1
  • 16
  • 22
  • Note: this is for Visual Studio __Code__. The question is about Visual Studio. There is a [separate question](https://stackoverflow.com/questions/30097634/how-do-i-jump-to-a-closing-bracket-in-visual-studio-code) for VS Code. – General Grievance Dec 29 '21 at 22:16
2

On the Swiss-French keyboard : use CTRL + SHIFT + ^

Fabio Salvalai
  • 2,479
  • 17
  • 30
2

On Spanish (Spain) keyboard with VS2012 is Ctrl + ¡ as stated by @Keith but if you use Ctrl + ¿ (typed as Ctrl + Shift + ¡) then goes to Matching Brace plus selects all the code within the two braces and then you can't go again to the other brace.

David Oliván
  • 2,717
  • 1
  • 19
  • 26
0

June 2021

On a Mac running Windows 10 under parallels for Visual Studio 2019 and c# and with US keyboard the solution which worked for me was to edit the shortcut in" Tools Options Keyboard Edit.GoToBrace

On my system that shortcut was blank...

Press the Ctl key and the ] key and save the shortcut

SunbeamRapier
  • 127
  • 2
  • 11
0

Windows, Visual Studio 2017, C++, Hungarian keyboard, Ctrl+ú

In Options/Environment/Keyboard, check Editor.GotoBrace.

TrueY
  • 7,360
  • 1
  • 41
  • 46