Visual Studio 2010 Extension: Move Line

In most of the Office applications there is a shortcut to move a line up or down in a paragraph.

You can make:

  • Line One
  • Line Two
  • Line Three

into the following:

  • Line Two
  • Line One
  • Line Three

With a simple keyboard shortcut you can reorder lists pretty easily.  Try it.  Paste the lines above into Word.  Put your cursor on one of the lines and use Alt-Shift Up/down arrow to move it around.  If you work a lot in PowerPoint, Word or OneNote you’ll find this little reorder feature really handy.

The Move Line Command extension, by Sergei Taguer, gives the same functionality to Visual Studio 2010!  This is extremely handy.  There have been MANY times I’ve used the office keyboard shortcut in Visual Studio by reflex and was surprised when nothing happened.  Each time I did that I also would remember that I had created an entry on my @Project list to create a DXCore extension to implement this.  Now I can strike that from my list!

UPDATE: It can also move full blocks of code up and down.  Select a whole method and then use this to move it around.

I ended up remapping the Edit.MoveLineUp and Edit.MoveLineDown to the same keys that Office uses, but that meant unmapping a few of the block selection shortcuts.  I can still do the block selection but it requires holding Ctrl-Alt-Shift down, then select with the arrows, though once you get the block selection going you can just hold the shirt key down until you’re done selecting.  This isn’t bad for me since this was actually the original block selection shortcut in previous versions of Visual Studio and the one my fingers already knew.  If you don’t want to change any of the mappings the Move Line extension is mapped to Alt-Down Arrow and Alt-Up Arrow when it is first installed.