Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching a closing brace in Visual Studio

Is there a setting in Visual Studio 2008 that I can turn on which would generate a matching closing brace for a opening brace?

EDIT: I would imagine that an IDE as powerful as Visual Studio would have this very useful feature.

EDIT: Is there a macro that can be written? From the responses I have received it looks like ReSharper is the only option. I don't want to have to ask my company to invest in the ReSharper tool, I work for a rather large enterprise and getting anything approved from procurement is not an easy task.

EDIT: I am using VS 2010 Ultimate. The Power Tools and Power commands now do everything I was looking for in this post.

like image 777
Developer Avatar asked Jan 15 '09 19:01

Developer


People also ask

How do you jump to a closing tag in VS code?

In this case you can simply press Ctrl + Shift + . to go to elements before or after the current element.

What is the main function of the highlight matching brackets option?

Bracket-matching provides visual cues illustrating the location of matched pair elements. With bracket-matching enabled, positioning the cursor on one paired element highlights the matching element in the code sequence.


2 Answers

I know the original question is about VS2008, but I'm putting this here as info for other people and to make it useful for recent versions

VS 2010 and VS 2012

The Productivity Power Tools (available for VS2010 and VS2012) extension now supports automatic brace completion.

If you already have it installed for VS2010, you must update to at least version 10.0.10710.22. Click

Tools -> Extension Manager -> Updates

Once you have it installed, you can turn brace completion on or off by going to

Tools -> Options -> Productivity Power Tools -> All Extensions -> Automatic Brace Completion

The most recent version now provides the ability to turn of any features you don't like so you can configure it to your requirements

VS 2013

Even though there's a matching addin for Visual Studio 2013 as well, VS now has native support for automatic brace completion without using any addins. Just go to:

Tools -> Options -> Text Editor -> C#

Tick checkbox against Automatic brace completion

like image 51
Simon P Stevens Avatar answered Oct 02 '22 06:10

Simon P Stevens


I use ReSharper. It does a whole lot more besides just the closing brace. The only downside is it's not free. But give it a try. The code analysis is worth the price anyway.

like image 40
Simon Hughes Avatar answered Oct 02 '22 05:10

Simon Hughes