How can I move down/up method in Pycharm?

Viewed 103

I want to move some methods up (I prefer build up flow not split down flow).

I have such class for example after extraction method from method_using_y.

class X:
  def method_using_y():
    pass

  def y():
    pass

And after refactoring I need this:

class X:
  def y():
    pass

  def method_using_y():
    pass

I want to change it to such order (with some automatic tool - I can do it with copy/paste and for such simple methods it works but it not works for large methods and more methods).

What I found I can navigate method up/down and mark method than cut, navigate up and paste. It is not simple and time consuming. I need it because refactoring code to method not works (it always put source function below function which will use it).

Can you help if any shortcuts or action in PyCharm to do it?

1 Answers

Ctrl + shift + (up/down) while the cursor is at the function definition line. The action is called move statement up / down. It might have a different shortcut on your OS.

In fact, you can move any block using this method, like a for loop or class.

Related