Sublime Text Tab Width: How to Set It
In this article
This guide shows you how to change the number of spaces a tab key inserts in Sublime Text, and how to make that setting apply to all files or just specific file types. You'll also learn how to control whether Sublime Text converts tabs to spaces automatically. No prior configuration is needed—just have Sublime Text open.
What You'll Need
- Sublime Text installed (any recent version, including Sublime Text 3 or 4).
- A file open in Sublime Text (or the ability to create a new one).
Step-by-Step
- Open Sublime Text and load a file (or create a new one) where you want to change the tab width.
- Look at the status bar at the bottom of the window. You'll see something like Spaces: 4 or Tab Width: 4 (the exact label may vary by version). This shows the current setting.
- Click on that status bar label. A small menu will pop up with options: 1, 2, 3, 4, 5, 6, 7, 8, and also Indent Using Spaces and Indent Using Tabs.
- Select a number (e.g., 2 or 4) to set the tab width for the current file. This changes how many spaces a tab character occupies when you press the Tab key, and also how many spaces are inserted when you indent a line.
- Optional: Set the indent style. In the same popup, choose Indent Using Spaces if you want the Tab key to insert actual space characters, or Indent Using Tabs if you want it to insert a tab character (which will display as the width you set).
- To change the default for all files: Go to the menu bar and select Preferences → Settings (or Sublime Text → Preferences → Settings on macOS). This opens two files side by side: the default settings on the left and your user settings on the right.
- In the user settings file (the one on the right), add the following lines (if they're not already there):
{ "tab_size": 4, "translate_tabs_to_spaces": true }Replace4with your preferred number. Thetranslate_tabs_to_spacessetting, whentrue, makes Tab insert spaces; whenfalse, it inserts a tab character. - Save the settings file (Ctrl+S on Windows/Linux, Cmd+S on macOS). The new default will apply to all new files and any file that hasn't been individually overridden.
- To set tab width per file type: For example, to make Python files always use 4 spaces, create a file named
Python.sublime-settingsin yourPackages/Userfolder. The easiest way is to use the menu: Preferences → Settings – Syntax Specific. This opens a settings file for the current syntax (e.g., Python). Add the same JSON lines there. - To apply the new tab width to an existing file's indentation: After changing the setting, select all (Ctrl+A or Cmd+A), then go to Edit → Line → Reindent. This will re-indent the entire file using the new tab width and indent style.
Common Mistakes
- Changing the setting in the default settings file (the left pane) instead of the user settings. It's not recommended to edit the default file; use the user file.
- Forgetting to save the settings file after editing. If you close without saving, your changes are lost.
- Setting tab width but not translate_tabs_to_spaces—if you leave translate_tabs_to_spaces as false, pressing Tab will insert a tab character, which may look different in other editors.
- Expecting the change to affect files that already have indentation—you need to reindent them manually.
Tips
- Use spaces for most languages—especially Python, where mixing tabs and spaces causes errors. Set
translate_tabs_to_spacestotrue. - Set per-syntax settings for different languages. For example, you might want 2 spaces for JavaScript and 4 for Python.
- Use the status bar to quickly check the current tab width—it's always visible at the bottom.
- If you work with multiple projects, consider using project-specific settings by adding a
settingsblock to your project file (e.g.,test.sublime-project). - Keyboard shortcut: You can also press
Ctrl+Shift+P(orCmd+Shift+Pon macOS) to open the command palette and type “Indent Using Spaces” or “Tab Width” to change settings quickly.
Troubleshooting
Why doesn't the change take effect? Make sure you saved the settings file. Also, if you're editing a file that already has its own indentation, you may need to reindent it (Edit → Line → Reindent).
The status bar doesn't show “Spaces” or “Tab Width”. In some versions, the status bar may be hidden. Go to View → Show Status Bar to enable it.
My Tab key still inserts a tab character even though I set translate_tabs_to_spaces to true. Check if you have a syntax-specific setting that overrides the global one. Also, make sure you didn't accidentally set translate_tabs_to_spaces to false in a project settings file.
I can't find the user settings file. The path is typically Packages/User/Preferences.sublime-settings. You can open it via Preferences → Settings—the right pane is your user file.
Reindent doesn't work as expected. It only works on selected text, so select all first. Also, it may not fix mixed tabs and spaces perfectly; you might need to use a tool like “Expand Tabs to Spaces” (found in the Command Palette under “Tabs: Expand Tabs to Spaces”).
Frequently Asked Questions
Can I set a different tab width for each file type?
Yes, use Preferences → Settings – Syntax Specific to create a settings file for the current syntax (e.g., Python.sublime-settings).
What's the difference between tab width and indent width?
In Sublime Text, tab width is the same as indent width—it controls how many spaces a tab or an indent level occupies. There's no separate indent width setting.
How do I make Sublime Text show tabs as spaces visually?
Set translate_tabs_to_spaces to true so that pressing Tab inserts spaces. To convert existing tabs to spaces, select all and use Edit → Line → Reindent or the command palette “Tabs: Expand Tabs to Spaces”.
Will changing the tab width affect the file's content?
Yes, if you change the setting and then reindent, the actual characters (spaces or tabs) in the file will change. If you only change the setting without reindenting, the visual display may change, but the file content stays the same.
What is the default tab width in Sublime Text?
The default is 4 spaces, with translate_tabs_to_spaces set to false (meaning it inserts tab characters).
Can I set tab width per project?
Yes, open your project file (.sublime-project) and add a settings section with "tab_size": 2 and other options.