Configure editor to remove whitespaces in blank lines

Answered

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

20 comments
Comment actions Permalink

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!"

7
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

This is an issue for me too

1
Comment actions Permalink

+1 I, too, am having this issue.

0
Comment actions Permalink

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

5
Comment actions Permalink

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!

13
Comment actions Permalink

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
Comment actions Permalink

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
Comment actions Permalink

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.

13
Comment actions Permalink

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.

5
Comment actions Permalink

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

5
Comment actions Permalink

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"

0
Comment actions Permalink

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

0
Comment actions Permalink

@Rand Voorhies

 

0
Comment actions Permalink

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.

0
Comment actions Permalink

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

0
Comment actions Permalink

@Rich Burdon

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

1
Comment actions Permalink

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

1
Comment actions Permalink

Yeah, I don't know if this was previously reported as a bug but I've just done so: https://youtrack.jetbrains.com/issue/IDEA-272196

0

Please sign in to leave a comment.