Tuesday, January 20, 2009

Converting Tabs to Spaces

Here's a quick way to convert a tab-stopped file to a space-formatted file.

:set expandtab


Anonymous said...

Is there a built-in way (other than to search/replace groups of spaces) to convert n spaces into tabs?

Note: not interested in the ensuing flame war about using tabs vs. spaces.

rantingnerd said...

Last I looked, "retab" was what turned tabs into spaces.

:set noexpandtab

will turn spaces into tabs. (It's not perfect -- a single space won't be replaced with a tab even if it would match up with the tabstop -- but it's really useful.)

Me, I use 4-space "tabs". :-)