Visual Studio Key Strokes: Swapping lines

21,820

Solution 1

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

Solution 2

As of Visual Studio 2013, you can simply use Alt + /

Solution 3

As an alternative solution, you could write a Visual Studio Extension to do this for you. Extensions are written in your favorite .NET language.

Refer to the MSDN article on creating Visual Studio Extensions for more information.

Solution 4

For Mac, It is: option + /

Share:
21,820

Related videos on Youtube

T.K.
Author by

T.K.

I am a computer science student at Georgia Institute of Technology. I have experience with: python java C# C++ C bash scripting matlab Note: I doubt I'll remember to update this as I learn more. Last Edited: February 3, 2011

Updated on July 15, 2020

Comments

  • T.K.
    T.K. almost 4 years

    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.
    
  • Pac0
    Pac0 about 7 years
    alt + Up / Down still valid in Visual Studio 2017, +1
  • v.oddou
    v.oddou over 2 years
    those commands are not associated in my install of VS2019.

Related