Remove trailing whitespace on save in IntelliJ IDEA 12

Is it possible to remove trailing whitespace automatically on save in IntelliJ IDEA? I know there are some workarounds, for example, using git to trim the whitespace on commit. Maybe this question is a duplicate of this one, but i hope this can be done without setting up keyboard shortcuts and macros.


Don't know about 12, but there's the following setting in 13:

Settings → Editor → Strip trailing spaces on Save

As of IntelliJ 2017.2 it's under

Settings → Editor → General → Strip trailing spaces on Save

configuration dialogue


In 2020.1 IntelliJ version:

File -> Settings -> Editor -> General -> then scroll down to 'Save Files'

Strip trailing spaces on Save option


Go to ==> PREFERENCES | GENERAL | OTHER |

Just as shown in the picture:

  1. Srip trailings spaces on Save: ALL
  2. Uncheck Allways keep....

It'll remove trailing spaces when save, not before

enter image description here