Visual Studio Key Strokes: Swapping lines

T.K. picture T.K. · Apr 12, 2011 · Viewed 18.1k times · Source

Is there a keystroke in visual studio similar to Eclipse's Alt + /?

For example:

int x = 0; // Cursor is anywhere on this line.
int y = 1;

and Alt + Down were pressed, then:

int y = 1;
int x = 0; // Cursor is anywhere on this line.

Answer

Diego Torres picture Diego Torres · Apr 12, 2011

VS 2013 and later:

Alt + (Edit.MoveSelectedLinesUp)

Alt + (Edit.MoveSelectedLinesDown)


VS 2012:

Shift+Alt+ T (Edit.LineTranspose)

but this only swaps between the current and the next line (move down only).

VS 2012 does not support macros but there is the Productivity Power Tools 2012 extension that adds (besides some other nice features) commands to move a line up or down with Alt + and Alt + .


VS 2010 and earlier:

Line transpose works (Shift+Alt+ T) but still no move up.

You could write a macro for those commands, I think this question may help you: Visual Studio: hotkeys to move line up/down and move through recent changes