How do I actually trim trailing whitespace?

Answered

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: https://www.youtube.com/watch?v=mChERGVl9Xo&feature=youtu.be

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/README.md
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.



Attachment(s):
Screen Shot 2015-08-26 at 2.25.17 PM.png
7 comments
Comment actions Permalink

Hi,

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.

0
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.

0
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():
  pass

Here PyCharm removes the empty space above the def

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

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

0
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:

0
Comment actions Permalink

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

text = '''
foo   
'''


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

0
Comment actions Permalink

I think it's covered by the following feature request https://youtrack.jetbrains.com/issue/PY-23871

Please upvote and feel free to leave comments.

0
Comment actions Permalink

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

0

Please sign in to leave a comment.