Configure editor to remove whitespaces in blank lines


Is it possible to configure an editor in pycharm to automatically remove whitespaces in blank lines and trailing whitespaces when saving a file.


Hello Volodymyr,

Settings | Editor | Strip trailing spaces on Save | All

Is it possible to configure an editor in pycharm to automatically

remove whitespaces in blank lines and trailing whitespaces when saving

a file.


Dmitry Jemerov

Development Lead

JetBrains, Inc.

"Develop with Pleasure!"


Hi Dmitry, I'm having an issue with this feature.

I've created this video documenting my problem:

Is there a way I can set pycharm to remove trailing whitespace on lines that are within a function?

Thank you for any help,




I have the same issue in Webstorm: trailing spaces in empty lines are not removed after saving even in case "Settings | Editor | Strip trailing spaces on Save | All"


This is an issue for me too


+1 I, too, am having this issue.


What worked for me is un-tick the option 'Always keep trailing space on caret line' underneath the 'Strip trailing spaces on Save' option


I, too, discovered my issue, but it was not the fix Wayne offered. After digging through other editor options I found a language-specific option (PHP in my case) in "Default Settings" at Default Settings >> Editor >> Code Style >> PHP >> Tabs and Indents (tab) >> "Keep Indents on Empty Lines" (check box). After unchecking "Keep Indents on Empty Lines", my problem was solved.


Hope this helps!


Jake! Thank you very much! This is answer on the topic. I puzzled why it works fine for me on Windows and does not work on OS X.

And the reason is the checkbox in code style for particular language.

I really appreciate your help!


I'm having this trouble with trailing spaces in docstrings. I understand that spacing in string literals need to be kept, but could we have an option to strip trailing spaces in docstrings, where trailing spacing is undesirable? 


Yes please add an option to remove trailing spaces in Python docstrings. It used to work with old PyCharm versions but the latest version does no longer strip all trailing white spaces in docstrings. It is extremely disruptive to be honest.


I had this issue and I fixed it on Preferences|Editor|Code Style|JavaScript <—here you choose the language you are using. There is a checkbox: Keep Indents On Empty Lines. For no reason I checked that checkbox and unchecked it again, clicked on Apply and then it magically worked. If you want to see the whitespace go to Editor|General|Appearance| and check Show Whitespaces. Create a whitespace anywhere and hit save you will see how whitespace is remove. The thing is that you have to move the caret to any other line and not keep it in the same line where you created whitespace.


This option seems to be unavailable for C# in Rider.


Have tried all of these steps, but still doesn't work for me on OSX.

What did work was disabling "settings may be overridden by EditorConfig"


Rich Burdon Do you mind sharing where you found the "settings may be overridden by EditorConfig" checkbox?


I get stuck with this every time I set up a new machine -- seeing my own post above from last year -- but that doesn't seem to work now.


Still don't see that checkbox -- or anything below "Detect and use existing file indents"


@Rich Burdon

If your question is the same as OP, please look in [File | Settings | Editor | General >> Save Files]


It's 2020 and the issue still occurs
solution provided by Marcelo Retana works, thx, Jetbrains pls fix this issue!


Yeah, I don't know if this was previously reported as a bug but I've just done so:


Please sign in to leave a comment.