Skip to content

Converting between tabs and whitespace

by mickey on December 2nd, 2010

It’s not an uncommon occurrence to find yourself editing a file that uses tabs instead of whitespaces, or vice versa. Thankfully, Emacs has facilities in place that make it possible to easily convert between tabs and spaces.

The commands tabify and untabify do just that; they convert the region to tabs or whitespaces. When you untabify or tabify, Emacs is smart enough to realign your code, so it should look the same after the replacement has taken place. When you use either command, the variable tab-width is also used to determine the indentation level.

One important point, though, is that tabify and untabify does not discriminate when it replaces tabs with spaces and vice versa, so that means tabs or whitespaces in strings may suffer. Be careful.

Share your thoughts

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS