Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Key Strokes: Swapping lines

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. 
like image 386
T.K. Avatar asked Apr 12 '11 19:04

T.K.


People also ask

What is Ctrl K in Visual Studio?

Edit.SelectionCancel. Surround with. Ctrl+K, Ctrl+S. (available only in Visual Studio 2019 and earlier)

How do I reset key bindings in Visual Studio?

Click File > Preferences > Keyboard Shortcuts. There is a triple-dot (...) at the top-right hand corner. Click on that and select "Show User Keybindings" Delete your listed keybindings.

What does Ctrl d do in Visual Studio?

Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.


2 Answers

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

like image 108
Diego Avatar answered Sep 20 '22 17:09

Diego


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

like image 31
Jack Tang Avatar answered Sep 19 '22 17:09

Jack Tang