How do I make Visual Studio auto generate braces for a function block?

后端 未结 5 1734
挽巷
挽巷 2021-01-11 15:19

I could swear I\'ve seen people typing function headers and then hitting some key combination to auto-create function braces and insert the cursor between them like so:

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-11 15:42

    The tools look nice (especially Resharper but at $200-350 ouch!) but I ended up just recording a macro and assigning it to ctrl+alt+[

    Macro came out like this:

    Sub FunctionBraces()
        DTE.ActiveDocument.Selection.NewLine
        DTE.ActiveDocument.Selection.Text = "{}"
        DTE.ActiveDocument.Selection.CharLeft
        DTE.ActiveDocument.Selection.NewLine(2)
        DTE.ActiveDocument.Selection.LineUp
        DTE.ActiveDocument.Selection.Indent
    End Sub
    

    Edit: I used the macro recorder to make this and it wasn't too bad

提交回复
热议问题