- removing whitespace from the entire file being edited:
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.
- removing whitespace only from the lines i changed:
preferences -> java -> editor -> save actions -> check "perform the selected actions on save -> check format source code -> select format edited lines.
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.
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
i used this command for git:
git config --global core.whitespace cr-at-eol
^m characters that are trailing.
i am not aware of any solution for the second part of your question. the reason is that it is not clear how to define i changed. changed when? just between 2 saves or between commits... basically - forget it.
i assume you would like to stick to some guideline, but do not touch the rest of the code. but the guideline should be used overall, and not for bites and pieces. so my suggestion is - change all the code to the guideline: it is once-off operation, but make sure that all your developers have the same plugin (anyedit) with the same settings for the project.
there is a really easy way to do this with sed, the unix command line tool. you could probably create a macro in eclipse to run this:
sed -i 's/[[:space:]]*$//' <filename>
as @malvineous said, it's not professional but a work-around to use the find/replace method to remove trailing space (below including tab u+0009 and whitespace u+0020).
just press ctrl + f (or command + f)
[\t ][\t ]*$
- replace with blank string
- use regular expressions
- replace all
for removing leading space, find
^[\t ][\t ]* instead of
[\t ][\t ]*$
for removing blank lines, find
for php there is also an option:
it is impossible to do it in eclipse in generic way right now, but it can be changed given with basic java knowledge and some free time to add basic support for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=180349
the dependent issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=311173
i would say anyedit too. it does not provide this specific functionalities. however, if you and your team use the anyedit features at each save actions, then when you open a file, it must not have any trailing whitespace.
so, if you modify this file, and if you add new trailing spaces, then during the save operation, anyedit will remove only these new spaces, as they are the only trailing spaces in this file.
if, for some reasons, you need to keep the trailing spaces on the lines that were not modified by you, then i have no answer for you, and i am not sure this kind of feature exists in any eclipse plugin...
in a pinch, for those editors that don't support removal of trailing whitespace at all (e.g. the xml editor), you can remove it from all lines by doing a find and replace, enabling regular expressions, then finding "[\t ]+$" and replacing it with "" (blank). there's probably a better regex to do that but it works for me without needing to install anyedit.
you can map a key in eclipse to manually remove trailing whitespaces in the whole file, but only on request instead of automatically at save. (preference/keys and then map a set of keys to file/remove trailing whitespace) this can be useful if you want to sanitize all new files, but keep legacy code untouched.
another strategy is to activate visual display of whitespace, so at least you'll know when you're adding some trailing whitespace. as far as i know, there's no way to display only trailing whitespace though, but i'll be glad to be proved wrong.
preferences -> java -> editor -> save actions
pydev can do it by either ctrl+shift+f if you have code formatter option set to do it, or by during saving:
eclipse -> window -> preferences -> pydev -> editor -> code style -> code formatter:
i use at least these:
- auto format before saving
- right trim lines?
- add new line at end of file
you don't need any plugin to do so. for instance, if you code java, you can erase trailing whitespaces configuring save actions:
preferences -> java -> editors -> save actions -> check perform the selected actions on save -> check additional actions -> click the configure.. button.
in the code organizing tab, check remove trailing whitespace
i assume your questions is with regards to java code. if that's the case, you don't actually need any extra plugins to accomplish 1). you can just go to preferences -> java -> editor -> save actions and configure it to remove trailing whitespace.
by the sounds of it you also want to make this a team-wide setting, right? to make life easier and avoid having to remember setting it up every time you have a new workspace you can set the save action as a project specific preference that gets stored into your scm along with the code.
in order to do that right-click on your project and go to properties -> java editor -> save actions. from there you can enable project specific settings and configure it to remove trailing whitespace (among other useful things).
nb: this option has been removed in eclipse kepler (4.3) and following releases.
nb #2: the option seems to be back in eclipse luna -
luna service release 1a (4.4.1)
- How to remove trailing whitespace in PyDev plugin for Eclipse
- How to remove trailing whitespace *from selection* in Eclipse
- Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?
- How to remove trailing space behind multiline comment's asterisk in Eclipse autoformat
- How to remove spaces after comments in Eclipse auto formatting?
- How to avoid the Eclipse text editor to trim all lines, ie. to remove all trailing whitespace?
- How to auto-remove trailing whitespace in Eclipse?
- How to remove unused imports from Eclipse
- Eclipse - how to remove light bulb on warnings
- How to remove old versions of Eclipse plugins?
- How does one show trailing whitespace in eclipse?
- How to remove native support from an Android Project in eclipse because eclipse is showing errors in jni?
- How do i remove m2eclipse from my eclipse installation?
- How do I remove Maven from a Eclipse java project?
- How to stop Eclipse formatter from adding trailing whitespaces in Javadoc
- How do I modify the set method signature that Eclipse auto generates?
- How to remove a file from an Eclipse project without deleting the file from the disk?
- How to remove a dependency from my Android project in Eclipse
- How to remove JAX-WS Web Services node in Eclipse Project Explorer?
- How to remove eclipse darkest dark theme?
- Eclipse : How to remove the attached Source which was added to a Jar
- Eclipse spell checker - How do I remove a word I added?
- How do I remove view right to the editor in Eclipse pydev perspective?
- How to remove the lock in file association in eclipse
- How to turn off Eclipse auto expanded my project folders?
- How to use auto completion in Eclipse adding fully qualified name
- Eclipse Equinox, how to configure auto load the bundles in plugin folder
More Query from same tag
- Android Eclipse project compilation errors with maven provided dependency
- In Eclipse PDT, how to include a Subclipse project into another one?
- Unresolved inclusion: <iostream> in eclipse on mac
- Why is Setting Up a Development Environment for Android 2.3 under Windows so Nightmarish?
- Replace propertyName with their getMethod
- How to create "New Gradle Project" in eclipse
- UnsupportedOperationException on Endpoint.publish() with Jetty
- Is there any way to print japanese characters in a textEdit?
- Tool to remove JavaDoc comments?
- How can I fix this error when installing ADT on Ubuntu?
- Maps not loading after releasing on Play Store
- Auto FTP-Sync with Aptana-Plugin for Eclipse
- Compile Groovy files in Eclipse
- Unable to run android's hello world in ecplise
- how to get change in sidebar in eclipse
- Android - how do I add context menu with about and quit choices?
- Persistence.xml editor
- e4 RCP: modifying main-menu item programmatically
- How do I get the workbench window to open a modal dialog in an Eclipse based project?
- Eclipse PDT - find inexistent classes?
- Why the imported war file does not work in Eclipse
- Eclipse Java Debugger just stepping after first resume
- Using Stanford CoreNLP - Java heap space
- php, zend debugging, svn setup for many developers
- Eclipse java project forName() classnotfoundexception
- Error while adding JavaFX files in eclipse
- eclipse changing text on button click
- Eclipse project became invisible in file explorer after pushing to github
- Eclipse Java heap space
- Can't update an SQLite table with Eclipse