Convert Tabs to Spaces in Sublime Text
Learn how to convert tabs to spaces in Sublime Text using built-in settings and commands, plus how to check the result and fix common indentation problems.
Before you start
Sublime Text converts indentation locally on your computer. You do not need a cloud service or an internet connection. You need a file open in Sublime Text, and the file should use an indentation style that the editor can detect or that you can set manually.
The conversion works on the current file or on a selected portion of it. It changes whitespace characters only. It does not change text, line breaks, or file encoding by itself, but saving the file writes the converted result to disk.
Step-by-step instructions
Open the file in Sublime Text. If you want to convert only part of the file, select that part first. If nothing is selected, the following commands apply to the whole file.
Open the View menu and choose Indentation. In the submenu, confirm or choose the number of spaces you want for each indentation level. Sublime Text commonly offers 2, 3, 4, and 8 spaces, depending on version and configuration. This sets the tab width used when converting.
If you also want new Tab key presses to insert spaces instead of tab characters, enable Indent Using Spaces in the same Indentation submenu. On some versions the submenu is available directly from the bottom status bar indentation indicator.
To convert existing tabs to spaces, open the View menu, choose Indentation, and select Convert Indentation to Spaces. Sublime Text replaces leading tab characters with the equivalent number of spaces based on the configured tab width.
If you only need spaces within a selected block, select the block first and run the same Convert Indentation to Spaces command. In many Sublime Text versions the command can also be run from the command palette.
Check the output
Turn on visible whitespace to inspect the result. You can find this option through the View menu or a command palette entry such as Toggle White Space. With whitespace visible, tabs typically appear as a marker or line, while spaces appear as dots.
Look at the indentation before the first non-whitespace character on several lines. They should now use spaces only. Lines that previously had different indentation depths should still be aligned to the correct number of levels.
Keep in mind that this command changes leading whitespace. Spaces that appear inside a line are not converted. If a file contains tab characters in the middle of a line, those remain untouched.
Common problems and next steps
If some tabs remain, the editor may have treated them as interior whitespace, or the command may have run on a selection that did not cover the whole file. Select the full file and run Convert Indentation to Spaces again.
If the indentation looks uneven, the original file may have mixed tabs and spaces, or it may use a different tab width than the one currently configured. Set the indentation width to match the intended level and run the conversion once more.
If you later open another file that uses tabs, that file is not changed automatically. Sublime Text can keep the file’s detected indentation or fall back to your configured default, depending on your settings.
For repeated work, check the indentation settings in your user preferences rather than adjusting the View menu each time. After changing indentation, save the file to keep the converted spaces.