通过查找/替换删除eclipse代码编辑器中的空行(Ctrl+F)

时间:2022-12-01 14:11:12

I want to remove all blank lines from my code by find/replace method in eclipse code editor.

我想通过eclipse代码编辑器中的find/replace方法从代码中删除所有空行。

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.

我使用正则表达式\n\s*\n查找所有空行,但在用任何字符串替换空行时,都有“不兼容的行分隔符接近索引55110”。

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?

有什么eclipse插件可以做这些工作吗?

7 个解决方案

#1


9  

You can try replacing this:

你可以试着替换这个:

^\s*\r?\n

with the empty string.

空字符串。

#2


11  

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

我不确定这是否是你的具体问题的答案,而是用\r\ ..表示Windows和UNIX文本编码不兼容。因此,一个简单的解决方案是将文件转换为UNIX编码

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

在Eclipse菜单中—>文件—>转换行分隔符—> Unix

#3


3  

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.

不过,这个神秘的错误是无法避免的。我想知道你是否有一个损坏的文件,也许是一个偶然的CR/LF混淆。

(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.)

(至于插件…我不知道,但是,学习awk, sed, perl…他们将永远为你的杂事工作服务。

#4


2  

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.

在回答第一部分关于索引错误附近不兼容的行分隔符的问题时,Eclipse似乎有一个问题,即根据文本文件编码和新的文本文件行分隔符设置替换给定的行分隔符。

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:

我遇到了一个问题,Windows应用程序错误地格式化了unix格式的源文件,在适合的地方插入CRLF。由于特殊情况,我必须用空格替换所有CRLF。由于这个错误,Eclipse不允许我这样做,但是获取前面和后面的字符就可以了:

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

Using wjans suggested answer:

使用wjans建议回答:

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

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

我希望这能帮助那些仍然得到不兼容的行分隔符错误的人。

#5


1  

try using \R instead of \n

试试用\R代替\n吧

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

\R任何Unicode断行序列\u000D\u000A|[\u000A\u000B\u000C\ u000C\u000D\u0085\u2028\u2029]

#6


0  

This worked for me for years:

这对我起了多年的作用:

Replace: [\t ]+$

替换:[\ t]+ $

With blank

空白的

#7


0  

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).

我已经有这个问题(或它的变体)很多年了,我怀疑它是由与Mac用户共享文件服务器引起的,特别是Dreamweaver用户(基本上是平面艺术家)。它看起来像是将它编辑的文件(上传?)更改为混合/奇怪的行结尾,看起来是NL+CR (hex 0a0d)、double-CR (0d0d)和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.

如果你打开同一个文件在vim中它不是双倍行距但行以一个M ^符号结束。

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)

您需要按顺序执行这些步骤(Eclipse 4.2.2)

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

1)。文件->转换行分隔符到-> MacOS 9 (CR, \r)

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

2)。编辑->查找/替换(Ctrl - F)

Find: \r$
Replace: leave blank

3.) Replace All

3)。替换所有

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.

如果你不按顺序来做,或者你先弄乱文件,你会得到一个关于“不兼容的行分隔符”的错误,就像问题中提到的那样。

#1


9  

You can try replacing this:

你可以试着替换这个:

^\s*\r?\n

with the empty string.

空字符串。

#2


11  

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

我不确定这是否是你的具体问题的答案,而是用\r\ ..表示Windows和UNIX文本编码不兼容。因此,一个简单的解决方案是将文件转换为UNIX编码

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

在Eclipse菜单中—>文件—>转换行分隔符—> Unix

#3


3  

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.

不过,这个神秘的错误是无法避免的。我想知道你是否有一个损坏的文件,也许是一个偶然的CR/LF混淆。

(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.)

(至于插件…我不知道,但是,学习awk, sed, perl…他们将永远为你的杂事工作服务。

#4


2  

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.

在回答第一部分关于索引错误附近不兼容的行分隔符的问题时,Eclipse似乎有一个问题,即根据文本文件编码和新的文本文件行分隔符设置替换给定的行分隔符。

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:

我遇到了一个问题,Windows应用程序错误地格式化了unix格式的源文件,在适合的地方插入CRLF。由于特殊情况,我必须用空格替换所有CRLF。由于这个错误,Eclipse不允许我这样做,但是获取前面和后面的字符就可以了:

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

Using wjans suggested answer:

使用wjans建议回答:

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

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

我希望这能帮助那些仍然得到不兼容的行分隔符错误的人。

#5


1  

try using \R instead of \n

试试用\R代替\n吧

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

\R任何Unicode断行序列\u000D\u000A|[\u000A\u000B\u000C\ u000C\u000D\u0085\u2028\u2029]

#6


0  

This worked for me for years:

这对我起了多年的作用:

Replace: [\t ]+$

替换:[\ t]+ $

With blank

空白的

#7


0  

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).

我已经有这个问题(或它的变体)很多年了,我怀疑它是由与Mac用户共享文件服务器引起的,特别是Dreamweaver用户(基本上是平面艺术家)。它看起来像是将它编辑的文件(上传?)更改为混合/奇怪的行结尾,看起来是NL+CR (hex 0a0d)、double-CR (0d0d)和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.

如果你打开同一个文件在vim中它不是双倍行距但行以一个M ^符号结束。

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)

您需要按顺序执行这些步骤(Eclipse 4.2.2)

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

1)。文件->转换行分隔符到-> MacOS 9 (CR, \r)

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

2)。编辑->查找/替换(Ctrl - F)

Find: \r$
Replace: leave blank

3.) Replace All

3)。替换所有

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.

如果你不按顺序来做,或者你先弄乱文件,你会得到一个关于“不兼容的行分隔符”的错误,就像问题中提到的那样。