Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to automatically remove trailing spaces in Eclipse?

Tags:

java

Is there a way to automatically remove trailing spaces in Eclipse?

I see there are nice functionality in Source like Correct Indentation and Format. But they dont remove trailing spaces.

Thanks

PS: What other functionalities of this kind you use to make the code nicer?

like image 916
user1796942 Avatar asked Jan 06 '13 02:01

user1796942


2 Answers

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

Note that this will remove all trailing whitespace from Java files - not just those you've touched. If you're working with people who don't remove trailing whitespace, this can be messy in terms of later doing a diff.

like image 176
Jon Skeet Avatar answered Oct 10 '22 08:10

Jon Skeet


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"

like image 20
Jim Rhodes Avatar answered Oct 10 '22 06:10

Jim Rhodes