Yes you can have your javascript style curly brace positioning if you really want to

This question came up on the forums the other day. Basically somebody wanted to change the auto formatting features of Visual Studio so that their curly braces didnt get pushed down on to their own lines every time they wrote the next line.

An example of how visual studio will auto-format your methods out of the box:

public bool IsEnabled()
  return true;

However the user wanted to keep the first curly brace on the same line as the method signature like:

public bool IsEnabled() {
  return true;

It's a matter of personal style. Personally I think it is less readable because it reduces the scanability of the code - you have to schwip your eyes over to the end of the method signature (which can be a variable length) to check where the start of the curly braces are.

Anyway I appreciate everyone has their preferences so this is how you set it up if you are excited about this same-line curly brace option:

  1. Click Tools | Options…
  2. Scroll down to the Text Editor node
  3. Expand the C# node
  4. Expand the Formatting node
  5. Click on the New Lines node
  6. You will see a list of options like in the image below which give you full control over when Visual Studio should put your open brace on a new line


Visual Web Developer 2008 Users

You might be wondering if this option is available to you, or you might have tried to follow the tutorial above and found out you cant find the nodes I described?

Well it is possible to configure this in VWD 2008 - the only difference is that after step 1 you need to tick the little checkbox that says "Show all settings".


Anonymous said...

Ah, this was exactly what I was looking for... curse that crafty "show all settings" button. Thank you, kind sir!

Anonymous said...

It's not a matter of personal choice, we don't put curly braces on a new line due to semi-colon insertion:

Anonymous said...

Thanks - exactly what I was looking for. Was searching to edit templates !!