Emacs: converting existing tabs to spaces

So you already know to use spaces instead of tabs for indenting. But what about those files that already have them? Here’s how to untabify an entire file at once. Note that you’ll still have to align anything that is out of whack because of the old tabs, but at least they’ll be spaces now.

  1. Go to the start of the file: M-<
  2. Start buffer selection: C-x h
  3. Mark the entire buffer: M-x mark-whole-buffer
  4. Convert tabs to spaces in the selected region: M-x untabify

You can do a partial region with this command too, just select a smaller region instead of the whole file.