How to change indentation and tab size in VS Code
Codemia Knowledge Hub ·
Click the indentation indicator in the bottom-right status bar of VS Code (it reads something like Spaces: 4 or Tab Size: 2). From there you can switch between tabs and spaces, change the width, or convert the file's existing indentation. For defaults, set editor.tabSize and editor.insertSpaces in settings.json.
There are three separate things here: tabs vs spaces, the column width, and converting existing files. VS Code handles all three, but from different places.
Changing indentation for the current file
Click the Spaces: 4 indicator in the status bar to get:
- Indent Using Spaces: switch to spaces and choose a width.
- Indent Using Tabs: switch to tab characters and choose a display width.
- Convert Indentation to Spaces: rewrite existing tabs as spaces in this file.
- Convert Indentation to Tabs: rewrite existing spaces as tabs in this file.
The same commands are in the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) under "indentation":
"Indent Using" changes how new indentation is inserted. "Convert Indentation" rewrites the whitespace already in the file.
Default tab size in settings.json
| Setting | Effect |
editor.insertSpaces | true uses spaces, false uses tab characters |
editor.tabSize | Number of columns per indentation level |
editor.detectIndentation | When true, VS Code auto-detects from file content |
With editor.detectIndentation at true (the default), VS Code reads each file and overrides tabSize and insertSpaces to match it. That helps in mixed-style repositories but is confusing when you expect your settings to apply. Set it to false to make your settings win.
Per-language indentation
Python uses 4 spaces, many JavaScript style guides use 2, and Go uses tabs. Override per language:
Language settings override global ones but are overridden by .editorconfig and formatter extensions.
EditorConfig
Many projects ship an .editorconfig to keep formatting consistent across editors. VS Code respects it (with built-in support or the EditorConfig extension).
When present, .editorconfig beats settings.json, so project rules override personal preferences.
Formatters have the final word
Prettier, ESLint, Black or gofmt decide indentation when you save or format. With Prettier set to 2 spaces:
Prettier rewrites the file to 2 spaces on format, whatever VS Code says. The priority chain:
Most "my indentation keeps changing back" problems come from a forgotten formatter or .editorconfig.
Workspace vs user settings
- User Settings apply to all projects:
~/.config/Code/User/settings.json(Linux),~/Library/Application Support/Code/User/settings.json(macOS), or%APPDATA%\Code\User\settings.json(Windows). - Workspace Settings apply to the current project:
.vscode/settings.jsonin the project root.
Workspace settings override user settings. Commit .vscode/settings.json so the whole team gets the same indentation.
Indentation shortcuts
| Action | Windows/Linux | macOS |
| Indent | Tab | Tab |
| Outdent | Shift+Tab | Shift+Tab |
To fix indentation across a whole file after changing settings:
- Select all (
Ctrl+A/Cmd+A). - Open the Command Palette (
Ctrl+Shift+P/Cmd+Shift+P). - Run Format Document (if a formatter is installed) or Reindent Lines.
Converting many files at once
For a project-wide change (say, tabs to 2 spaces), the command line is faster than VS Code.
Using expand (Unix):
Using Prettier:
Why indentation does not change as expected
- Changing
editor.tabSizedoes not convert tabs. It only changes how tab characters display. Run "Convert Indentation to Spaces" to rewrite the file. - A formatter or
.editorconfigis enforcing a standard. Look for.editorconfig,.prettierrc,pyproject.tomlor similar before overriding. editor.detectIndentationis on. VS Code follows the file's existing style and silently ignores your defaults.- Mixed tabs and spaces get committed when teammates use different settings. An
.editorconfigor a pre-commit formatting hook prevents it.
Related reading
- How to change symbol for decimal point in double.ToString?
- How to change the color of progressbar in C .NET 3.5?
- How to change the color of winform DataGridview header?
- How to change the timeout on a .NET WebClient object
- How to change the value of attribute in appSettings section with Web.config transformation
- How to check if IEnumerable is null or empty?
- How to check if object has been disposed in C
- How to check if property setter is public

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.