Remove Shape Matching in Visual Studio

In Visual Studio, I can go from / to the opening / closing bracket using the Control+] shortcut.

Is there a shortcut that will allow me to remove both curly braces at once (possibly using a macro / extension)?

eg.

 foo = ( 1 + bar() + 2 ); 

When I am in the first opening bracket, I would like to remove her and her suitable shape in order to get

 foo = 1 + bar() + 2; 
+6
source share
3 answers

It's not as simple as JaredPar suggested, but I'm not a macro level expert either.

This works for (), {} and []

 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 

Then add a shortcut to this macro in VS.

+2
source

There is no built-in way in Visual Studio to do this. For this you need to implement a macro.

If you choose a macro route, you need to get acquainted with the Edit.GoToBrace command. This is a command that will move you from the current to the corresponding bracket. Note that this will actually reset you after the corresponding bracket, so you may need to look back one character to find the item to delete.

The best way to implement this as a macro is

  • Save current carriage position
  • Run Edit.GoToBrace
  • Remove the bracket to the left of the carriage
  • Remove the bracket in the starting position of the carriage
+3
source

Make a macro to press Ctrl +] twice, and then back, then Ctrl + minus and delete. Ctrl + minus moves the cursor back in time.

+2
source

Source: https://habr.com/ru/post/911796/


All Articles