How to Convert Tabs to Spaces in VS Code

Learn how to convert tabs to spaces in Visual Studio Code, change indentation settings, and convert existing files without changing your workflow.

Define the alternatives

VS Code can handle indentation in two ways: tab characters or space characters. Converting tabs to spaces usually means changing how new indentation is inserted, changing an existing file, or both. Before changing anything, decide which case applies. If you only want future edits to use spaces, change the editor settings. If you need an already written file cleaned up, also run a conversion command on that file.

The intended use matters because some projects require spaces for consistency. YAML files, for example, can be sensitive to mixed indentation. A camera or media tool project may include configuration files, scripts, or caption data where indentation errors make the file harder to read or process. Converting to spaces should not be treated as formatting the entire file; it only affects indentation at the start of lines.

Compare meaningful differences

VS Code separates per-editor behavior from per-file detection. The editor setting controls what happens when you press Tab or use indentation commands. A separate setting controls how many spaces equal one tab when indentation is inserted. The exact names and defaults can depend on the installed VS Code version, so verify what the current version shows instead of assuming an older menu path.

A file can also have its own detected indentation. If you change the global editor to spaces, an open file may still be treated as tab-indented because VS Code detected tabs in it. This is why a settings change alone does not always appear to work. The status bar can show the current indentation for the active file, and the language-specific display may differ from the detected file indentation.

Existing indentation is converted separately from typing behavior. The conversion command that replaces indentation is available through the command palette or an indentation menu. It changes the leading indentation of the document but does not reformat code, normalize blank lines, or modify spaces used for alignment inside a line.

Practical trade-offs

Using spaces makes indentation look the same across editors and viewers, which is useful when sharing scripts or configuration with a team. The trade-off is that files can become larger because a tab is replaced by several spaces. For small media tool configuration files this is rarely significant, but for large generated files it can change file size.

Mixed indentation is the main risk. If some lines contain tabs and others contain spaces, a file can look correct in one editor and shift elsewhere. VS Code can show or highlight whitespace, which helps you check for remaining tabs. Do not rely on the file looking correct after conversion if it already contained inconsistent indentation.

Published defaults and user-reported behavior should not be confused with measured performance. VS Code documents its indentation controls, but responsiveness or conversion speed on a very large file is not a fixed specification. The practical difference is usually workflow, not processing power.

Choose for the use case

If the project convention requires spaces, start by setting the editor to insert spaces for the relevant language or workspace. Then check the active file indentation and run the conversion command on the document. This covers both future edits and the current file.

If you only need to inspect or occasionally edit a file, converting the active document may be enough. Use the indentation menu available for the file and choose the conversion option that targets tab indentation. Confirm afterward that the file still opens in the tool that consumes it, especially if it is a script, configuration file, or caption dataset.

For workspaces with multiple file types, avoid applying one indentation choice to every language automatically. A JSON or Python project may need spaces, while another file type may have its own convention. VS Code allows indentation settings to be scoped, so prefer a workspace or language setting over a broad global change when the project is shared.