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:46

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.

查看更多
叼着烟拽天下
3楼-- · 2020-02-16 08:46

ALT + CTRL + SHIFT + CLICK on linux

查看更多
我只想做你的唯一
4楼-- · 2020-02-16 08:46

What I usually use (NetBeans, but I believe it is simple to use in any IDE) is find&replace.

You just find ;\n and replace it with + $foo;\n then you don't apply to ALL lines but you place cursor on the first line and you just hit "replace" button (depends on your IDE I suppose) 7 times to change 7 lines in no time. Easy and simple and it should be done with the most basic and the most advanced IDE you can find.

EDIT: In IntelliJ (don't know if it works in other IDEs too) you can use your regexp search&replace to selection only so you can actually use "replace all"

查看更多
手持菜刀,她持情操
5楼-- · 2020-02-16 08:54

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)

查看更多
登录 后发表回答