Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA - multiple carets?

Sometimes I have to write Java class where I need to define multiple fields of the same type. For example, I know that I will need to duplicate private final String on the next 4 lines.

Is it possible to spawn multiple carets in IntelliJ editor, so I can type on mutliple lines at the sime time?

like image 710
Xorty Avatar asked Aug 20 '13 10:08

Xorty


People also ask

How do I make multiple cursors in Intellij?

Alt+Shift+Click at the target location to add another caret. Alt+Shift+Click at one of the multiple carets to remove it.

How do you select multiple lines vertically?

Place your cursor somewhere in or next to the first word you wish to select. While holding down Ctrl (Windows & Linux) or Command (Mac OS X), click in the next word you wish to select. Repeat until you've selected the words you want to change.


2 Answers

IntelliJ IDEA 14.1 & 15

You can press Alt + Shift and using the mouse left click you can put many carets.

E.g.:

long caret 1

will become

long caret 2

typing "added" only once.

If you want to have a continuous vertical line, it's enough to press Alt + drag your mouse vertically. If there are lines with a length lower than the current position, the vertical line will be broken (carets will be placed at the end of every line) if "Allow placement of caret after end of line" is disabled (in File > Settings... > Editor > General > Virtual Space).

Another way to add a continuous vertical line is to hit Ctrl twice and then press up or down arrow key (supported in JetBrains 2016.X products, and possibly earlier).

If you cannot get the shortcuts working, check what they're currently assigned to under Settings > Keymap Add or Remove Caret, Clone Caret Above and Clone Caret Below. If they look right and you're on Linux, your window manager may be capturing the combination, e.g., for Alt + window drag operations.

See:

  • http://blog.jetbrains.com/idea/2015/02/multiple-selections-in-editor-using-mouse/

  • https://www.jetbrains.com/help/idea/2016.3/multicursor.html

like image 197
ROMANIA_engineer Avatar answered Sep 19 '22 18:09

ROMANIA_engineer


I think "Column Selection Mode" could help you. You can enable it in the context menu in the editor. Then you can select multiple lines and type same text at once.

like image 20
chalimartines Avatar answered Sep 22 '22 18:09

chalimartines