Geeks With Blogs
Lee Brandt's Blog You're only as smart as your last line of code
Today I have been using a ReSharper keyboard shortcut to rearrange chunks of code. I needed to move a method above another method in a class. With the cursor at the beginning of the line inside the chunk I want to move, I hit: Ctrl+Shift+Alt+UpArrow and it moves the entire method up one section (above the method before it).

So.. given:

public string SomeMethod()
{
    Here.Is.SomeCode.ToBe(Superseded);
}
public string MyMethod()
{
    Here.Is.SomeCode(that).Saves(Something);
}

I put my cursor at the line beginning where of the line in MyMethod. THat's the LINE beginning all the way up against the edge of the text editor window (the HOME key should get you there). Then hit Ctrl+Shift+Alt+UpArrow and it moves MyMethod up above SomeMethod.

R# finds code chunks separated by curly braces in C#, and moves them together. So code like this:

public string AnotherMethod()
{
    ForEach(var thing in things)
    {
        GottaDo.Dome(thing);
        ThenSomething<Else>(here);
    }
    var things = new List<Thing>();
}

I can move the Foreach loop below the declaration by putting my cursor at the LINE beginning of either line in the ForEach loop and hit: Ctrl+Shift+Alt+DownArrow and it will move the ForEach loop down as a unit.

This little shortcut has been extremely helpful for rearranging code today. Hope it helps someone else too.

~Lee Posted on Monday, April 13, 2009 1:25 PM Software , Resharper | Back to top


Comments on this post: Resharper Tip of the Day: Moving Chunks of Code

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Lee Brandt | Powered by: GeeksWithBlogs.net