visual-studio HTML 键盘快捷键中的匹配标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2738573/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:52:52  来源:igfitidea点击:

Matching tag in HTML keyboard shortcut

visual-studiovisual-studio-2008

提问by nikib3ro

Is there a shortcut in Visual Studio (2008) that will allow me to jump to matching HTML tag... as CTRL+] does for matching braces when you are in code view?

Visual Studio (2008) 中是否有一个快捷方式可以让我跳转到匹配的 HTML 标签......就像 CTRL+] 在代码视图中匹配大括号时所做的那样?

Example:

例子:

<table>
  <tr>
    <td>
    </td>
  </tr>
</table|>

Cursor is on closing table tag and I would like to press something like CTRL+] to jump to opening table tag.

光标在关闭表格标签上,我想按 CTRL+] 之类的东西跳转到打开表格标签。

Any ideas?

有任何想法吗?

采纳答案by Royi Namir

Ok here is the answer as 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 cursor somewhere in beginning tag, run 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

回答by Kaushik Halvadia

I search and couldn't found direct short cut. But you can use..

我搜索并找不到直接的捷径。但是你可以用..

If you want to go starting matching HTML tag, then follow below steps.

如果您想开始匹配 HTML 标签,请按照以下步骤操作。

  1. Place cursor at ending matching HTML tag.
  2. Press Ctrl+M+M[To Collapse entire tag]
  3. Press HomeKey [To place cursor at before starting tag]
  4. Press Ctrl+M+M[To Expand entire tag]
  1. 将光标放在匹配的 HTML 标签的结尾处。
  2. Ctrl+ M+ M[折叠整个标签]
  3. Home[将光标置于开始标记前] 键
  4. Ctrl+ M+ M[展开整个标签]

If you want to go ending matching HTML tag, then follow below steps.

如果您想结束匹配的 HTML 标签,请按照以下步骤操作。

  1. Place cursor at starting matching HTML tag.
  2. Press Ctrl+M+M[To Collapse entire tag]
  3. Press EndKey [To place cursor next to ending tag]
  4. Press Ctrl+M+M[To Expand entire tag]
  1. 将光标置于开始匹配的 HTML 标记处。
  2. Ctrl+ M+ M[折叠整个标签]
  3. End[将光标置于结束标记旁边]
  4. Ctrl+ M+ M[展开整个标签]

回答by Steve Cooper

In Visual Studio 2015, this is now supported with the usual bracket matching keystrokes;

在 Visual Studio 2015 中,现在支持使用通常的括号匹配击键;

  • ctrl+]jumps from the start tag to the end tag.
  • ctrl+shift+]selects everything between the start tag and the end tag.
  • ctrl+]从开始标签跳转到结束标签。
  • ctrl+shift+]选择开始标记和结束标记之间的所有内容。

It seems pretty sensitive, though, and to select an entire tag and its contents you need to start right on the <that opens the tag.

不过,这似乎非常敏感,要选择整个标签及其内容,您需要从<打开标签的那一刻开始。

回答by nikib3ro

After http://www.jetbrains.com/resharper/is installed CTRL+] for matching braces works in HTML edit mode...

http://www.jetbrains.com/resharper/安装后 CTRL+] 匹配大括号在 HTML 编辑模式下工作...

回答by Steve Cooper

In Visual Studio 2012, in 'source' view, right at the bottom of the document window, there is a breadcrumb-trail-style description of the DOM. You can click at any point to select.

在 Visual Studio 2012 中,在“源”视图中,就在文档窗口的底部,有一个面包屑路径样式的 DOM 描述。您可以在任意点单击以进行选择。

It's not a keyboard shortcut, but it does give you the selection behaviour you're looking for, and you don't need to match tags by eye any more.

它不是键盘快捷键,但它确实为您提供了您正在寻找的选择行为,并且您不再需要通过眼睛来匹配标签。

(Edit) If you hover over the breadcrumb, you will see a dropdown arrow. Click the down arrow and click "Select Tag Content". Then you can just scroll up or down until you find text that is not highlighted.

(编辑)如果您将鼠标悬停在面包屑上,您将看到一个下拉箭头。单击向下箭头,然后单击“选择标记内容”。然后您可以向上或向下滚动,直到找到未突出显示的文本。

回答by Jorge Vargas

This totally works when you open a HTML file with the XML Editor (Right click -> Open With... -> XML Editor).

当您使用 XML 编辑器(右键单击 -> 打开方式... -> XML 编辑器)打开 HTML 文件时,这完全有效。

回答by JuliaJ

I am using Visual Studio Code in Windows 10. Currently version 1.34.0. To jump to the matching html tag, I set it up through File -> Preferences -> Keyboard Shortcuts. Look for "Matching Tag: Jump to matching tag" .. There's a + when you hover it, then I set keybinding Shift + ].. you can set your own as long as it isn't used for another function. So now I am able to jump to the closing HTML tag. Hope this helps.

我在 Windows 10 中使用 Visual Studio Code。目前版本 1.34.0。为了跳转到匹配的 html 标签,我通过 File -> Preferences -> Keyboard Shortcuts 设置它。寻找“匹配标签:跳转到匹配标签”.. 悬停它时有一个 +,然后我设置键绑定Shift + ].. 只要它不用于其他功能,您就可以设置自己的。所以现在我可以跳转到结束 HTML 标签。希望这可以帮助。

回答by Ihor

Jump to matching tag functionality is easily achieved with this simple extension: VSCode Highlight Matching Tag

使用这个简单的扩展可以轻松实现跳转到匹配标签的功能:VSCode Highlight Matching Tag

Once installed, you may use Command Palette (Win/Linux: Ctrl+Shift+P; Mac: Cmd+Shift+P) and search command name: Jump to matching tag. Or configure keyboard shortcut for that command. Here is my example of key binding for shift+5in my case:

安装后,您可以使用命令面板 (Win/Linux: Ctrl+Shift+P; Mac: Cmd+Shift+P) 并搜索命令名称:Jump to matching tag。或者为该命令配置键盘快捷键。shift+5在我的情况下,这是我的键绑定示例:

  {
    "key": "shift+5",
    "command": "highlight-matching-tag.jumpToMatchingTag",
    "when": "editorLangId == html"
  }

回答by Seb

No, you can't do that in Visual Studio 2010, not in the current version or in older ones. Maybe the next version will have this feature.

不,您不能在 Visual Studio 2010 中执行此操作,不能在当前版本或旧版本中执行此操作。也许下个版本会有这个功能。