Move line Up/Down shortcut in Visual Studio 2012

2020-05-13 20:45发布

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:

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

9条回答
我命由我不由天
2楼-- · 2020-05-13 21:08

If you have Resharper, then you can hit Ctrl + Shift + Alt + to move the current line up. or Ctrl + Shift + Alt + to move one line down.

This works in VS 2012 Premium with Visual Studio keyboard scheme in Resharper 7 (7.0.97.60 to be precise).

Edit: This is mapped to 'ReSharper.ReSharper_MoveUp'/'MoveDown' commands.

查看更多
Explosion°爆炸
3楼-- · 2020-05-13 21:09

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.

查看更多
爷的心禁止访问
4楼-- · 2020-05-13 21:09

In Visual Studio 2017(atleast) I have below

enter image description here

查看更多
登录 后发表回答