Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA way of editing multiple lines

People also ask

How do I edit multiple lines in IntelliJ?

To select ranges as multiple rectangular selections, Ctrl+Alt+Shift+Click and drag the mouse over the desired parts of code. As a result, you will have multiple selection ranges in each affected document line. On lines that are shorter than the rectangle, the selection will only span to the last character.

How do you edit multiple lines at once?

Select the lines you want and then press: Windows: Shift + Alt + i. Mac: shift + option + i.

How do I format multiple lines in IntelliJ?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | Code Style. Switch to the Formatter tab and in the Do not format field, enter the files and directories that you want to exclude using a glob pattern. , the field will expand, and each pattern will be shown on a separate line.


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.


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)


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


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.