Code formatting

B

Brian Schwartz

Quick question related to Visual Studio's automatic code formatting. Often I
like to write my variable declarations with spacing to line them up, like
this (not sure if this spacing will come out right for everyone, but
hopefully you get what I'm after):

private int _xyz
private string _stringVar
private ContentAlignment _align

Whenever I paste code, or set a closing brace, after declarations like this,
the IDE removes all the spacing between the type and the name. I've looked
through the formatting options a couple of times, but haven't hit on
anything to disable this behavior yet. Anyone know how to take care of this?
 
G

Guest

I don't think think there is an option to take care of this.

You probably don't want to hear this, but 'right-alignment' is frowned upon
by most code formatting guru's (e.g., 'Code Complete' by Steve McConnell).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
 
D

Dom

There is no option for this, and there wasn't one in VB either. Like
David said, it must be frowned on. I can't see why. I like it too.
Makes it easier to "find" a variable.

Dom
 
G

Guest

Personally, I find I have more important "stuff" to worry about. However, if
this kind of "stuff" is what floats your boat, you can study EnvDte and write
a macro or similar add-in code that will custom "reformat" your code to your
liking.
Who knows? There may be like-minded souls who'd be willing to pay money for
it.
Peter
 
P

Paul Hadfield

In the old DOS days I used to do that a lot, but now I like viewing my code
in a non-fixed width font, which means it's never possible to use spaces to
line things up regardless of whether the editor allows it or not - in fact
your example ends up looking worse than a single space.

- Paul.
 
G

Guest

Brain,

You can go to Tools->Options->Text Editor->C#->Formatting->General and
untick all three boxes on the right - you will get what you want.

HTH
 
D

Dom

I think unclicking these options will do a lot more than you want,
some stuff that you don't want. But give it a try.

As far as the non-fixed width font, I think Brian wants to tab to a
certain column, so it will still line up.

I wouldn't say it "floats my boat", but the editor obviously does a
lot to make sure formatting is standardized, and we all like that
don't we?

Dom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top