FileGizmo Text tools
Convert tabs to spaces
Expand tabs to the next tab stop the way an editor does, or turn leading spaces back into tabs. Column-aware conversion for code and config files.
Complete
Your result is ready
Simple by design
Tabs to spaces in three steps
Converting tabs to spaces is the sort of task that looks like a search and replace and is not, and the difference shows up the moment a tab is not the first character on its line.
A tab does not mean a fixed number of spaces. It means advance to the next tab stop. With tab stops every four columns, a tab at the start of a line moves to column four, so it is worth four spaces. A tab after two characters only has to travel two columns to reach the same stop, so it is worth two. Replacing each tab with four spaces in both cases produces a file that disagrees with the original about where every subsequent column sits, and the misalignment compounds along the line.
That is not a subtle difference in a file where tabs are used for alignment rather than only for indentation, which describes a great deal of older code, most Makefiles, and every tab-separated data file. It is exactly the situation someone converts tabs in order to fix, so a converter that gets it wrong makes the problem worse while appearing to work.
FileGizmo expands tabs by tracking the column position along each line and inserting only as many spaces as are needed to reach the next stop, which is what every editor does. The width is yours to choose, from one to sixteen columns. Four is the common modern choice, two is common in web codebases, and eight is the traditional terminal default and the one that makes old files line up as their authors saw them.
Converting in the other direction is deliberately more conservative. Only leading whitespace is turned back into tabs. Spaces that appear inside a line are usually alignment that someone put exactly where they wanted it, often to line up a comment or a column of values, and replacing a run of them with a tab moves that text to wherever the reader’s tab stops happen to fall. The indentation at the start of a line is the part that is genuinely structural, so that is the part that is converted. Any remainder that does not fill a whole tab stop is left as spaces, which keeps mixed indentation aligned rather than rounding it.
The result reports how many lines changed and the tab stop width used, so a file that was already consistent says so. Everything runs in this tab.
- 1
Paste code a config file or a tab-separated list
- 2
Choose the direction and the tab stop width
- 3
Press Convert indentation and copy or download the result
Good to know
Frequently asked questions
Why is a tab not always the same number of spaces?
Because a tab advances to the next tab stop rather than inserting a fixed run. With a width of four, a tab after two characters is two spaces, not four. Every editor works this way.
Does converting back touch spaces inside a line?
No. Only leading whitespace is converted to tabs. Spaces inside a line are usually alignment somebody put there deliberately, and turning them into tabs would move the text.
What widths are supported?
Any tab stop from 1 to 16 columns. Four and two are the common choices for code, eight is the traditional terminal default.
Does it change anything other than whitespace?
No. Only tabs and leading spaces are affected. The characters of every line are otherwise untouched, including trailing whitespace.
Learn more