visual-studio 在 Visual Studio 中匹配右大括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/448186/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Matching a closing brace in Visual Studio
提问by Developer
Is there a setting in Visual Studio 2008 that I can turn on which would generate a matching closing brace for a opening brace?
我可以打开 Visual Studio 2008 中的设置,该设置将为左大括号生成匹配的右大括号吗?
EDIT: I would imagine that an IDE as powerful as Visual Studio would have this very useful feature.
编辑:我想像 Visual Studio 一样强大的 IDE 会有这个非常有用的功能。
EDIT: Is there a macro that can be written? From the responses I have received it looks like ReSharperis 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.
编辑:是否有可以编写的宏?从我收到的回复来看,ReSharper是唯一的选择。我不想让我的公司投资 ReSharper 工具,我在一家相当大的企业工作,从采购中获得任何批准都不是一件容易的事。
EDIT: I am using VS 2010 Ultimate. The Power Tools and Power commands now do everything I was looking for in this post.
编辑:我使用的是 VS 2010 Ultimate。Power Tools 和 Power 命令现在可以完成我在这篇文章中寻找的一切。
采纳答案by Simon Hughes
回答by Simon P Stevens
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
我知道最初的问题是关于 VS2008,但我把它放在这里作为其他人的信息,并使其对最新版本有用
VS 2010 and VS 2012
VS 2010 和 VS 2012
The Productivity Power Tools(available for VS2010and VS2012) extension now supports automatic brace completion.
在生产力电动工具(可用于VS2010和VS2012)扩展现在支持自动支具完成。
If you already have it installed for VS2010, you must update to at least version 10.0.10710.22. Click
如果您已经为 VS2010 安装了它,则必须至少更新到 10.0.10710.22 版本。点击
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
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:
即使 Visual Studio 2013 也有匹配的插件,VS 现在在不使用任何插件的情况下对自动大括号完成提供本机支持。只需前往:
Tools -> Options -> Text Editor -> C#
Tick checkbox against Automatic brace completion
勾选自动大括号完成复选框
回答by Sylvain Rodrigue
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).
如果要编写 for 循环,只需键入“for”,然后键入 TAB。VS 将完成它(包括大括号)。
Same thing for if, struct, class, switch... You don't even have to type the first brace !!
if、struct、class、switch 也是如此……您甚至不必键入第一个大括号!
Good paper about it here : https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/programming-and-development/?p=655
关于它的好论文:https: //web.archive.org/web/1/http: //blogs.techrepublic%2ecom%2ecom/programming-and-development/?p=655
回答by Allen Pestaluky
EDIT: Thanks hyde, Steven's answerappears to be right: The Microsoft Productivity Power Tools do have a 2012 versionnow.
编辑:谢谢海德,史蒂文的答案似乎是正确的:Microsoft Productivity Power Tools 现在确实有2012 版本。
Original outdated answer:
原始过时的答案:
It appears that the Microsoft Productivity Power Tools don't work in VS 2012 yet. If you're looking for a solution that works on the new version, you can check out this extension:
Microsoft Productivity Power Tools 似乎还不能在 VS 2012 中工作。如果您正在寻找适用于新版本的解决方案,您可以查看此扩展:
http://visualstudiogallery.msdn.microsoft.com/0e33cb22-d4ac-4f5a-902f-aff5177cc94d
http://visualstudiogallery.msdn.microsoft.com/0e33cb22-d4ac-4f5a-902f-aff5177cc94d
回答by Jeffrey Jenkins
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.
在 VS 2013 中有“自动分隔符突出显示”选项(在工具、选项、文本编辑器下),在选中该框时应突出显示匹配的大括号,但在默认设置下不会。这是因为默认背景是白色,默认高亮颜色也是白色。这可以通过转到环境、字体和颜色以及更改“括号匹配(矩形)”的背景颜色来更改。然后匹配的大括号将突出显示并可见。
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.
在我回答之后我意识到问题是创建支架无法找到现有的支架。由于这是我在结束时试图回答的问题,因此我将留下答案以防万一。
回答by Protector one
Late to the party here, but I guess you got use an independently running AutoHotKey script to insert closing brackets/quotes for you.
聚会迟到了,但我猜您使用了一个独立运行的 AutoHotKey 脚本来为您插入右括号/引号。
回答by Joel Spadin
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.
如果你不想为 ReSharper 或类似的包付费,我做了一个免费的扩展来自动关闭大括号。您可以在位于http://visualstudiogallery.msdn.microsoft.com/en-us/0e33cb22-d4ac-4f5a-902f-aff5177cc94d的 Visual Studio 库中找到它。不过它只能在 Visual Studio 2010 中工作。
回答by Alex
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.
取决于你在寻找什么 VS 确实有一些标准的自动完成 if[tab][tab] 和 for[tab][tab] try[tab][tab](和许多其他结构)会让你得到比匹配更多的东西以一种非常漂亮的方式戴上牙套。

