转到 Visual Studio 中的匹配大括号吗?

发布于 2024-08-06 12:07:35 字数 189 浏览 17 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(28

冬天旳寂寞 2024-08-13 12:07:35

我为您找到了这个: 在大括号之间跳转Visual Studio

将光标放在大括号之前或之后(您的选择),然后按 CTRL + ]。它与括号 ( )、方括号 [ ] 和大括号 { } 一起使用。从现在开始,您不需要玩《沃尔多在哪里?》找到那个支架。

使用上述快捷键,您还可以按住SHIFT进行选择。

在 MacOS 上,使用 CMD + SHIFT + \

I found this for you: Jump between braces in Visual Studio:

Put your cursor before or after the brace (your choice) and then press CTRL + ]. It works with parentheses ( ), brackets [ ] and braces { }. From now on you don’t need to play Where’s Waldo? to find that brace.

With the above shortcut, you can also hold SHIFT to select.

On MacOS, use CMD + SHIFT + \ .

装迷糊 2024-08-13 12:07:35

我使用 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.

半山落雨半山空 2024-08-13 12:07:35

使用 CTRL + ] 在它们之间切换。使用时将光标置于其中一个大括号处。

Use CTRL + ] to switch between them. Place the cursor at one of the braces when using it.

孤独难免 2024-08-13 12:07:35

注意:它也适用于 #if / #elif / #endif 匹配。插入符号必须位于 # 上。

Note: It also works for #if / #elif / #endif matching. The caret must be on the #.

锦上情书 2024-08-13 12:07:35

如果由于某种原因这对您不起作用,则可能是某些东西弄乱了您的键盘绑定(它对我不起作用)。不过,您可以很容易地重新启用绑定 - 至少我是这么想的:

我尝试了这个过程:

  • 转到菜单工具 -> 选项 -> 环境 -> 键盘
  • 滚动到或搜索命令 Edit.GotoBrace
  • 分配所需的快捷方式(我的是空的,所以我输入 CTRL    + ]
  • 一定要点击“分配按钮”

我试过了,还是不行。我重新启动了 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:

  • Go to menu Tools -> Options -> Environment -> Keyboard
  • Scroll to, or search for the command Edit.GotoBrace
  • Assign the desired shortcut (mine was empty, so I put in CTRL    + ])
  • Be sure to click the "Assign Button"

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!

旧瑾黎汐 2024-08-13 12:07:35

在我的法语键盘上,它是 CTRL + ^

On my French keyboard, it's CTRL + ^.

不气馁 2024-08-13 12:07:35

在德语键盘上,它是 Ctrl + ´

On a German keyboard it's Ctrl + ´.

黯淡〆 2024-08-13 12:07:35

在西班牙语键盘上,它是 CTRL + ¿(或 CTRL + ¡)。

On a Spanish keyboard it is CTRL + ¿ (or CTRL + ¡).

夏日落 2024-08-13 12:07:35

在我的丹麦语键盘上,它是 CTRL + Å

On my Danish keyboard it's CTRL + Å.

江挽川 2024-08-13 12:07:35

在土耳其语键盘上,它是 Ctrl + ü

On a Turkish keyboard, it is Ctrl + ü.

烧了回忆取暖 2024-08-13 12:07:35

Ctrl + Shift + ] 将选择所有文本。

And Ctrl + Shift + ] will select all of the text.

对你而言 2024-08-13 12:07:35

为了完整起见,在瑞典语键盘上它是 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.

你的往事 2024-08-13 12:07:35

在我的意大利语键盘上,它是 CTRL + ^

On my Italian keyboard, it's CTRL + ^.

孤千羽 2024-08-13 12:07:35

在我的葡萄牙语键盘和 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.

寄风 2024-08-13 12:07:35

在我的 pt-BR(巴西葡萄牙语)键盘上,它实际上是 CTRL + [

On my pt-BR (Brazilian Portuguese) keyboard it is actually CTRL + [.

浮生未歇 2024-08-13 12:07:35

在我的斯洛文尼亚语键盘上,它是 ALT    + Đ

On my Slovenian keyboard it is ALT    + Đ

狂之美人 2024-08-13 12:07:35

在 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.

音栖息无 2024-08-13 12:07:35

对于 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:

File/Preferences/Keyboard Shortcut

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.

放飞的风筝 2024-08-13 12:07:35

在我的荷兰语(比利时)键盘上,它是 CTRL + ^

On my Dutch (Belgian) keyboard, it's CTRL + ^.

兮颜 2024-08-13 12:07:35

转到工具>选项>环境>字体和颜色,选择“大括号匹配(矩形)”并将“项目背景”更改为例如黄色。这适用于 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 [].

小女人ら 2024-08-13 12:07:35

让每个人受益的细节 (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 called editor.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.

客…行舟 2024-08-13 12:07:35

在匈牙利语键盘上,它是 Ctrl + ú

On a Hungarian keyboard it is Ctrl + ú.

天涯离梦残月幽梦 2024-08-13 12:07:35

有点相关,但对于 HTML 标签:(因为没有内置解决方案, Ctrl + J 不适用于 HTML 标签:)

以下是答案我构建的宏可以执行此操作(切换),包括转到焦点:

这是演示:

在此处输入图像描述

这是代码。享受!

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Windows.Forms

Public Module Module2
    Sub beginToEnd()

        'Place the cursor somewhere in the beginning tag, run the macro, to select from beginning to end tag

        DTE.ActiveDocument.Selection.SelectLine()
        Dim objSel As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint As TextPoint = objSel.TopPoint
        Dim lTopLine As Long = topPoint.Line
        objSel.GotoLine(lTopLine, False)
        '  DTE.ActiveDocument.Selection.StartOfLine()
        DTE.ActiveDocument.Selection.SelectLine()
        Dim line1 As String = DTE.ActiveDocument.Selection.Text()

        If InStr(line1, "/") Then

            ' MsgBox(line1)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
            objSel.GotoLine(lTopLine, False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        Else
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine(False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        End If

        DTE.ActiveDocument.Selection.SelectLine()
        Dim line2 As String = DTE.ActiveDocument.Selection.Text()
        Dim objSel3 As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint3 As TextPoint = objSel3.TopPoint
        Dim lTopLine3 As Long = topPoint3.Line
        objSel.GotoLine(lTopLine3, False)
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, False)
    End Sub
End Module

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:

Enter image description here

And here is the code. Enjoy!

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Windows.Forms

Public Module Module2
    Sub beginToEnd()

        'Place the cursor somewhere in the beginning tag, run the macro, to select from beginning to end tag

        DTE.ActiveDocument.Selection.SelectLine()
        Dim objSel As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint As TextPoint = objSel.TopPoint
        Dim lTopLine As Long = topPoint.Line
        objSel.GotoLine(lTopLine, False)
        '  DTE.ActiveDocument.Selection.StartOfLine()
        DTE.ActiveDocument.Selection.SelectLine()
        Dim line1 As String = DTE.ActiveDocument.Selection.Text()

        If InStr(line1, "/") Then

            ' MsgBox(line1)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine()
            DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, True)
            objSel.GotoLine(lTopLine, False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        Else
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
            DTE.ActiveDocument.Selection.EndOfLine(False)
            DTE.ExecuteCommand("Edit.ToggleOutliningExpansion")
        End If

        DTE.ActiveDocument.Selection.SelectLine()
        Dim line2 As String = DTE.ActiveDocument.Selection.Text()
        Dim objSel3 As TextSelection = DTE.ActiveDocument.Selection
        Dim topPoint3 As TextPoint = objSel3.TopPoint
        Dim lTopLine3 As Long = topPoint3.Line
        objSel.GotoLine(lTopLine3, False)
        DTE.ActiveDocument.Selection.StartOfLine(vsStartOfLineOptions.vsStartOfLineOptionsFirstText, False)
    End Sub
End Module
路还长,别太狂 2024-08-13 12:07:35

在德语键盘上的 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.

听你说爱我 2024-08-13 12:07:35

在瑞士法语键盘上:使用 CTRL + SHIFT + ^

On the Swiss-French keyboard : use CTRL + SHIFT + ^

緦唸λ蓇 2024-08-13 12:07:35

在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.

与酒说心事 2024-08-13 12:07:35

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

小镇女孩 2024-08-13 12:07:35

Windows、Visual Studio 2017、C++、匈牙利键盘、Ctrl+ú

Options/Environment/Keyboard 中,选中 Editor.GotoBrace

Windows, Visual Studio 2017, C++, Hungarian keyboard, Ctrl+ú

In Options/Environment/Keyboard, check Editor.GotoBrace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文