Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:%s/\s+$// incorrectly removes empty lines #889

Open
jpiche opened this issue Nov 21, 2015 · 4 comments
Open

:%s/\s+$// incorrectly removes empty lines #889

jpiche opened this issue Nov 21, 2015 · 4 comments

Comments

@jpiche
Copy link

jpiche commented Nov 21, 2015

The command :%s/\s+$// is a common one for removing trailing whitespace from lines. Without the % range, :s/\s+$// works correctly on a single line, but with the % range (or 1,$) the expression incorrectly removes blank lines.

For example, running the command against the following (Github is removing whitespace :-/, hence the \ss instead of real spaces)

var a = 0
\s\s\s\s
var b = 1

should result in

var a = 0

var b = 1

but instead results in

var a = 0
var b = 1

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@squarefrog
Copy link
Contributor

Do you feel up to writing a test case for this to make it easier to fix?

@pebble8888
Copy link
Member

\s includes \n on ICU regular expressions.

Match a white space character. White space is defined as [\t\n\f\r\p{Z}].

http://userguide.icu-project.org/strings/regexp

So try to use this instead.
:s/[\u0020\t]+$//

@structAnkit
Copy link

I know this is a VIM-derived project but since it's a plugin for Xcode, have you considered setting your Xcode Editor options to remove trailing whitespace automatically?

@jpiche
Copy link
Author

jpiche commented Jan 19, 2016

@structAnkit, the remove trailing whitespace feature of Xcode doesn't always work correctly, but even if it did, :%s/\s+$// still doesn't work as Vim does. Though @pebble8888's comment seems to explain why, and using :%s/[ \t]+$// did work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants