Visual Studio 2013 Preview: Moving Lines of Code

And I’m finally back! It’s been a few months since I have blogged and I am glad to be doing it again. This year I will be revising and updating most of the tips for VS2013. Not all of them will be updated simply because some features just aren’t used that much anymore and I want to focus on the more used pieces of the product.

 

With that said this is post number one of many, many more to come. I wanted to begin by reviewing some cool new features that were talked about at TechEd and BUILD. Of course I will be adding my own commentary to the mix as well :)

 

The first step in our journey is a very easy, and yet very cool, item that I fell in love with right away: moving lines of code around. We have always had the ability to insert lines and juxtapose lines. In fact, there are several tips I have written about manipulating the lines of code in the IDE. This new feature makes moving lines around a whole lot easier. Let me show you how it works!

 

Single Line Move

In Visual Studio 2013 Preview go to any code that you have and put your cursor on a line of code:

image

 

Now simply hold down your ALT key and use your UP or DOWN arrow keys to move the line to the new position:

image

 

 

Multi-Line Move

This also works when you select multiple lines:

image

 

And use your ALT key plus UP or DOWN to move the lines:

image

 

Naturally if you mess up a move you can always undo any moves by using CTRL+Z.

 

 

Turning It Off

Currently the only way I see to turn this feature off if you don’t like it is to go to Tools | Options | Environment | Keyboard and remove the bindings for the following commands:

 

ProjectandSolutionContextMenus.Item.MoveUp

ProjectandSolutionContextMenus.Item.MoveDown

 

Here is what it will look like in Tools | Options | Environment | Keyboard:

image