IntelliJ IDEA way of editing multiple lines

2020-02-16 08:08发布

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

16条回答
\"骚年 ilove
2楼-- · 2020-02-16 08:35

For Mac:

Option + Shift + Click & Drag
查看更多
唯我独甜
3楼-- · 2020-02-16 08:36

You could also do a vertical code block selection by clicking mouse wheel and dragging:

enter image description here

查看更多
We Are One
4楼-- · 2020-02-16 08:36

Hold ALT and use the mouse for click and drag

查看更多
祖国的老花朵
5楼-- · 2020-02-16 08:37

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

查看更多
倾城 Initia
6楼-- · 2020-02-16 08:37

It's Option + Shift + Click for Macbook.

All Important Intellij Shortcuts: https://docs.google.com/document/d/1KagEr4hDmTugMJJLsYUgc122zXEnbj4A2vHoe8PtKpo/edit?usp=sharing

查看更多
来,给爷笑一个
7楼-- · 2020-02-16 08:38

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.

查看更多
登录 后发表回答