Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move line Up/Down shortcut in Visual Studio 2012

In VS2010 I had a shortcut set up Alt+Up/Down to move lines of code up or down, just like I used to have in Eclipse in my Java days.

Now since Power Tools and macros (which is how I set up this shortcut in VS2010) are not available in VS2012, how do I get this to work?

I've seen somebody mentioned that Resharper can do this, but for the love of fire and water, I can't find the command names in the list of commands that can do that. I have tried ReSharper_MoveUp/MoveDown and that does not move lines up/down:

Move_Up command did not do the trick

This moves blocks of text up and down. I just want line-by-line up or down, no fancy logic there. Before

What I have

After ALT+Up (when cursor is on WriteLine line) I would like to see this:

Line moved one up, inside the bracket, indented

I have seen these threads: What's the equivalent for eclipse's ALT+UP/DOWN (move line) in Visual Studio?, Visual Studio: hotkeys to move line up/down and move through recent changes, but none of the suggested solutions work in VS2012.

Any other ideas?

UPD 7 Nov 2012: . Extensions are catching up with Visual Studio 2012. Now I know at least 3 extensions that provide this functionality:

  • MoveLine Extension. Link provided by Carl G
  • Move Line Extension with modifications to 2010 version. By gius
  • Productivity Power Tools 2012. Have not actually tried this, but this blog post states it does the line move up/down

UPD 15 Nov 2012: Just stumbled across another extension that claims it does what is required here. Have not tried it though: LineMan Extension

UPD 10 May 2015 Just installed VS2015 RC and this is built-in already: MoveLineUp/Down

like image 474
trailmax Avatar asked Aug 09 '12 11:08

trailmax


People also ask

How do you move a line up and down in Visual Studio?

If you put the cursor on a line of code and use the Alt+Up Arrow keys, the line of code you've selected moves up. If you use the Alt+Down Arrow keys, the line of code selected moves down.

How do you move a line up and down?

ALT + UP/DOWN will move a line up or down.


2 Answers

For those who arrived on this question using Visual Studio 2013 or above, the feature is built right into the program. Just use AltUp and AltDown to move the line with your cursor—or the selected lines—up and down.

If you wish to rebind it in Tools > Options > Environment > Keyboard, the keys are Edit.MoveSelectedLinesUp and Edit.MoveSelectedLinesDown. You may need to remove your new combination from other existing keys first.

like image 128
Keavon Avatar answered Oct 13 '22 03:10

Keavon


Update: huzzah, Productivity PowerTools VS2012 is now available and offers this functionality (along with another personal favorite, Tools.AddEndTokenAtTheEnd.)

MoveLine Extension (compatible with VS 2012; I had to manually restart my VS in order to see the commands in VS's keyboard shortcut tool.)

like image 24
Carl G Avatar answered Oct 13 '22 03:10

Carl G