Reorder code without the copy-paste fuss
Have you ever wanted to reorder code members — say, members in a class or just member statements — without the usual copy-paste routine? With ReSharper, this is easy.
The shortcut to remember here is Ctrl+Shift+Alt + Arrow buttons. While holding the Ctrl+Shift+Alt combination, the arrow keys have a multitude of uses depending on where the caret is in your code and what code block you have selected. Here are some examples:
Pressing the left and right arrow keys while on a member of an addition operation such as
a + b
will move the operand left or right, if possible. For instance, with the caret atb
, pressing Ctrl+Shift+Alt+Left will change the expression tob + a
.Pressing the up and down arrow keys moves the whole statement up and down. Note: if you want to have a statement moved inside a code block that follows it, use right/left keys instead of up/down.
Having the caret at the method declaration, the up/down keys (together with Ctrl+Shift+Alt, of course) move it up and down with respect to other member declarations. This lets you reorder fields, properties, methods and events how you wish.
![Rearranging code: selecting movable elements Rearranging code: selecting movable elements](https://resources.jetbrains.com/help/img/dotnet/2024.3/Coding_Assistance__Moving_Code_Elements__method_parameters__01.png)
Since many of these refactorings rely on the exact code elements being selected, ReSharper offers useful shortcut keys in order to extend and shrink selection. An extension can grow from a single identifier, to a whole statement, to all statements, to the containing method, and so on. Use Control+W to extend selection and Control+Shift+W to shrink it.