Last Updated: February 25, 2016
·
1.084K
· bbolli

How to remove TABs from source files

I recently took over a C++ project that was indented inconsistently. Some lines had TABs, most had spaces; so I decided to remove all TABs from the files. vim to the rescue:

:args *.cpp *.h
:set tabstop=2 expandtab
:argdo retab | update

Done.

Explanation:

  • :args sets the file list to all source files I want to change
  • :set sets up the number of spaces I want to replace the TABs with
  • :argdo executes the retab and update (i.e. save if changed) commands for each file in the file list