Vim: Replace Tabs with Spaces

Where I work, some folks simply refuse to follow standards and use spaces instead of tabs in their code.  At first, this was, for me, merely an issue of aesthetics.  When using vim/vi, the tabs are displayed as ----> so that I more easily identify where tabs are lurking.  I could change that in my .vimrc config file, but I would rather know where they so that I can remove them.

Tabs, however, have a nasty habit of messing with JavaScript code, and I have experienced, from time to time, odd behaviour in python code as well.  Therefore, it is more than simple aesthetics that drives me to remove tabs from any file in which I find them.  Using a GUI client like Komodo, you can do a global search and replace on the tab, substituting it for four spaces (our standard).  No problem.  In vi, however, you have to use the \t , like so:

:%s/\t/    /g

I am not certain why it has taken me this long to use the replace function in vi to handle this task.  In the past, I would just leave the tabs in if I were editing a file in vi and came across the, or I would delete them if there were only a few. Now, however, I execute the search and replace every time.

0 Comments, 0 trackbacks (Trackback URL)

0 responses to Vim: Replace Tabs with Spaces

Leave a Comment
  1. (required)
  2. Ignore this field:
  3. Don't put anything in this field:
    Don't put anything here:
  4. Leave this empty:
    (required)
  5. Your email is not publically displayed.