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.

11 comments

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.

http://www.jetbrains.com/

"Develop with Pleasure!"

2

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

I've created this video documenting my problem: https://www.youtube.com/watch?v=QgSpKoErotA&feature=youtu.be

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

Thank you for any help,

Max

 

2

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"

3

This is an issue for me too

1

+1 I, too, am having this issue.

0

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

4

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!

9

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!

1

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? 

2

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.

12

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.

0

Please sign in to leave a comment.