Matching a closing brace in Visual Studio

后端 未结 8 1025
别跟我提以往
别跟我提以往 2021-01-17 11:01

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 p

相关标签:
8条回答
  • 2021-01-17 11:24

    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.

    0 讨论(0)
  • 2021-01-17 11:26

    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 : https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/programming-and-development/?p=655

    0 讨论(0)
  • 2021-01-17 11:39

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

    0 讨论(0)
  • 2021-01-17 11:42

    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.

    0 讨论(0)
  • 2021-01-17 11:44

    In VS 2013 there is the option of "Automatic delimiter highlighting" (under tools, options, text editor) and while checking that box should highlight matching braces, it doesn't under default settings. This is because the default background is white, and the default highlight color is also white. This can be changed by going to environment, fonts and colors, and changing the background color of "brace matching (rectangle)". Then matching braces will be highlighted and visible.

    I realized after I answered that the question was creating the brace not being able to find existing braces. As that's the question I was trying to answer when I ended up here I'm leaving the answer in case it's helpful.

    0 讨论(0)
  • 2021-01-17 11:46

    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

    0 讨论(0)
提交回复
热议问题