Say I wanted to replace all commas with commas and a new line using Intellij IDEA's replace function. What do I put in the search box? In vim I'd use &\r
假设我想用逗号替换所有的逗号,并使用Intellij IDEA的replace函数替换新的行。我在搜索框里放了什么?在vim中我使用&\r
8 个解决方案
#1
138
You need to check the Regex box and use "\n" for the new line character:
您需要检查Regex框,并使用“\n”作为新行字符:
#2
83
Use Multiline button, no Regex is needed.
使用多线按钮,不需要Regex。
edit: the multiline button is missing since IntelliJ 15, but you can enable it by clicking into the textfield and pressing Alt+Enter
or Ctrl+Shift+Enter
编辑:自从intellij15以来,多行按钮就不见了,但是你可以通过点击textfield并按Alt+Enter或者Ctrl+Shift+Enter来启用它
#3
7
Hit CTRL+F
and check the regex
checkbox. Then search for ,
and replace it with ,\n
.
按CTRL+F,选中regex复选框。然后搜索,并替换为,\n。
#4
6
The easiest way that I have done it is to use the regular expression form of replace.
最简单的方法是使用正则表达式形式的replace。
Chances are that you don't want to replace the {
, but just keep in my escaping them if you do want to do so.
您可能不希望替换{,但是如果您确实想这样做,请继续使用我的转义符。
#5
2
For those looking for the old multiline replace in inteliJ with version > 15.x. It seems somewhat hidden, but if you select multiple lines > click CTRL+F
, then immediately click CTRL+R
you are presented with the original multiline replace.
对于那些寻找用> . 15.x版本替换inteliJ中的旧多行。它看起来有点隐藏,但是如果你选择多行>点击CTRL+F,然后立即点击CTRL+R,你会看到原来的多行替换。
This is working on Mac IntelliJ 2016.1.3
with ⌘+F > ⌘+R
这是工作在Mac IntelliJ 2016.1.3⌘+ F >⌘+ R
#6
1
On intellij Ultimate 2017.1:
在intellij终极2017.1:
I didn't need regex. But I could make the multiline replace appear.
我不需要正则表达式。但是我可以让多行替换出现。
- I entered \n in the field I wanted to replace
- 我在我想要替换的领域中输入了\n
- I placed my cursor in the field where I wanted to enter the replacement text, and clicked Ctrl-Shift + Enter. Here I just hit return
- 我将光标放在要输入替换文本的字段中,然后单击Ctrl-Shift + enter。这里我点击return
#7
0
A clean approach would be to add (?m)
in front of the regular expression, which turns on the multi line mode. This has the advantage that you can also use it in the global file search (Ctrl-Shift-F).
一种干净的方法是在正则表达式前面添加(?m),正则表达式打开多行模式。这在全局文件搜索(Ctrl-Shift-F)中也可以使用它。
Example: (?m)\{(.|\n)*?\}
searches for multi-line blocks surrounded by curly braces.
例如:(?)\ {(. | \ n)* ?搜索被花括号包围的多行块。
#8
0
For Intellij Ultimate 2017.3 on Mac, command-shift-enter
works
对于Mac上的Intellij Ultimate 2017.3,命令移位-enter工作
#1
138
You need to check the Regex box and use "\n" for the new line character:
您需要检查Regex框,并使用“\n”作为新行字符:
#2
83
Use Multiline button, no Regex is needed.
使用多线按钮,不需要Regex。
edit: the multiline button is missing since IntelliJ 15, but you can enable it by clicking into the textfield and pressing Alt+Enter
or Ctrl+Shift+Enter
编辑:自从intellij15以来,多行按钮就不见了,但是你可以通过点击textfield并按Alt+Enter或者Ctrl+Shift+Enter来启用它
#3
7
Hit CTRL+F
and check the regex
checkbox. Then search for ,
and replace it with ,\n
.
按CTRL+F,选中regex复选框。然后搜索,并替换为,\n。
#4
6
The easiest way that I have done it is to use the regular expression form of replace.
最简单的方法是使用正则表达式形式的replace。
Chances are that you don't want to replace the {
, but just keep in my escaping them if you do want to do so.
您可能不希望替换{,但是如果您确实想这样做,请继续使用我的转义符。
#5
2
For those looking for the old multiline replace in inteliJ with version > 15.x. It seems somewhat hidden, but if you select multiple lines > click CTRL+F
, then immediately click CTRL+R
you are presented with the original multiline replace.
对于那些寻找用> . 15.x版本替换inteliJ中的旧多行。它看起来有点隐藏,但是如果你选择多行>点击CTRL+F,然后立即点击CTRL+R,你会看到原来的多行替换。
This is working on Mac IntelliJ 2016.1.3
with ⌘+F > ⌘+R
这是工作在Mac IntelliJ 2016.1.3⌘+ F >⌘+ R
#6
1
On intellij Ultimate 2017.1:
在intellij终极2017.1:
I didn't need regex. But I could make the multiline replace appear.
我不需要正则表达式。但是我可以让多行替换出现。
- I entered \n in the field I wanted to replace
- 我在我想要替换的领域中输入了\n
- I placed my cursor in the field where I wanted to enter the replacement text, and clicked Ctrl-Shift + Enter. Here I just hit return
- 我将光标放在要输入替换文本的字段中,然后单击Ctrl-Shift + enter。这里我点击return
#7
0
A clean approach would be to add (?m)
in front of the regular expression, which turns on the multi line mode. This has the advantage that you can also use it in the global file search (Ctrl-Shift-F).
一种干净的方法是在正则表达式前面添加(?m),正则表达式打开多行模式。这在全局文件搜索(Ctrl-Shift-F)中也可以使用它。
Example: (?m)\{(.|\n)*?\}
searches for multi-line blocks surrounded by curly braces.
例如:(?)\ {(. | \ n)* ?搜索被花括号包围的多行块。
#8
0
For Intellij Ultimate 2017.3 on Mac, command-shift-enter
works
对于Mac上的Intellij Ultimate 2017.3,命令移位-enter工作