.NET Tips and Tricks

Blog archive

Free Visual Studio Tool: Brace Completer

When I work in Visual Basic and add an If statement, Visual Studio writes the End If statement; If I add a Class declaration, Visual Studio adds the End Class statement. Why, then, when I work in C# and I type an open brace, doesn't Visual Studio write the closing brace?

In fact, C# will stubbornly mark my line as an error until I do add the closing brace (often hiding some real error). When you do finally type the closing brace in C#, Visual Studio formats the code -- that's got to be harder than adding the brace. That's why, whenever I type an opening brace, I immediately type the closing brace to reduce my chances of having a mismatched brace. Having Visual Studio add the brace would fit right in with my standard practice.

The Brace Completer extension does what I want: when I type an opening brace and hit the Enter key, Brace Completer adds the closing brace, lets Visual Studio format my code according to my settings, and then puts my cursor on the line following the opening brace.

If you're not happy with the default behavior, you can configure the utility from the Tools/Options/Environment/Brace Completer menu choice. Brace Completer does the right thing for C#, C/C++, CSS, and JavaScript; and if you're feeling brave, it's willing to support any other language known to Visual Studio that you might select in the Options dialog. You can also configure Brace Completer to insert the closing brace as soon as you type the opening brace, if you're one of those people who occasionally want to keep everything on one line (and, when you do finally hit the Enter key, you'll get the default formatting expected).

It doesn't seem like a big deal, but I like it very much. I know that it's only saving me one keystroke, but that's one keystroke every time I use a brace. I don't know what that is over a day, month or year, but I bet it's a ton of keystrokes. And, sure, there may come a time when I'll wish that Brace Completer hadn't added the closing brace -- but it hasn't happened yet.

You can find Brace Completer in the online section of Visual Studio's Tools/Extensions and Addins.

Posted by Peter Vogel on 03/18/2013


comments powered by Disqus

Featured

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

  • Copilot Agentic AI Dev Environment Opens Up to All

    Microsoft removed waitlist restrictions for some of its most advanced GenAI tech, Copilot Workspace, recently made available as a technical preview.

Subscribe on YouTube