views:

1695

answers:

7

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.

+6  A: 

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.

Simon Hughes
+2  A: 

Believe it or not, automatic brace closing still doesn't come as standard in VS2008. Like Simon, I use ReSharper to get this functionality and a whole lot more.

Kev
A: 

Depends on what you are looking for VS does have some standard auto completion if[tab][tab] and for[tab][tab] try[tab]tab will get you more than the matching braces in a really nice fashion.

Alex
+4  A: 

Most of the time, you can use autocompletion and code snippets.

If you want to write a for loop, just type "for" and then TAB. VS will complete it (including the braces).

Same thing for if, struct, class, switch... You don't even have to type the first brace !!

Good paper about it here : http://blogs.techrepublic.com.com/programming-and-development/?p=655

Sylvain
A: 

Late to the party here, but I guess you got use an independently running AutoHotKey script to insert closing brackets/quotes for you.

Protector one
A: 

If you don't want to pay for ReSharper or a similar package, I made a free extension to automatically close braces. You can find it in the Visual Studio Gallery at http://visualstudiogallery.msdn.microsoft.com/en-us/0e33cb22-d4ac-4f5a-902f-aff5177cc94d. It will only work in Visual Studio 2010 though.

Joel
A: 

The Productivity Power Tools extension now supports automatic brace completion. (This extension is for VS2010 only, and I know the original question is about vs2008, but I'm putting this here as info for other people)

(If you already have it installed, 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->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)

Simon P Stevens
I installed it the very day it was released :)
Nick