Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop VS 2010 from Auto Creating Braces After else keyword

I'm using VS 2010, and I'm getting constantly annoyed when I type "else" and then it auto returns line and adds braces. Something like:

else
{

}

I cannot imagine I'm the only one who often puts one-liners after the else and prefers no braces. How do I stop this from happening?

like image 608
themaestro Avatar asked Jul 12 '11 13:07

themaestro


2 Answers

I also found this behavior very annoying.

My first attempt involved opening the Templates Explorer (ReSharper / Templates Explorer...), selecting C#, then unchecking "else". This did get rid of the braces. Unfortunately, hitting enter after "else" now just added a space! I was having to hit enter twice. Not quite what I was hoping for.

But if you double-click on the else template it opens up an editor where you can specify what happens. I found that simply removing the braces gave me the functionality I desired - hitting enter after an else was now putting me on a new line, tabbed over under the else - without braces.

To recap, to fix this you need to open Resharper's Templates Explorer, select the C# scope, then double-click on the else template and remove the braces. Your template "snippet" should look like this (just two lines):

else
  $END$

This works in Resharper 6.1 and Visual Studio 2008. I have no idea about other versions of the software.

like image 154
bsegraves Avatar answered Nov 15 '22 12:11

bsegraves


Okay, finally figured out what the hell is doing this. I have ReSharper installed on this machine, and apparently the "else" keyword is a ReSharper autocomplete keyword. So even after I turned off the braces completion, ReSharper was still kicking in and adding them. Rage. In order to stop this, you have to turn off the ReSharper autocomplete.

like image 25
themaestro Avatar answered Nov 15 '22 11:11

themaestro