如何自动删除 Eclipse 中的尾随空格? [英] How to auto-remove trailing whitespace in Eclipse?

查看:30
本文介绍了如何自动删除 Eclipse 中的尾随空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有两个部分,其中一个我已经有了答案.

The question has two parts, one of which I already have the answer for.

  1. 如何从正在编辑的整个文件中自动删除尾随空格?-> 答案:使用 AnyEdit 插件,它可以设置为在任何保存到文件时执行此操作.
  2. 如何仅从我更改的行中自动删除尾随空格?-> 这个我不知道,希望得到任何帮助.
  1. How to auto-remove trailing whitespace from the entire file being edited? -> Answer: use the AnyEdit plugin, which can be set to do that on any save to the file.
  2. How to auto-remove trailing whitespace only from the lines I changed? -> This I don't know and would appreciate any help.

推荐答案

  1. 从正在编辑的整个文件中删除空白:

Preferences -> Java -> Editors -> Save Actions -> 勾选 Perform the保存时的选定操作 -> 检查 附加操作 -> 单击 Configure.. -> 转到 代码组织 选项卡 -> 检查删除尾随空格 -> 选择所有行.

Preferences -> Java -> Editors -> Save Actions -> check Perform the selected actions on save -> check Additional actions -> click Configure.. -> go to Code organizing tab -> check Remove trailing whitespace -> select All lines.

  1. 仅从我更改的行中删除空格:

Preferences -> Java -> Editor -> Save Actions -> 勾选Perform保存时选择的动作 -> 勾选Format source code -> 选择Format编辑行.

Preferences -> Java -> Editor -> Save Actions -> check "Perform the selected actions on save -> check Format source code -> select Format edited lines.

请注意,不必单击在格式化程序页面上配置格式化程序设置 - 所有代码样式都会自动包括删除尾随空格.至少我在 Formatter 配置中找不到这个设置,而且它对于内置的 Java 约定、Eclipse、Eclipse 2.1 样式以及 GoogleStyle.

Note it is not necessary to click Configure the formatter settings on the Formatter page - all the code styles automatically include removing trailing whitespace. At least I couldn't find a setting for this in Formatter configuration, and it worked out of the box for built-in Java Conventions, Eclipse, Eclipse 2.1 styles, as well as GoogleStyle.

使用此设置时,您显然还需要关闭问题第 1 部分的解决方案.

When using this set-up, you obviously need to also turn off the solution to part 1 of the question.

Eclipse version checked: 4.5.2, 4.11

这篇关于如何自动删除 Eclipse 中的尾随空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆