Freigeben über


Moving Between Matching Braces (C#)

Keyboard:  CTRL + ]
Command:  Edit.GotoBrace
Versions:  2008,2010
Published:  10/15/2010
Code:  vstipEdit0075

 

In C# you can travel between matching braces by using the CTRL + ] shortcut.  Here is how it works:

 

To see the brace matching highlights, click to the left of an opening brace:

image

image

 

or to the right of a closing brace:

image

image

 

 

Now press CTRL + ] to go from one brace to the matching one.  Give it a try!  you should find yourself easily navigating between them.  This technique is very useful when you have braces far away from each other.

Comments

  • Anonymous
    October 14, 2010
    OMG! so simple and so useful. Can't believe I missed this before.  Thanks!

  • Anonymous
    October 17, 2010
    The nice part is that this works in C/C++ code as well.

  • Anonymous
    October 18, 2010
    This looks like a great feature indeed - a shame though that there is no separate ']' key on my (finnish/swedish) keyboard; the ']' symbol is on the '9' key for me, so trying to type CTRL-] would result in CTRL-9 instead. Of course keybindings are customizable in visual studio. The command for this seems to be called "Edit.GotoBrace" - I just bound CTRL-å to that :)

  • Anonymous
    January 22, 2011
    Is is possible to extend this #if/#else/#endif ?  SlickEdit does it, and it's very useful.

  • Anonymous
    January 22, 2011
    Is is possible to extend this to #if/#else/#endif ?  SlickEdit does it, and it's very useful.

  • Anonymous
    January 23, 2011
    CB -- although I didn't document it this DOES work with preprocessor instructions as well.

  • Anonymous
    January 23, 2011
    Thanks for the reply.  I use ViEmu and assumed '%' was mapped to Edit.GoToBrace...  When I manually mapped Ctrl+], it worked as desired.  I'll have to figure out what's going on with the ViEmu mappings...