删除 Eclipse 中的空行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1974491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:04:45  来源:igfitidea点击:

Remove blank line in Eclipse

eclipse

提问by Steve

How can I remove lines that only contain spaces when using Eclipse Find/Replace prompt. I checked the "Regular Expression" check box, and tried the following, neither of which worked.

使用 Eclipse 查找/替换提示时,如何删除仅包含空格的行。我选中了“正则表达式”复选框,并尝试了以下方法,但均无效。

^[:space:]*$

and

^\s*$

回答by iamamac

Find: ^\s*\n

找: ^\s*\n

Replace with: (empty)

替换为:(空)

回答by fasseg

sry this might be an different answer but you can set the number of blank lines you wish to have after fields, methods and blocks in the formatting dialog of the eclipse preferences. then you can hit ctrl-shift-f to automatically format your code depending on your custom definitions.

抱歉,这可能是一个不同的答案,但您可以在 eclipse 首选项的格式设置对话框中的字段、方法和块之后设置您希望拥有的空行数。然后您可以点击 ctrl-shift-f 以根据您的自定义定义自动格式化您的代码。

have fun!

玩得开心!

回答by Copycopy

I was suprised that for XML files edited with Eclipse there is a good solution:

我很惊讶对于用 Eclipse 编辑的 XML 文件有一个很好的解决方案:

  • Select the checkbox value named 'Clear all blank lines' in Formatting panel Window->Preferences->XML->XML Files-> Editor

  • Save and use the "Ctrl+Shift+F' shortcut

  • 在格式面板窗口->首选项->XML->XML文件->编辑器中选择名为“清除所有空白行”的复选框值

  • 保存并使用“Ctrl+Shift+F”快捷键

The blank lines will dissappear!

空行将消失!

回答by Amit

  1. for the find/replace operation, "\n\r\s" regex will work on windows, for unix based system, "\n\s" can be used
  2. as already suggested, you can format your code by Ctl+Shift+F
  3. for manual work, locate a blank line and press Ctl+D (Cmd+D on Mac) <- gives u satisfaction of killing the line with your own bare hands :)
  1. 对于查找/替换操作,"\n\r\s" 正则表达式将在 windows 上工作,对于基于 unix 的系统,可以使用 "\n\s"
  2. 正如已经建议的那样,您可以通过 Ctl+Shift+F 格式化您的代码
  3. 对于手动工作,找到一个空行并按 Ctl+D(在 Mac 上为 Cmd+D)<- 让您满意地用自己的双手杀死该行:)

cheer!

欢呼!

回答by Ernani Joppert

This one worked for me for years:

这个对我来说有效了多年:

Replace this: [\t ]+$

替换这个: [\t ]+$

With nothing

一无所有

Hope this helps!

希望这可以帮助!

回答by easyplanner.cu.cc

Many thanks to lamamac. In genereal, when you want to do search replace with regular expressions in eclipse the $ sign doesn't work as it should. Use '\s*\n' instead of '$'

非常感谢喇嘛。一般来说,当你想在 eclipse 中用正则表达式进行搜索替换时,$ 符号不能正常工作。使用“ \s*\n”代替“ $

回答by eeadev

As already suggested, regular expression and replacement is the solution, but such response would have been saving some minutes to me:

正如已经建议的那样,正则表达式和替换是解决方案,但这样的响应会为我节省几分钟:

  1. click on ctrl+f
  2. use this replacement:
  1. 点击 ctrl+f
  2. 使用这个替换:

enter image description here

在此处输入图片说明