In Eclipse, how do I replace a character by a new line?
Asked Answered
T

6

93

In Eclipse 3.3.2, I would like to replace a character (say ',') by a new line in a file. What should I write in the "Replace with" box in order to do so ?

EDIT : Many answers seems to be for Eclipse 3.4. Is there a solution for Eclipse 3.3.X ?

Training answered 1/10, 2008 at 8:32 Comment(0)
A
156

Check box 'Regular Expressions' and use '\R' in the 'Replace with' box

It's a new feature introduced with Eclipse 3.4, See What's New in 3.4

Abaca answered 1/10, 2008 at 8:35 Comment(7)
Check if Eclipse value assistance in the Replace with box offers you \R as a possibility, if it doesn't your Eclipse version doesn't handle itAbaca
I'm on version 3.3.2 and, the assistance doesn't show me that value.Training
This has bugged me for years. I can't believe I never took the time to google how to do it (which of course brought me here.)Blooper
You saved my as minimum 15 minutesLosse
Eclipse.org have stopped hosting that archived release. I found it online here: helpml.com:8088/help/index.jsp?topic=/… (click on Search in the Table of contents)Forewarn
With the Find/Replace dialog open and in focus, press F1 to bring up a context sensitive help popup and then click on the link to Find/Replace with regular expressions to see all the supported escape sequences.Forewarn
I am using Eclipse 4.25, and as suggested by @user9796835, I have to search with the Regular expression option selected (i.e. ticked) in order to enable the Regular expression option when I subsequently select the Replace option(s).Joshuajoshuah
A
3

Check box 'Regular Expressions' and use '\n' in the 'Replace with' box

Amick answered 1/10, 2008 at 8:41 Comment(2)
Yes, I tried that first but it is not working on my eclipse (3.3.2).Training
This worked for netbeansWhiffletree
R
3

Like the others said, just use regular expression, but instead of just \r, put \r\n

Rehm answered 1/6, 2017 at 12:25 Comment(0)
M
1

if the file search is performed with Regular Expressions checkbox checked, then replace all / replace selected will also allow regular expression and will transform \n to a newline in the file(s)

Muckrake answered 15/5, 2018 at 21:35 Comment(0)
T
0

I've just found an article about that problem. It seems to be a bug.

There's a workaround which is to copy a new line in clipboard and then paste it inside the "replace" box.

Training answered 1/10, 2008 at 8:40 Comment(4)
I don't even understand what the workaround is supposed to beAbaca
You'll have to select the "new line character" by clicking on the last character's line and move the mouse before the first character on the next line. I indeed select something but I'm not able to paste it in the replace box.Training
Managed to paste using right click menu, but the replace won't insert newlines.Abaca
invalid link on the answerMorette
G
0

I'm using Helios and it works, however I had some issues with replacement... I wanted to place a line break between any of these brackets "><" (to make each new XML tag go to a new line)... first I had to place a chacter between the 2 brackets, for instance /r, after this i checked the "regular expressions" box and replaced the /r with \R, which resulted in the correct linebreak. otherwise, the replace seemed to be greyed out.

Gutturalize answered 12/4, 2011 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.