Trailing Whitespaces Vim

Trailing whitespaces are a pain in the ass. Adding, deleting and modifying code can lead to invisible spaces at the end of the line. This is “bad” and useless.

Here comes Vim!

A substitution command :%s/<search>/<substitute>/
Where the search is for trailing whitespaces \s\+$ and the substitute is “nothing”.

Writing this every time is too much effort, it’s a good idea to define a user command:
:command Deltw :%s/\s\+$//

Or better, add the line to your vimrc file:
command Deltw :%s/\s\+$//

now just typing the command Deltw deletes those annoyances.


Vim patterns ⇒GO
Vim user_commands manual ⇒GO


Leave a comment

Filed under tips, vim

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s