views:

86

answers:

5

I've searched but does Visual Studio 2008 have a setting for C# where it will autoformat/beautify my code as I write it? There is a setting for VB.NET called "prettify". I've also searched the archives already and found a macro to execute this on save and I know I can drag and drop it onto the toolbar but I want it to work without my doing ANYTHING for both ASPX and CS files.

Is this possible via built-in setting, modification, or available from an add on? Thanks

+4  A: 

Select the code block and press Ctrl+K+F

Darin Dimitrov
hi, how do you paste the Keybord thingy?
VoodooChild
@VoodooChild : `<kbd>CTRL+K+F</kbd>`
Darin Dimitrov
@Darin: thanks. WAIT, how come it didn't do it in the comment?
VoodooChild
nm, I see it was a quoted / coded tagged!
VoodooChild
A: 

You can have VS reformat your code by hitting ctrl-a ctrl-k but I don't think there is a setting to have it do it on the fly.

Moo
+2  A: 

Would a keyboard shortcut work for you?

Ctrl + k + d - format the whole document.

Ctrl + k + f - format selection.

In C#, you can also delete and reinsert the } for a similar effect on the block in question.

Oded
One of the best keyboard shortcuts. Ctrl+K, Ctrl+D, Ctrl+S
AMissico
@AMissico - And what does it do?
Oded
Formats the whole document then save it. :O) You Ctrl+k+d is actually, Ctrl+K then Ctrl+D.
AMissico
A: 

Under Tools | Options, you can navigate to Text Editor | C# | Formatting and select all three checkboxes. This will cause your code to be auto formatted per the formatting options in C# | Formatting on those certain events: namely typing a semi-colon, typing a close stache, or pasting in code.

Note: In order for this to work, the code in the file must be able to compile without errors. Also, if you don't have any formatting options specified, or left at their default values, you may not see any difference.

Daniel Joseph
@Daniel, shows no effect in my studio but comes closest to answering the question.
Curtis White
A: 

You could also look into tools like ReSharper (disclaimer: I work for them)

Hadi Hariri
@Hadi That's fine but you did not specifically provide a yes or no if your product supports specifically what I asked.
Curtis White
Well I kind of thought it was implicit, inviting you to look at the product. We provide Code Cleanup which does a whole slew of things and customizable to your own needs. Best is you look at it and see if it suits your needs exactly.
Hadi Hariri