java 有没有办法在 Eclipse 中自动删除尾随空格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14178839/
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
Is there a way to automatically remove trailing spaces in Eclipse?
提问by user1796942
Is there a way to automatically remove trailing spaces in Eclipse?
有没有办法在 Eclipse 中自动删除尾随空格?
I see there are nice functionality in Source like Correct Indentation and Format. But they dont remove trailing spaces.
我看到 Source 中有很好的功能,比如正确的缩进和格式。但它们不会删除尾随空格。
Thanks
谢谢
PS: What other functionalities of this kind you use to make the code nicer?
PS:您还使用了哪些其他功能来使代码更好?
回答by Jon Skeet
It's available as a Save action, at least. (I can't see it under the formatter options.)
它至少可以作为保存操作使用。(我在格式化程序选项下看不到它。)
Go to Window / Preferences, Java / Editor / Save Actions. Tick "Additional Actions" and click on Configure. In the "Code Organizing" tab, the first option is "Remove trailing whitespace".
转到窗口/首选项、Java/编辑器/保存操作。勾选“其他操作”并单击“配置”。在“代码组织”选项卡中,第一个选项是“删除尾随空格”。
Note that this will remove alltrailing whitespace from Java files - not just those you've touched. If you're working with people who don'tremove trailing whitespace, this can be messy in terms of later doing a diff.
请注意,这将从 Java 文件中删除所有尾随空格 - 不仅仅是您接触过的空格。如果您正在与不删除尾随空格的人一起工作,那么就稍后进行差异而言,这可能会很混乱。
回答by Jim Rhodes
You can easily remove all the trailing whitespace within a single file by using a regular expression with the Find/Replace dialog. Enter [ \t]+$in the "Find:" box and leave the "Replace with:" box empty. Check the "Regular expressions" option then click "Replace All"
通过在“查找/替换”对话框中使用正则表达式,您可以轻松删除单个文件中的所有尾随空格。在“查找:”框中输入[ \t]+$并将“替换为:”框留空。选中“正则表达式”选项,然后单击“全部替换”
回答by Sven
There is also the plugin "AnyEdit" from http://andrei.gmxhome.de/eclipse/. This tool removes the whitespace in every file type on save.
还有来自http://andrei.gmxhome.de/eclipse/的插件“AnyEdit” 。此工具会在保存时删除每种文件类型中的空格。