转到 Visual Studio 中的匹配大括号吗?
Visual Studio 2008 中有没有办法从右大括号转到左大括号?我发现了很多关于突出显示大括号的内容,但没有找到关于将光标移动到它的内容。
(此问题的 VB.NET 版本:用于在“If/End If”之间跳转的键盘快捷键)
Is there a way in Visual Studio 2008 to go from a closing brace to its opening brace? I've found a fair amount of stuff about highlighting the brace, but nothing about moving the cursor to it.
(VB.NET version of this Question: Keyboard shortcut for Jumping between "If/End If")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(28)
我为您找到了这个: 在大括号之间跳转Visual Studio:
使用上述快捷键,您还可以按住SHIFT进行选择。
在 MacOS 上,使用 CMD + SHIFT + \ 。
I found this for you: Jump between braces in Visual Studio:
With the above shortcut, you can also hold SHIFT to select.
On MacOS, use CMD + SHIFT + \ .
我使用 Visual Studio 2008,您可以自定义此快捷方式。
单击菜单工具 -> 选项 -> 环境 -> 键盘。然后查找Edit.GotoBrace。
这将告诉您当前为此分配的组合键。我认为您可以根据需要更改此设置,但如果 Ctrl + ] 不起作用,它会很有用。
I use Visual Studio 2008, and you can customize what you want this shortcut to be.
Click menu Tools -> Options -> Environment -> Keyboard. Then look for Edit.GotoBrace.
This will tell you what key combination is currently assigned for this. I think you can change this if you want, but it's useful if the Ctrl + ] doesn't work.
使用 CTRL + ] 在它们之间切换。使用时将光标置于其中一个大括号处。
Use CTRL + ] to switch between them. Place the cursor at one of the braces when using it.
注意:它也适用于 #if / #elif / #endif 匹配。插入符号必须位于 # 上。
Note: It also works for #if / #elif / #endif matching. The caret must be on the #.
如果由于某种原因这对您不起作用,则可能是某些东西弄乱了您的键盘绑定(它对我不起作用)。不过,您可以很容易地重新启用绑定 - 至少我是这么想的:
我尝试了这个过程:
我试过了,还是不行。我重新启动了 Visual Studio,但它仍然无法工作 - 它仅适用于 .cs 文件,但我需要它适用于 .vb 文件和文本文件,并且......所有文件!
If for some reason this is NOT working for you, something may have messed up your keyboard bindings (it didn't work for me). You can re-enable the binding easy enough though - at least so I thought:
I tried this procedure:
I tried it, and it still didn't work. I restarted Visual Studio, and it still didn't work - well it ONLY worked for .cs files, but I need it to work for .vb files and text files, and...well ALL files!
在我的法语键盘上,它是 CTRL + ^。
On my French keyboard, it's CTRL + ^.
在德语键盘上,它是 Ctrl + ´。
On a German keyboard it's Ctrl + ´.
在西班牙语键盘上,它是 CTRL + ¿(或 CTRL + ¡)。
On a Spanish keyboard it is CTRL + ¿ (or CTRL + ¡).
在我的丹麦语键盘上,它是 CTRL + Å。
On my Danish keyboard it's CTRL + Å.
在土耳其语键盘上,它是 Ctrl + ü。
On a Turkish keyboard, it is Ctrl + ü.
Ctrl + Shift + ] 将选择所有文本。
And Ctrl + Shift + ] will select all of the text.
为了完整起见,在瑞典语键盘上它是 CTRL + å 。
另外,我想合乎逻辑,但值得一提 CTRL + shift + å (对于大写 Å),选择大括号内的所有内容并转到匹配的一个。
For completeness sake, on a Swedish keyboard it's CTRL + å .
Also, I guess logical, but worth mentioning CTRL + shift + å (for capital Å), selects everything inside the braces and goes to the matching one.
在我的意大利语键盘上,它是 CTRL + ^。
On my Italian keyboard, it's CTRL + ^.
在我的葡萄牙语键盘和 EN VS 上,使用 CTRL + « 导航到匹配的大括号,使用 CTRL + SHIFT + « 如果您打算选择内部代码。
On my Portuguese keyboard and SO with EN VS, it's CTRL + « to navigate to matching brace and CTRL + SHIFT + « if you intend to select the inner code.
在我的 pt-BR(巴西葡萄牙语)键盘上,它实际上是 CTRL + [。
On my pt-BR (Brazilian Portuguese) keyboard it is actually CTRL + [.
在我的斯洛文尼亚语键盘上,它是 ALT + Đ
On my Slovenian keyboard it is ALT + Đ
在 Mac 上使用 command+shift+\。
来源:对此答案的评论:https://stackoverflow.com/a/37877082/3345085。
在 Visual Studio Code 版本 1.10.2 中测试。
On a Mac use command+shift+\.
Source: a comment on this answer: https://stackoverflow.com/a/37877082/3345085.
Tested in Visual Studio Code version 1.10.2.
对于 Visual Studio Code(如其文档中所示),请使用 Ctrl+Shift+\。
该设置可以在以下位置找到:
我正在使用 Visual Studio Code 1.8.0 。注意 Visual Studio Code 对于国际键盘的行为可能有所不同(如此答案:德语键盘中所示)
希望这对某人有帮助。
For Visual Studio Code (as seen in their documentation), use Ctrl+Shift+\.
The setting can be found in:
I am using Visual Studio Code 1.8.0 . Note Visual Studio Code may behave differently for international keyboards (as seen in this answer re: German keyboard)
Hope this helps someone.
在我的荷兰语(比利时)键盘上,它是 CTRL + ^。
On my Dutch (Belgian) keyboard, it's CTRL + ^.
转到工具>选项>环境>字体和颜色,选择“大括号匹配(矩形)”并将“项目背景”更改为例如黄色。这适用于 C# 括号 () {} 和 []。
Goto Tools > Options > Environment > Fonts and Colors, select the "Brace Matching (Rectangle)" and change the "Item Background" to e.g. Yellow. This worked for the C# parentheses () {} and [].
让每个人受益的细节 (Linux/Win/Mac)
键盘快捷键菜单/编辑器中的命令是
editor.action.jumpToBracket
,您可以将其设置为您喜欢的任何内容。还有一个名为editor.action.selectToBracket
,默认情况下没有快捷方式(至少在 Mac 上)。等等。
在 Mac 上
editor.action.jumpToBracket
开头为 Cmd+Shift+\我将其更改为 Ctrl+] 以与其他人在这里所说的保持一致。我这样做是希望可以使用 Ctrl+Shift+] 来“将选择范围扩展到匹配的括号”。这就是导致我发现上述细节的原因。我将
editor.action.selectToBracket
设置为 Ctrl+Shift+] 并得到了我想要的行为。Details that can benefit everyone (Linux/Win/Mac)
The command in the keyboard shortcuts menu/editor is
editor.action.jumpToBracket
there you can set it to whatever you like. There is also one callededitor.action.selectToBracket
which has no shortcut by default (at least on Mac).Etc.
On the Mac
editor.action.jumpToBracket
starts out as Cmd+Shift+\and I changed it to Ctrl+] to be in line with what others say here. I did so in the hopes that I could use Ctrl+Shift+] to "Extend selection to matching bracket". That is what lead me to discover the details above. I set
editor.action.selectToBracket
to Ctrl+Shift+] and got exactly the behavior I wanted.在匈牙利语键盘上,它是 Ctrl + ú。
On a Hungarian keyboard it is Ctrl + ú.
有点相关,但对于 HTML 标签:(因为没有内置解决方案, Ctrl + J 不适用于 HTML 标签:)
以下是答案我构建的宏可以执行此操作(切换),包括转到焦点:
这是演示:
这是代码。享受!
A bit relevant, but for HTML tags: (since there is no built-in solution, Ctrl + J doesn't work for HTML tags : )
Here is the answer as a macro which I've built which does it (toggle), including go to focus:
Here is the demo:
And here is the code. Enjoy!
在德语键盘上的 Visual Studio Code 中,它是 ctrl+shift+^
但是您必须打开具有正确扩展名的文件 - 它在新版本中不起作用例如未保存的文件。
In Visual Studio Code on german keyboard it's ctrl+shift+^
But you have to open a file with correct extension - it's not working in new unsaved files for example.
在瑞士法语键盘上:使用 CTRL + SHIFT + ^
On the Swiss-French keyboard : use CTRL + SHIFT + ^
在VS2012的西班牙语(西班牙)键盘上是 Ctrl + ¡ 如@Keith所述,但如果您使用 Ctrl + ¿ kbd> (输入为 Ctrl + Shift + ¡),然后转到匹配大括号并选择两个大括号内的所有代码,然后您可以不要再去另一个支架。
On Spanish (Spain) keyboard with VS2012 is Ctrl + ¡ as stated by @Keith but if you use Ctrl + ¿ (typed as Ctrl + Shift + ¡) then goes to Matching Brace plus selects all the code within the two braces and then you can't go again to the other brace.
2021 年 6 月
在运行 Windows 10 的 Mac 上运行 Visual Studio 2019 和 c# 并使用美式键盘,对我有用的解决方案是编辑“”中的快捷方式
工具
选项
键盘
Edit.GoToBrace
在我的系统上,该快捷方式为空...
按 Ctl 键和 ] 键并保存快捷方式
June 2021
On a Mac running Windows 10 under parallels for Visual Studio 2019 and c# and with US keyboard the solution which worked for me was to edit the shortcut in"
Tools
Options
Keyboard
Edit.GoToBrace
On my system that shortcut was blank...
Press the Ctl key and the ] key and save the shortcut
Windows、Visual Studio 2017、C++、匈牙利键盘、Ctrl+ú
在
Options/Environment/Keyboard
中,选中Editor.GotoBrace
。Windows, Visual Studio 2017, C++, Hungarian keyboard, Ctrl+ú
In
Options/Environment/Keyboard
, checkEditor.GotoBrace
.