IntelliJ IDEA 13.1 Web Help

In this section:

To add a line
  • Press Shift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift EnterShift EnterShift 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:

    shiftEnter1.gif

    Press Shift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift+EnterShift EnterShift EnterShift Enter to start the next line immediately:

    shiftEnter2

  • To add a line before the current one, press Ctrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterCtrl+Alt+EnterAlt Command EnterAlt Command EnterAlt Command Enter.
To duplicate a line or fragment
  1. Place the caret at the line to be duplicated, or select the desired fragment of text.
  2. Press Ctrl+DCtrl+DCtrl+DCtrl+DMeta+DCtrl+DCtrl+DCtrl+D, Ctrl+Shift+Down or Ctrl+Shift+UpCtrl+DCommand DCommand DCommand D.
To remove a line
  • Press Ctrl+YCtrl+YCtrl+YCtrl+YCtrl+YCtrl+YCtrl+Shift+LCtrl+ECtrl+DCommand BackspaceCommand YCommand D to delete the line at caret.
To move a line
  1. Place the caret at the line to be moved.
  2. Do one of the following:
    • On the main menu, choose Code | Move Line Up or Code | Move Line Down.
    • Press Shift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift+Alt+UpShift Alt UpShift Alt UpShift Alt Up or Shift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift+Alt+DownShift Alt DownShift Alt DownShift Alt Down.

    IntelliJ IDEA moves the selected line one line up or down, performing the syntax check. For example:

    moveLine1

    After moving line at caret:

    moveLine2

To move a statement up or down
  1. 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.
  2. Do one of the following:
    • On the main menu, choose Code | Move Statement Up/Move Statement Down.
    • Press Ctrl+Shift+UpCtrl+Shift+UpCtrl+Shift+UpCtrl+Shift+UpCtrl+Shift+UpCtrl+Shift+UpCtrl+Shift+UpShift+Alt+UpAlt+UpShift Command UpShift Command UpAlt Up or Ctrl+Shift+DownCtrl+Shift+DownCtrl+Shift+DownCtrl+Shift+DownCtrl+Shift+DownCtrl+Shift+DownCtrl+Shift+DownShift+Alt+DownAlt+DownShift Command DownShift Command DownAlt Down.

    Note

    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.

    IntelliJ IDEA 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:

    moveStatement1

    After moving the statement:

    moveStatement2

Tip

Make sure that keyboard shortcuts are not in conflict. You can do that in the Keymap page of the IDE Settings.

See Also

Procedures:

Reference:

Web Resources: