How do I actually trim trailing whitespace?


I have tried the following:

1. "Strip trailing spaces on Save" = "All" and "Allow placement of caret after end of line" off.

- Doesn't work:

2. "Strip trailing spaces on Save" = "All" and "Allow placement of caret after end of line" on.

- Doesn't work, same as video above

3. Recording a macro to find `[ ]+$` and replace all

- Macro seems to use "replace" instead of "replace all", or maybe it didn't record that I selected "regex" checkbox

4. Configuring an "external tool" `sed -i '' -E 's/[ ]+$//g' $FilePath$`

- My sed command works on command line, fails in rubymine with:


/usr/bin/sed -i '' -E 's/[ ]+$//g' /Users/jared/redacted/
sed: 1: "'s/[": invalid command code '


Maybe rubymine is putting double quotes around the pattern parameter.

I've spent over an hour trying to get this simple feature to work, so please tell me there's a way to actually strip trailing whitespace in rubymine.

Screen Shot 2015-08-26 at 2.25.17 PM.png
Comment actions Permalink


for me both #1 and #2 works, to verify this I'd suggest to turn "show whitespace" option on (Settings|Editor|General|Appearance).
Also the problem can be caused by one of installed plugins.  I'm using markdown plugin from Jetbrains and everything works ok.

Hope this help, Oleg.

Comment actions Permalink

An extension indeed might cause a problem. I had to configure Vim Emulator Ctrl+S mapping in Rider to be handled by IDE instead of the extension.

Comment actions Permalink

The problem I'm having is that PyCharm does not remove trailing spaces inside a string. For example, I'll represent the trailing spaces with a ! :

def foo():

Here PyCharm removes the empty space above the def

def foo():
  a = '''
some text!!

Here PyCharm does not remove the spaces after 'some text'

Comment actions Permalink

Hey Francisco,

Why would PyCharm remove it?
Many people add spaces to the string intentionally and don't want them to be removed by IDE.

Consider the following example:

name = input('My name is: ')

Without additional space after the column it wouldn't look very nice to the user:

Comment actions Permalink

Hi Serguey, the problem only happens with multi-line strings. For example:

text = '''

If there are trailing spaces after foo, pyflakes will complain about trailing spaces

Comment actions Permalink

I think it's covered by the following feature request

Please upvote and feel free to leave comments.

Comment actions Permalink

Yes, I already voted for it. Although I think it's a bug, considering pyflakes sees this as an error.


Please sign in to leave a comment.