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条回答
狗以群分
2楼-- · 2020-02-16 08:40

In this case you can also just select the piece of code in which you want to do this and perform a replace on it. Replace:

";

with:

" + "foo";

So in case you didn't know: If you have text selected while you perform a replace (Ctrl+R or Cmd+R) it will only apply to the selected piece of text.

查看更多
The star\"
3楼-- · 2020-02-16 08:41

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.

查看更多
成全新的幸福
4楼-- · 2020-02-16 08:42

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

查看更多
何必那么认真
5楼-- · 2020-02-16 08:42

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

查看更多
6楼-- · 2020-02-16 08:43

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

Use:

Alt + Shift + Mouse click

for selection. More about this new improvement in IntelliJ blogpost here. Very useful feature.

查看更多
爷的心禁止访问
7楼-- · 2020-02-16 08:43

It took me a while to find out, but on a Mac you can double-press Option (press it once, release, press it again, keep it pressed) and use Up/Down keys to create/remove carets as you wish.

You can also hold Shift+Option and click to create/remove carets at specific points.

查看更多
登录 后发表回答