Convert Tabs to Spaces Across Files in VS Code

Learn how to convert tabs to spaces across all files in a VS Code project, including editor settings, command palette actions, and search-and-replace workflows.

Define the alternatives

When you need consistent indentation across a project, VS Code gives you several ways to convert tabs to spaces. The choice depends on whether you are changing one file, many open files, or every file in a workspace or folder. This guide covers the practical workflows for converting tabs to spaces across files without inventing menu locations or measurements.

The main alternatives are: editor settings that control what happens when you type or format a file, the Convert Indentation to Spaces command for the active file, search-and-replace with regular expressions for many files, and formatter or extension settings that apply project-wide rules. Each approach affects different scopes: current file, open editors, search results, or all files matched by a search.

Compare meaningful differences

The editor setting for tab size and insert spaces controls new indentation and can be set per user or per workspace. In current versions of VS Code, you can use the command palette to run Convert Indentation to Spaces, which changes the active file's existing leading indentation. This command does not automatically walk every file in a folder, so it is not by itself a bulk conversion tool.

For bulk changes, the Find in Files view supports regular expressions. One common pattern is to search for a leading tab character and replace it with the number of spaces that matches your configured tab size. Because replacement behavior can vary with VS Code version and search settings, test the pattern on a small set of files first rather than assuming an exact result across every file type.

Formatters such as Prettier or language-specific extensions may also change indentation when you format documents. Their output depends on the formatter's own configuration and whether it is set as the default formatter. This can be convenient for supported file types, but it is not a guarantee for every file in a mixed project.

Practical trade-offs

Using the built-in command is safe and predictable for one file, but it requires repeating the action for each file unless you automate it through another workflow. Find and replace across files is fast and broad, but it can alter tab characters inside strings, templates, or data files if the pattern is too general. Version control history becomes important here: review the diff before committing a bulk indentation change.

Editor and formatter settings are better for preventing mixed indentation in future edits. They can enforce spaces during normal typing or formatting, but they may not retroactively convert existing files unless you run a format or conversion action. Some extensions offer project-wide conversion commands, but their behavior depends on the extension version and configuration, so verify what a specific command does in your environment.

Choose for the use case

If you are fixing a single file while working, run Convert Indentation to Spaces from the command palette. If you need to update a known group of files, use Find in Files with a carefully scoped search, apply the replacement to matching results, and inspect the changes. If you want to prevent tabs in new work, set the workspace preference to insert spaces and configure the formatter used by the project.

For a large mixed-language project, do not assume one button will safely convert all files. Start with a representative subset, confirm the result in the diff viewer, and then expand the change. If your project already has an agreed formatting tool, prefer its documented workspace settings over manual search patterns so that future formatting stays consistent.