ThingyMaJig

Thingy Ma Jig is the blog of Nicholas Thompson and contains any useful tips, sites and general blog-stuff which are considered interesting or handy!

Connect

LinkedIn GitHub

Topics

announcement 25 apache 3 Apple 1 bash 8 code 7 cool 30 Days Out 8 Dark Basic Pro 4 design 12 doctor who 1 Drupal 74 E4600 1 EOS 400D 3 firefox 2 Flickr 3 free 21 games 5 geek 38 git 2 GreaseMonkey 1 hardware 7 Homebrew 1 How to 37 humour 5 iphone 1 javascript 1 jquery 1 K800i 6 k850i 4 lighttpd 3 linux 33 mac 9 miscellaneous 4 mobile phone 9 music 4 mysql 8 n73 1 n95 1 New Relic 1 Ogre3D 1 OS X 2 performance 3 photos 10 programming 40 Quicksilver 1 review 19 security 3 SEO 6 software 12 svn 2 technology 4 tip 7 tips 10 tv 3 video 3 vim 7 webdev 2 websites 33 wii 1 windows 1 YADS 10

Removing trailing spaces with vim

Posted on 16 July 2008 in
vim linux Drupal

After recently reading about how great VIM is for the three hundredth and fifty second time (I kept count), I decided to take a look.

It really is quite cool! I've also decided to try to log any cool tips I learn about it. Here is the first which I found after running the coder module on one of my modules (Page Title 2) and it threw hundreds of errors about too many trailing spaces on empty lines.

How to clear trailing spaces using VIM

[adsense:468x60:4496506397]

After a bit of googling, it turned out to be REALLY easy!

:%s=\s\+$==

And thats it!

  • The % tells it to be global - not just the current line.
  • S is a shortcut for substitute.
  • The \s (whitespace) and \+ (at least once) are regular expression terms (the + needs to be escaped, it seems…).
  • The $ (dollar) represents the end of a line.
  • The = are being used as delimiters, the == at the end implies that the pattern is replaced with nothing.