I wanted to replace all commas with commas and a newline using IntelliJ IDEA's replace function. What do I put in the search box? In vim I'd use &\r
.
10 Answers
You need to check the Regex box and use "\n" for the new line character:

- 16,160
- 5
- 51
- 68
-
And how can you remove an empty line using same regex. :) – muasif80 Sep 20 '17 at 18:22
Use Multiline button, no Regex is needed.
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

- 12,020
- 7
- 45
- 52
-
6I'm using 15, and it looks like the multiline feature is no more. Why would they remove such a useful feature? – Matthew Cornell Jan 14 '16 at 16:29
-
4This still exists, select multiple lines, then click `CTRL+F`, *then* click `CTRL+R`, it seems to be a hidden feature, but still works in that case as previous versions – wired00 May 22 '16 at 07:09
-
11It's even easier now -- a visible return carriage arrow appears within the find or replace boxes -- clicking it will insert a newline. – Louis St-Amour Nov 15 '17 at 16:02
-
is there any way to make it keep indentation? If I replace a string `apples` that starts at col 16 with `apples\nbananas`, bananas will be at column 0 – Tom M Nov 08 '21 at 16:55
-
-
For Intellij Ultimate 2017.3 on Mac, command-shift-enter
works

- 181
- 1
- 2
-
1This answer is legitimate and work for search and replace in IntelliJ IDEA, PHPStorm and WebStorm where the user wants to replace an instance of `\n` with actual new line. Please do not downvote useful answers. – Bartekus Apr 02 '18 at 23:01
Hit CTRL+F
and check the regex
checkbox. Then search for ,
and replace it with ,\n
.

- 1,725
- 10
- 22
The easiest way that I have done it is to use the regular expression form of 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.

- 22,034
- 5
- 72
- 84
-
-
It does, and it seems like you're faster with Paint :). PS: If you have not tried it, then I strongly suggest the Darcula! It is so much easier on my eyes. – pickypg Jan 19 '14 at 17:19
-
1It's PicPick I'm using. I tried Idea Darcula Theme, but I guess I'm too much used to the default colors. – Andrey Chaschev Jan 19 '14 at 19:13
On intellij Ultimate 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
- 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

- 7,063
- 4
- 43
- 44
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.
This is working on Mac IntelliJ 2016.1.3
with ⌘+F > ⌘+R

- 13,930
- 7
- 70
- 73
-
3
-
Even with this trick it is not possible to enter multiple lines in the replace field. – Daniele Torino Jun 22 '16 at 11:16
-
Its working for me fine within `IntelliJ 2016.1.3` on MAC, ⌘ + F > ⌘ + R – wired00 Jun 22 '16 at 22:33
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).
Example: (?m)\{(.|\n)*?\}
searches for multi-line blocks surrounded by curly braces.

- 2,129
- 1
- 13
- 12
The is related but not exactly what you asked. But I needed it and I can imagine others do to. So I had the problem in Node.js where I wanted to split a reject into call into a log and reject for clarity
reject(error)
into
appLogger.log(error, 'error')
reject(error)
In normal mode, I did find and replace
Find:
reject(error)
Replace:
appLogger.log(error, 'error')\n reject(error)
Then in regex mode I did a second find and replace:
Find:
\\n
Replace
\n

- 36
- 1
- 6
-
1If your answer is helpful, but not actually answering this question, it's better to ask a new question and add your answer there. We always welcome useful new questions and answers, and it's encouraged to answer your own question if you can :) – Max Vollmer Sep 30 '18 at 20:20