IntelliJ IDEA way of editing multiple lines

Solution 1:

Since Idea IntelliJ IDEA 13.1 there is a possibility to edit multiple lines.

Windows

Alt + Shift + Mouse click

macOS

Option + Shift + Mouse click

for selection. More about this new improvement in the IntelliJ blog post here. Very useful feature.

Solution 2:

I use Column Selection Mode (Cmd+Shift+8 on Mac) which allows to create multiple cursors via Shift+Up or Shift+Down then edit all the lines together.

Starting from IntelliJ IDEA 14 there is also Clone Caret Above / Below:

  • Windows: Ctrl, Ctrl+Up/Down
  • MacOS: Option,Option + Up/Down

(hold the second press of the modifier key, then press the arrow key)

Solution 3:

Another keyboard-only approach. It's possible (since 13.1 version) to use Alt+J / Shift+Alt+J (Ctrl+G for OS X) shortcuts for creating multiple carets. Alt+J selects the next occurrence of the currently selected text and adds another caret.

  1. Select the first semicolon

enter image description here

  1. Then press Alt+J four times

enter image description here

  1. Edit what you want to

enter image description here

  1. Press Esc to return to the first line.

enter image description here

Solution 4:

Place caret at end

Windows: CTRL + CTRL(Hold) + ↑ / ↓

Mac: option + option(Hold) + ↑ / ↓.

To place caret at the end of rows: move caret to top row, clone down to bottom, and click END.

Change Multi-caret Hotkey

To add a custom Keymap, CTRL+SHIFT+A, type keymap and click on the one with Settings as subtext. Search for Clone Caret Above and Clone Caret Below.

I mapped mine to ALT+SHIFT+↑ / ↓ on Windows and +↑ / ↓ on Mac.

Bonus

Try holding combinations of CTRL, SHIFT, and arrows for improved selection power.