views:

30

answers:

2

I did some code alignment in the way I preferred, using vim--then tried to paste it into VS2008. Voila, 2008 decides to reformat it, removing all the whitespace I added to make some declarations beautifully aligned.

Is there a way to have VS2008 either (A) paste without changing whitespace or (B) align the code as shown below?

public int              SomePropertyName   { get; set; }
public Nullable<string> SomeOtherProperty  { get; set; }
public Nullable<int>    YetAnotherProperty { get; set; }

which ends up like this when I paste it into VS2008:

public int SomePropertyName { get; set; }
public Nullable<string> SomeOtherProperty { get; set; }
public Nullable<int> YetAnotherProperty { get; set; }
+2  A: 

It is an option. Tools + Options, Text Editor, C#, Formatting, "Automatically format on paste" check box.

Hans Passant
+2  A: 

Also, if you like the reformat most of the time, you can keep the option that Hans pointed out checked, and simply do a ctrl + z after you paste. It won't undo the paste, but it will undo the reformatting of your code. I prefer this method, since most of the time the reformat is a good thing. But, when I don't like the results, ctrl + z and it's all better.

Samuel Meacham
+1, that's the better solution. I'll leave my answer for, ahem, reference.
Hans Passant