views:

77

answers:

3

Is there a simpler way of reordering methods within a class source file in IntelliJ than cutting and pasting the code manually? Nowadays I often need this while refactoring legacy code, e.g. to move related methods close to each other in the source code.

In Eclipse AFAIK there is a view similar to the Structure view of IntelliJ, where I can drag and drop methods around. However, this does not work in IntelliJ and I couldn't find any hints from its help either.

I am using IntelliJ 9.0.2 to be specific.

+1  A: 

Select a block of text (hit Ctrl-W a few times) and then use Ctrl-Shift-Up and Ctrl-Shift-Down to move it around.

JacobM
+3  A: 

You can select a method name and hit: Control-Shift-Up or Control-Shift-Up it up and down.

Beyond this the Rearranger Plugin lets you move methods around quickly, and even define a standard ordering based on your coding convention.

retronym
A: 

With your cursor on the method definition line (you do not have to and press ctrl-shift-up or ctrl-shift-down, to move up or down respectively. You can also to ctrl-shift-numberpad- to quickly collapse everything so you can focus on moving around (plain - works on my laptop as well, not sure why) and ctrl-shift-numberpad+ to get back to see everything (ctrl-shift-equals works on my laptop as well).

Yishai