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.
Type M-x delete-trailing-whitespace to delete all trailing whitespace. This command deletes all extra spaces at the end of each line in the buffer, and all empty lines at the end of the buffer; to ignore the latter, change the variable delete-trailing-lines to nil .
To remove leading and trailing spaces in Java, use the trim() method. This method returns a copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space.
Trailing whitespace. Description: Used when there is whitespace between the end of a line and the newline.
You can use Find Action with ⌘⇧A (macOS), or Ctrl+Shift+A (Windows/Linux), and then type in 'Show virtual space at the bottom of the file'. This allows you to scroll past the end of the file so that the last line of text will be at the top of the window.
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
In 2020.1 IntelliJ version:
File -> Settings -> Editor -> General -> then scroll down to 'Save Files'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With