13

Intellij has a shortcut for moving the current method internally in the class ( I think it is Ctrl+Shift+{Up or Down Arrow})

I would like to know if Eclipse has the same functionality.

I could mark the whole method and then alt-arrow to move it, but then it would move one line at a time. I would like it to move one member for every keystroke.

I would also not like to use the mouse (in the outline view where one may re-order members of a class)

2 Answers 2

7

if you double-click just after the opening { of a function, you will select the all function body.

You can then:

  • Alt+Up: to move the function up one line
  • Alt+Down: to move the function down one line

Of course, that is the shortcut you describe in your question, and moving a function by just one line can result in an incorrect code (as the function can end up within another one).
You have to repeat the shortcut the appropriate number of time to actually move the function before or after another one.

So the answer is: No, not exactly like IDEA, but close enough.

Actually, if the outline view is not sorted alphabetically, you can drag and drop a function in order to reorder them.
But that is not a shortcut.

4
  • But that is exactly what Nils Otto asked for. Dec 31, 2013 at 8:01
  • @PaulVerest I agree. I simply stated what I found, more than 4 years ago. Do you know if the latest Eclipse versions have evolved on that feature?
    – VonC
    Dec 31, 2013 at 8:13
  • As of Eclipse 4.4 M2 old shortcut works. For Java Editor Drag-n-drop of methods can be used to move or copy methods between classes (or copy inside) Dec 31, 2013 at 8:19
  • @PaulVerest "old" shortcut? The one I mention in my answer? For moving the function in the class? And the drag-and-drop is what I mention in my answer too. I don't see anything relevant in download.eclipse.org/eclipse/downloads/drops4/….
    – VonC
    Dec 31, 2013 at 8:34
6

If you can afford to use the mouse, you can do it from the outline view. That will be easiest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.