Delete blank lines in eclipse code editor with find / replace (Ctrl + F)

I want to remove all empty lines from my code using the find / replace method in the eclipse code editor.

I used the regular expression \n\s*\n to find all empty lines, but I got the error "Incompatible line delimiter near index 55110" when replacing an empty line with any line.

Why did I get this error and how to delete empty lines correctly? What will be the working replacement symbol?

Is there any eclipse plugin for this kind of work?

+7
source share
7 answers

You can try replacing this:

 ^\s*\r?\n 

with an empty string.

+9
source

I am not sure if this is the answer to your specific problem, but a solution with \ r \ .. indicates that it is incompatibility between Windows text encoded and UNIX. Thus, a simple solution would be to convert the file to UNIX encoding

In Eclipse Menu -> File -> Convert line delimiter -> Unix

+10
source

I tried your expression and it combined some lines. I found this to work:

 \n\s*$ 

with replacement [nothing].

It is impossible to help with a mysterious mistake. I wonder if you have a corrupt file, possibly a CR / LF wandering confusion.

(As for the plugin ... I don’t know anyone, but, well, study awk, sed, perl ... they will always serve you well for your various tasks on word processing.)

+2
source

In response to the first part of your question about incompatible line delimiter near index error, Eclipse seems to have a problem replacing the specified line separator depending on the settings for Text file encoding and New text file line delimiter .

I had a problem when a Windows application mistakenly formatted UNIX source files by inserting CRLF wherever it is. Due to the specific situation, I had to replace the entire CRLF with space. Eclipse would not allow me to do this because of this error, but capturing previous and subsequent characters did the trick:

 Find : (.)\r\n(.) Replace: $1 $2 

Using wjans suggested answer:

 Find : ^\s*\r?\n(.) Replace: $1 

Hope this helps those who still get incompatible line delimiter error.

+2
source

try using \R instead of \n

\ R Any Unicode string sequence \ u000D \ u000A | [\ u000A \ u000B \ u000C \ u000D \ u0085 \ u2028 \ u2029]

+1
source

This has worked for me for many years:

Replace: [\ t] + $

With empty

0
source

I have had this problem (or its variations) for many years, and I suspect that this is caused by the exchange of file servers with Mac users, in particular Dreamweaver users (mostly graphic artists). It looks like he is changing the files he is editing (loading?) Into mixed / weird lines, which are a combination of NL + CR (hex 0a0d), double-CR (0d0d) and solid newline lines (0a).

If you opened the same file in vim, it is not a double interval, but all lines end with ^ M.

Anyway, none of the solutions on this page worked for me, but I found something that does.

You need to follow these steps (Eclipse 4.2.2)

1.) File β†’ Convert Line Delimiters To β†’ MacOS 9 (CR, \ r)

2.) Change β†’ Find / Replace (Ctrl-F)

 Find: \r$ Replace: leave blank 

3.) Replace everything

If you do not do this in order or start with the file again, you will receive an error message "incompatible line separators", as in the question.

0
source

All Articles