Yueseryueser.com

← All guides

Tabs to Spaces: Lining Up Columns Copied from Excel

Text copied from Notepad, Excel, or a terminal contains tabs you cannot see but which control alignment. Converting each tab to four spaces leaves everything else alone, and columns line up again in a monospace font.

Open the tool:Tabs to Spaces

When tabs need to become spaces

Copy a few columns out of Excel into a Markdown table or a code comment and the tabs are rendered at different widths in different apps, so the result collapses or jumps far to the right. Spaces have a fixed width, so the columns finally line up in a monospace font.

Terminal output, old project files, and configs written in Windows Notepad often indent with tabs too. Pasted into GitHub, an online editor, or a chat window, a tab may render as one space or eight, and the layout falls apart in a way that looks like a formatting bug.

How to convert without breaking alignment

Each tab is replaced with exactly four spaces, regardless of your editor's tab-width setting. If you indent with two spaces, replace each run of four spaces with two afterwards, or use your editor's indent conversion. Do not expect this tool to read your preferences.

Replacement is character by character, so tabs at the start, middle, and end of a line are all converted, and two consecutive tabs become eight spaces. If the original aligned columns by jumping to fixed tab stops, four spaces per tab may still not line the columns up; fix that in the target editor.

Where it stops, and what to use instead

It only substitutes characters. It does not convert indentation levels or format code. To standardise indentation to a language's convention, an editor formatter or a tool such as gofmt or prettier is far more reliable than a text substitution.

The reverse also matters: some targets require tabs, and a Makefile will actually fail if its recipe lines use spaces. In those cases change the editor's display width rather than the file content, or the build breaks for a reason that is hard to spot.

FAQ

Why four spaces, and can I get two?

The replacement is fixed at four spaces and has nothing to do with your editor's tab-width setting. If you indent with two spaces, replace each run of four spaces with two afterwards, or use your editor's indent conversion.

How is this different from just deleting tabs?

Deleting removes the character and glues neighbouring text together, while replacing keeps the gap so columns still line up in a monospace font. Use this one when structure matters, and the delete tool when you just want the text joined.

The columns still do not line up after converting. Why?

Because the original alignment came from jumping to fixed tab stops rather than a fixed width. Expanding tabs to four spaces moves each column's starting point. Re-split the data in a spreadsheet, or pad with spaces by hand.

Related tool:Tabs to Spaces