How to stop intellij-idea from removing white spaces at end of text lines in my file?

Go to File->Settings->Editor->General and under Other, set the drop down next to Strip trailing spaces on Save to whatever you wish. For future reference, you can press Ctrl-Shift-A and type a search term to find any menu command or setting very quickly. In this case, "trailing spaces" or "strip trailing spaces" works really well.


Newer PyCharm (2020 and beyond) have slightly different answer than Code-Apprentice's.

Go to File->Settings->Editor->General, and then scroll down to Save Files section. The drop down Strip trailing spaces on Save for: is there. You can select None if you don't want any stripping in no circumstances.

Here is an image showing the setting: Image describing the location of the drop-down