:%s/[ ]*$//g
Why does the regular expression above squeeze >=1 spaces at the end of any line to exactly one but not 0 spaces?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your regex works. There are no spaces left at the end of the line after you run it.
What you probably see is the “residual” incremental highlighting that would go away if you used
:%s/[ ]\+$//g. — Note the\+instead of the*. the incremental highlighting remains because*always matches, even with zero spaces.To remove the highlighting, type
:noh(short for:nohlsearch).FYI:
:%s/[ ]*$//gis equivalent to:%s/ *$//g.