IntelliJ IDEA 13.1.0 Web Help

IntelliJ IDEA makes it possible to concatenate two unselected or several selected lines into one, removing the extra spaces, and providing the proper syntax. This operation smartly analyzes the lines being joined and treats them accordingly. For example, you can join lines of code, lines of comments, field declaration and initialization.

In this section:

To smartly join several lines
  1. Place the caret on the line, to which the other lines should be added.

    Screenshot

  2. Sequentially press Ctrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JControl Shift JControl Shift JControl Shift J keyboard shortcut, until all fragments are joined in a single line.

    Screenshot

    Screenshot

Tip

You can select the lines and press Ctrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JControl Shift JControl Shift JControl Shift J to obtain the same result.

To smartly join several literals into a single string
  1. Select the lines with string literals that should be joined.

    ctrlShiftJ4

  2. Press Ctrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JControl Shift JControl Shift JControl Shift J keyboard shortcut. All redundant characters (spaces, quotes, and plus signs) are gone.

    ctrlShiftJ5

Examples

Joining a field or variable declaration and assignment:

ctrlShiftJ8

Pressing Ctrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JControl Shift JControl Shift JControl Shift J produces the following result, with the unwanted spaces and variable name in the second line removed:

ctrlShiftJ9

Consider the following pair of statements:

ctrlShiftJ10

Press Ctrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JCtrl+Shift+JControl Shift JControl Shift JControl Shift J to join these lines into a correct single-line statement.

ctrlShiftJ11

See Also

Getting Started:

Web Resources: