Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 739
klingt.net Avatar asked Dec 19 '13 10:12

klingt.net


People also ask

How do you get rid of trailing white space?

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 .

How do you get rid of leading and trailing white spaces?

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.

What are trailing whitespace?

Trailing whitespace. Description: Used when there is whitespace between the end of a line and the newline.

How do I show whitespace in Intellij?

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.


2 Answers

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

like image 167
Vic Avatar answered Oct 02 '22 23:10

Vic


In 2020.1 IntelliJ version:

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

Strip trailing spaces on Save option

like image 35
zeljko_a Avatar answered Oct 02 '22 23:10

zeljko_a