sponsor Vim development Vim logo Vim Book Ad

basic Tip #1487: Spaces are my enemies..

 tip karma   Rating 21/44, Viewed by 3542 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   January 23, 2007 23:43      complexity:   basic
author:   iGeek      as of Vim:   6.0

I have this document filled up with spaces, as lines, and blanks at the end of each line.

Eliminate empty lines: v/\S/d
Eliminate spaces at the beginning of each line: %s/\s\+$//
Eliminate spaces at the end of the each line:%s/\s\+$//

 rate this tip  Life Changing Helpful Unfulfilling 

<< change the pink omnicomplete popup to a readable color | Bookmark files >>

Additional Notes

Anonymous, January 27, 2007 4:04
Is there any way to edit the tip,  I want to edit the beginning of line part..
salmanhalim@hotmail.com, January 24, 2007 21:47
The beginning pattern probably should be different from the ending one; remove the $.
Anonymous, January 24, 2007 23:09
It should be:

Eliminate spaces at the beginning of each line: %s/^\s\+//
stATistic.org, January 26, 2007 1:30
In addition, people who are doing lots of editing where spaces are important should read the help for the 'list' option. It displays $ at eol, ^I for tabs, and such. You can configure what characters it uses with 'listchars'.
stATistic.org, January 25, 2007 5:57
Just in case anyone is confused by the above, all of the suggested commands are : commands, not normal-mode keybindings. So you should do :%s/patterns// and :v/\S/d (note the leading colons). Missing the colons off would have hilarious consequences.
Anonymous, January 29, 2007 6:31
At this time, I do not believe there is a way to edit your tip.

Just make a comment to the tip.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo