Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get VS2008 to paste code without reformatting it (changing whitespace)?

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; }
like image 403
Kimball Robinson Avatar asked Jul 20 '10 17:07

Kimball Robinson


2 Answers

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.

like image 102
Samuel Meacham Avatar answered Oct 17 '22 13:10

Samuel Meacham


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

like image 36
Hans Passant Avatar answered Oct 17 '22 14:10

Hans Passant