共用方式為


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

Comments

  • Anonymous
    July 01, 2013
    The comment has been removed

  • Anonymous
    July 01, 2013
    Greg :) Yes. If you read my post you can see that I refer to the fact this is not a new concept but the key bindings are new and the command is actually a new one as well. The commands you mention are actually part of the Power Tools for VS2010 and some people may not (or be able to) have this installed. The new commands Item.MoveDown and Item.MoveUp make this standard in the IDE regardless of extensions you have installed. Z

  • Anonymous
    July 01, 2013
    "Yes. If you read my post you can see that I refer to the fact this is not a new concept but the key bindings are new." I don't see anything like that in your post, and I've read it through several times.  Is that perhaps something that you intended to write but didn't? "The commands you mention are actually part of the Power Tools for VS2010 and some people may not (or be able to) have this installed. " Ah, right.  I thought I had them through an add-in, but that's usually Visual Assist, and they didn't have the Visual Assist prefix, and I didn't realize that other addins could add things like "Edit.MoveLineDown", so I thought I was just mis-remembering, and they were actually a regular part of the IDE. I also have the assignments from Alt-Down to "ProjectandSolutionContextMenus.Item.MoveUp" in mine, so either this capability was added to these existing functions, or you still need to check the Text Editor shortcuts for the real assignments.

  • Anonymous
    July 01, 2013
    Greg :) DOH! I was thinking about tomorrow's post. I'm a week ahead on posts so they all kind of blur together a bit. Tomorrow I mention the fact that many of the new features are the direct result of Power Tools features coming into the mainstream IDE. I think what the team has done is create a new Item.MoveUp and Item.MoveDown to encompass text functionality so it looks like the commands were there but not used in this way. Z