[英]Delete Matching Braces in Visual Studio
在Visual Studio中,我可以使用Control+]
快捷方式從/向跳轉/關閉大括號跳轉。
是否有一個快捷方式允許我一次刪除兩個大括號(可能有一個宏/擴展名)?
例如
foo = ( 1 + bar() + 2 );
當我在第一個開口支架上時,我想刪除它和它的匹配支架
foo = 1 + bar() + 2;
使用Visual Studio沒有固有的方法。 您需要為此實現宏。
如果選擇宏路徑,則需要熟悉Edit.GoToBrace
命令。 這是將您從當前跳轉到匹配括號的命令。 請注意,它實際上會在匹配的括號后轉儲您,因此您可能需要向后查找一個字符以找到要刪除的元素。
將此作為宏實現的最佳方法是
Edit.GoToBrace
使宏按Ctrl +]兩次然后退格,然后按Ctrl +減號和刪除。 Ctrl +減號將光標移回時間。
它並不像JaredPar建議的那么簡單,但我也不是宏專家。
這適用於(),{}和[]
Sub DeleteMatchingBrace()
Dim sel As TextSelection = DTE.ActiveDocument.Selection
Dim ap As VirtualPoint = sel.ActivePoint
If (sel.Text() <> "") Then Exit Sub
' reposition
DTE.ExecuteCommand("Edit.GoToBrace") : DTE.ExecuteCommand("Edit.GoToBrace")
If (ap.DisplayColumn <= ap.LineLength) Then sel.CharRight(True)
Dim c As String = sel.Text
Dim isRight As Boolean = False
If (c <> "(" And c <> "[" And c <> "{") Then
sel.CharLeft(True, 1 + IIf(c = "", 0, 1))
c = sel.Text
sel.CharRight()
If (c <> ")" And c <> "]" And c <> "}") Then Exit Sub
isRight = True
End If
Dim line = ap.Line
Dim pos = ap.DisplayColumn
DTE.ExecuteCommand("Edit.GoToBrace")
If (isRight) Then sel.CharRight(True) Else sel.CharLeft(True)
sel.Text = ""
If (isRight And line = ap.Line) Then pos = pos - 1
sel.MoveToDisplayColumn(line, pos)
sel.CharLeft(True)
sel.Text = ""
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.