In this section:
- Press Shift+Enter to add a new line after the one where the
caret is currently located and move the caret to the beginning of this new line.
For instance, you have typed some text:
Press Shift+Enter to start the next line immediately:
- To add a line before the current one, press Ctrl+Alt+Enter.
- Place the caret at the line to be duplicated, or select the desired fragment of text.
- Press Ctrl+D.
- Place the caret at the line to be moved.
- Do one of the following:
- On the main menu, choose or .
- Press Shift+Alt+Up or Shift+Alt+Down.
PyCharm moves the selected line one line up or down, performing the syntax check. For example:
After moving line at caret:
- Select a statement to be moved, or just place the caret at the first or last lines of a multi-line statement. Note that if moving a statement is not allowed in the current context, the commands will be disabled.
- Do one of the following:
- On the main menu, choose .
- Press Ctrl+Shift+Up or Ctrl+Shift+Down.
If you apply the same commands to a line at caret, or a to a selection, it will be moved one line up or down.
PyCharm moves the selected statement above the previous one, or directly underneath the next one, performing the syntax check. For example, place the caret at the method declaration:
After moving the statement:
Make sure that keyboard shortcuts are not in conflict. You can do that in the Keymap page of the IDE Settings.