Vim: Replace tabs with spaces

When working in other peoples code I almost always notice mixed tabs and spaces. Like many programmers, this makes my skin crawl since it usually causes formatting to look horrible or incomprehensible.

First I'll double check that there are mixed tabs and spaces by highlighting the tabs.

If I see some whitespace highlighted and some not highlighted I'll look at the indentation and figure out how many spaces each tab should be, then do a replace. This will perform a replace on the entire file (%s) for all tabs (\t) into four spaces (\ \ \ \ ), the g at the end will allow the match to be done multiple times per line:
:%s/\t/\ \ \ \ /g

If your tab expand matches the file, you can also use the vim built-in retab:


Popular posts from this blog

XCode4: UITabBarController with UINavigationController using Interface Builder

Taking Stuff Apart: Sony TC-800B Portable Reel-to-Reel Recorder

Easy and accurate SVG to DXF conversion using Inkscape and pstoedit