Matching tag in HTML keyboard shortcut

2019-01-23 01:13发布

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?

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.

Any ideas?

7条回答
Anthone
2楼-- · 2019-01-23 01:32

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
查看更多
戒情不戒烟
3楼-- · 2019-01-23 01:37

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

查看更多
ら.Afraid
4楼-- · 2019-01-23 01:39

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

  • ctrl+] jumps from the start tag to the end tag.
  • ctrl+shift+] selects everything between the start tag and the end tag.

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.

查看更多
小情绪 Triste *
5楼-- · 2019-01-23 01:44

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.

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.

查看更多
老娘就宠你
6楼-- · 2019-01-23 01:46

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

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-23 01:51

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.

查看更多
登录 后发表回答