开发者

Remove empty lines in eclipse code editor by find/replace (Ctrl+F)

I want to remove all blank lines from my code by find/replace method in eclipse cod开发者_如何学编程e editor.

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

Why i got this error and how to properly remove the blank lines? What will the working replacement character ?

Is there any eclipse plugin for these kind of job?


I am not sure if it is the answer to your specific problem but the solution with the \r\ .. indicates it is an incompatibility between Windows and UNIX text encoding . So a simple solution will be to convert the file to UNIX encoding

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


You can try replacing this:

^\s*\r?\n

with the empty string.


try using \R instead of \n

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


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

\n\s*$

with a replacement of [nothing].

Can't help with the mysterious error, though. I wonder if you have a corrupt file, maybe a stray CR/LF confusion.

(As for a plugin... don't know of any, but, well, learn awk, sed, perl... they'll always serve you well for your miscellaneous text-mangling jobs.)


In response to the first part of your question about the incompatible line delimiter near index error, Eclipse seems to have an issue with Replacing the given line delimiter depending on the Text file encoding and New text file line delimiter settings.

I had an issue where a Windows application mistakenly formatted UNIX-formatted source files, inserting CRLF wherever it saw fit. Because of the particular situation I had to replace all of the CRLF's with space. Eclipse wouldn't allow me to do this because of that error, but grabbing the preceding and succeeding characters did the trick:

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

Using wjans suggested answer:

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

I hope this helps with those of you still getting the incompatible line delimiter error.


This worked for me for years:

Replace: [\t ]+$

With blank


I've been having this problem (or variations of it) for years and I suspect it's caused by sharing fileservers with Mac users, specifically users of Dreamweaver (graphic artists basically). It looks like it changes the files it edits (uploads?) to mixed/weird line endings that appear to be a combination of NL+CR (hex 0a0d), double-CR (0d0d) and solidary newlines (0a).

If you opened the same file in vim it isn't double-spaced BUT the lines all end with an ^M symbol.

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

You need to perform these steps in order (Eclipse 4.2.2)

1.) File -> Convert Line Delimiters To -> MacOS 9 (CR, \r)

2.) Edit -> Find / Replace (Ctrl - F)

Find: \r$
Replace: leave blank

3.) Replace All

If you don't do it in order or you mess with the file first you'll get an error about "incompatible line delimiters" like in the question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜