Tip of the day: Vim command to replace tabs with spaces   15 Nov 2010

As I am coding in Python, I had to use 4 space characters as delimiters to group statements or expressions which belong to the same block. This is the way Python behaves instead of grouping in curly braces like Java for example. Sometimes I observe files, where I had used tabs instead of 4 spaces by mistake. In most of the cases this is happening if I you do not use a "smart" editor which can automatically replace tabs to 4 spaces and you have forgotten it :p.

So if you use "vim" the command to replace the tabs with 4 spaces is the following:

:%s/\t/    /g

This will replace the tabs everywhere in the line and text. Even better, if you only want to update the spaces at the beginning of each line:

:%s/^\t/    /g