IntelliJ IDEA way of editing multiple lines

Viewed 149794

I've seen this done in TextMate and I was wondering if there's a way to do it in IDEA.

Say I have the following code:

 leaseLabel = "Lease";
 leaseLabelPlural = "Leases";
 portfolioLabel = "Portfolio";
 portfolioLabelPlural = "Portfolios";
 buildingLabel = "Building";

What is the best way to append '+ "foo"' to every line? Column mode won't work since the lines are not correctly aligned on the right side... unless there is an easy way to right justify the text :P

21 Answers

Column mode works just fine: first select all the lines in column mode, then press END: each cursor will jump to the end of respective line.

On Linux (NO MOUSE NEEDED):

  1. ALT + SHIFT + INSERT to enter block-mode

    entered column edit mode

  2. SHIFT + UP or SHIFT + DOWN to select multiple lines

    enter image description here

  3. END to jump to the end of each line

    enter image description here

  4. now type foo, it will append it to each line:

    enter image description here

  5. Now deselect everything with ESCAPE and switch back to normal selection mode with ALT + SHIFT + INSERT.

Since WebStorm 2020.2 you can use AltShiftG to add carets at the end of each selected line.

The new action for working with multiple carets (Alt+Shift+G) lets you quickly place carets at the end of each selected line and removes the selection as soon as all carets are added.

What’s new in WebStorm 2020.2

enter image description here

Select Next Occurrence:

      Alt+J on Windows, Ctrl-G on Mac OS X

Unselect Occurrence:

      Alt+Shift+J on Windows, Ctrl-Shift-G on Mac OS X

Select All Occurrences:

      Ctrl+Alt+Shift+J on Windows, Ctrl-Cmd-G on Mac OS X

for more reference: link

I just use the macros for this sort of thing. I start recording the macro, do it once, then play back the macro on each line I want to modify. You'd be amazed at how fancy you can get with the macro record/playback feature.

ALT + CTRL + SHIFT + CLICK on linux

Hold ALT and use the mouse for click and drag

I hold (Shift + option + command) then click where ever I want the extra cursor to go. Using Webstorm and on a Mac

For Mac:

Option + Shift + Click & Drag

For newer versions use: Alt + Shift + Insert

You can set multiple carets from the search and replace tool.

  1. Ctrl + R to open Search & Replace tool
  2. Write the character or word identifying the beginning of each recurrence to edit
  3. Clic on 'Select all occurence' in the Search & Replace tool, IntelliJ will put a caret for each occurence

Live the magic

For mac users it's : ALT + SHIFT + Click

All the above answer are great, but if you want multiline edit at the end of lines then you have press "End" key while your multiline selection is active.

For Mac Sequence of command will be:

shift option click # select a set of lines

command right arrow # go to the end of lines

This will do multiline select at the end of the line and you can edit it as required

Related