How to preserve format while pasting in Visual Studio 2015?

Since the question is related to reordering in general this may be helpful as well.

To easy reorder code: select code to move then use Alt+UpArrow or Alt+DownArrow to move the selection up or down. For indenting the selection use Tab or Shift+Tab to move indentation back.


You're experiencing a "feature" of Visual Studio that auto-formats code on certain actions (completed statement on ;, completed block on }, or on Paste. Fortunately, these preferences can be changed via the following settings page (they are language-specific):

VS 2015

Tools > Options > Text Editor > C# > Formatting

Then temporarily uncheck the Automatically format on paste option.

General C# formatting options

VS 2017/2019

In Visual Studio 2017 and 2019, the "Formatting" options moved underneath a new "Code Style" menu and added some extra settings:

enter image description here


This might sound silly, but the way the paste and reformat feature works in Visual Studio is that Visual Studio first pastes, and then formats the text in various steps.

If you don't want to disable the "Automatically format on paste" feature, try this:

  1. Paste the text as normal (VS will format the text, but hang on)
  2. Undo (Ctrl + Z) multiple times until all formatting steps have been reverted