Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio adding space after if-statements

Tags:

Sometimes (but not always!?) when I paste or end a line with a semi-colon, Visual Studio will add a space after the if statement! For example, when pasting, this

if()

will turn into this:

if (condition)

and, when completing a line, this

if(condition)
    DoSomething()

will turn into this:

if (condition)
    DoSomething();

Having to constantly delete this space (sometimes twice!) is driving me absolutely Bonkers! It seems to happen with if and while but not for.

I cannot find anything relating to this in the VS options. I do have Resharper installed, but it is set to not add the space automatically: (image of my resharper settings)

Why is Visual Studio punishing me?

like image 629
BlueRaja - Danny Pflughoeft Avatar asked Nov 17 '10 19:11

BlueRaja - Danny Pflughoeft


2 Answers

In the Visual Studio options, under Text Editor / C# / Formatting / Spacing, in the "Set other spacing options" part, there's an option for "Insert space after keywords in control flow statements".

I suspect you'll find you've got that checked, and you don't want it to be. (I have it checked deliberately :)

like image 71
Jon Skeet Avatar answered Sep 27 '22 00:09

Jon Skeet


Disable auto-formatting as you see fit.

Tools->Options->Text Editor->C#->Formatting->General.

All are checked by default in my C# Express 2010 config:

  • Automatically format completed statement on ;
  • Automatically format completed block on }
  • Automatically format on paste
like image 39
Steve Townsend Avatar answered Sep 25 '22 00:09

Steve Townsend