How do I get VS2008 to paste code without reformat

2019-06-21 03:42发布

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条回答
戒情不戒烟
2楼-- · 2019-06-21 04:03

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

查看更多
Root(大扎)
3楼-- · 2019-06-21 04:25

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.

查看更多
登录 后发表回答