Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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:

void foo()_

to

void foo()
{
    _
}

Is this a built-in feature?

like image 512
Luke Avatar asked Aug 13 '08 05:08

Luke


4 Answers

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

like image 122
Luke Avatar answered Nov 15 '22 13:11

Luke


Check out Resharper - it is a Visual Studio add-on with this feature, among many other development helps.

Also see C# Completer, another add-on.

If you want to roll your own, check out this article. Insane that one should have to do that, though.

like image 42
pc1oad1etter Avatar answered Nov 15 '22 13:11

pc1oad1etter


It can be achieved by using code snippets, some are already built in (try typing "svm" and hitting TAB-TAB)..

There's a wealth of info on the net on creating these:

Jeff did a post himself here

Have a google! I use them LOTS! :D

like image 41
Rob Cooper Avatar answered Nov 15 '22 12:11

Rob Cooper


Take a look at visual assist as well.

like image 40
David McGraw Avatar answered Nov 15 '22 12:11

David McGraw