IntelliJ IDEA编辑多行的方式
我已经在 TextMate 中看到了这一点,我想知道是否有办法在 IDEA 中做到这一点。
假设我有以下代码:
leaseLabel = "Lease";
leaseLabelPlural = "Leases";
portfolioLabel = "Portfolio";
portfolioLabelPlural = "Portfolios";
buildingLabel = "Building";
将 '+ "foo"' 添加到每一行的最佳方法是什么? 列模式将不起作用,因为行在右侧没有正确对齐...除非有一种简单的方法来右对齐文本:P
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(21)
从 Idea IntelliJ IDEA 13.1 开始,可以编辑多行。
Windows
Alt + Shift + 鼠标单击
macOS
Option + Shift + 鼠标单击
进行选择。 有关 IntelliJ 博客文章中这一新改进的更多信息 此处。 非常有用的功能。
Since Idea IntelliJ IDEA 13.1 there is a possibility to edit multiple lines.
Windows
Alt + Shift + Mouse click
macOS
Option + Shift + Mouse click
for selection. More about this new improvement in the IntelliJ blog post here. Very useful feature.
我使用列选择模式(在 Mac 上为 Cmd+Shift+8),它允许通过 < kbd>Shift+Up 或 Shift+Down 然后一起编辑所有行。
从 IntelliJ IDEA 14 开始,还有在上方/下方克隆插入符:
(按住第二次修改键,然后按箭头键)
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:
(hold the second press of the modifier key, then press the arrow key)
另一种仅使用键盘的方法。 可以(自 13.1 版本起)使用 Alt+J / Shift+Alt+J< /kbd>(对于 OS X,Ctrl+G)用于创建多个插入符的快捷方式。 Alt+J 选择当前所选文本的下一个匹配项并添加另一个插入符号。
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.
将脱字符号放在末尾
Windows: CTRL + CTRL(按住)+ ↑ / ↓
Mac:< /strong> 选项 + 选项(按住)+ ↑ / ↓。
要将脱字符号放在行末尾:将脱字符号移动到顶行,向下克隆到底部,然后单击 END。
更改多插入符号热键
要添加自定义键盘映射,请按 CTRL+SHIFT+A,输入
keymap
并单击以Settings
作为潜台词的一个。 搜索克隆插入符上方
和克隆插入符下方
。我将我的映射到 Windows 上的 ALT+SHIFT+↑ / ↓ 和 ⌘+↑ / ↓ 在 Mac 上。
奖励
尝试按住 CTRL、SHIFT 和箭头的组合以提高选择能力。
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 withSettings
as subtext. Search forClone Caret Above
andClone 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.
列模式工作得很好:首先在列模式下选择所有行,然后按 END:每个光标将跳转到相应行的末尾。
在 Linux 上(无需鼠标):
ALT
+SHIFT
+INSERT
进入块模式< /p>SHIFT + UP
或SHIFT + DOWN
选择多行END
跳转到每个图像的末尾线现在输入
foo
,它会将其附加到每一行:现在使用
ESCAPE
取消选择所有内容,并使用 < 切换回正常选择模式代码>ALT + SHIFT + INSERT。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):
ALT
+SHIFT
+INSERT
to enter block-modeSHIFT + UP
orSHIFT + DOWN
to select multiple linesEND
to jump to the end of each linenow type
foo
, it will append it to each line:Now deselect everything with
ESCAPE
and switch back to normal selection mode withALT + SHIFT + INSERT
.自 WebStorm 2020.2 起,您可以使用 AltShiftG 在每个选定行的末尾添加插入符号。
WebStorm 2020.2 中的新增功能
Since WebStorm 2020.2 you can use AltShiftG to add carets at the end of each selected line.
What’s new in WebStorm 2020.2
您还可以通过单击鼠标滚轮并拖动来进行垂直代码块选择:
You could also do a vertical code block selection by clicking mouse wheel and dragging:
选择下一个出现:
取消选择出现:
选择所有出现:
更多参考:链接
Select Next Occurrence:
Unselect Occurrence:
Select All Occurrences:
for more reference: link
我花了一段时间才找到答案,但在 Mac 上,您可以双击 Option(按一次,松开,再按一次,保持按下)并使用 Up/向下 键可根据需要创建/删除插入符。
您还可以按住 Shift+Option 并单击以在特定点创建/删除插入符号。
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.
Linux 上的 ALT + CTRL + SHIFT + 单击
ALT + CTRL + SHIFT + CLICK on linux
我只是将宏用于此类事情。 我开始录制宏,执行一次,然后在我想要修改的每一行上回放宏。 您会惊讶地发现宏记录/回放功能如此美妙。
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并使用鼠标单击并拖动
Hold ALT and use the mouse for click and drag
我按住(Shift + option + command),然后单击我想要额外光标移动的位置。 在 Mac 上使用 Webstorm
I hold (Shift + option + command) then click where ever I want the extra cursor to go. Using Webstorm and on a Mac
对于 Macbook,它是
Option + Shift + Click
。所有重要的 Intellij 快捷方式:https://docs.google.com/document /d/1KagEr4hDmTugMJJLsYUgc122zXEnbj4A2vHoe8PtKpo/edit?usp=sharing
It's
Option + Shift + Click
for Macbook.All Important Intellij Shortcuts: https://docs.google.com/document/d/1KagEr4hDmTugMJJLsYUgc122zXEnbj4A2vHoe8PtKpo/edit?usp=sharing
在这种情况下,您也可以只选择要执行此操作的代码段并对其执行替换。 替换:
”;
与:
” + “foo”;
因此,如果您不知道:如果您在执行替换(Ctrl+R 或 Cmd+R)时选择了文本,它将仅适用于选定的文本片段。
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.
对于较新版本,请使用:Alt + Shift + Insert
For newer versions use: Alt + Shift + Insert
您可以通过搜索和替换工具设置多个插入符。
享受魔法
You can set multiple carets from the search and replace tool.
Live the magic
对于苹果机:
For Mac:
上面的所有答案都很好,但是如果您想在行尾进行多行编辑,那么您必须在多行选择处于活动状态时按“End”键。
对于 Mac,命令顺序为:
shift
option
click
# 选择一组行command
right arrow
# 转到行尾这将在行尾进行多行选择,您可以根据需要对其进行编辑
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 linescommand
right arrow
# go to the end of linesThis will do multiline select at the end of the line and you can edit it as required
我通常使用的(NetBeans,但我相信它在任何 IDE 中使用都很简单)是
find&replace
。您只需找到
;\n
并将其替换为+ $foo;\n
那么您并不适用于所有行,而是将光标放在第一行上,然后您就可以了点击“替换”按钮(我想这取决于你的 IDE)7 次即可立即更改 7 行。 简单又简单,应该使用您能找到的最基本和最先进的 IDE 来完成。编辑:
在 IntelliJ 中(不知道它是否也适用于其他 IDE),您可以仅使用正则表达式搜索和替换来选择,这样您实际上可以使用“全部替换”
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"
对于 Mac 用户,它是:
ALT + SHIFT + Click
For mac users it's :
ALT + SHIFT + Click