Convert Tabs to Spaces in PhpStorm
Learn how to convert tabs to spaces in PhpStorm, apply indentation settings to a file, and avoid mixed indentation problems.
Before you start
PhpStorm can convert existing tab characters to spaces in the file you are editing. The conversion happens locally and does not require an online service or account. You only need a file open in the editor and, for full-file changes, the file must be editable rather than opened in a read-only state.
Check which indentation style the project should use before converting. A project may already configure indentation in its code style settings, but converting an individual file can override the appearance of that file if its own indentation settings differ.
Step-by-step instructions
The most direct way to replace existing tabs in a file is to use the conversion action in the Edit menu.
- Open the file in the PhpStorm editor.
- Go to Edit in the main menu.
- Choose Convert Indents.
- Select To Spaces.
- Save the file if the indentation change is correct.
This action works on the current selection if text is selected. When nothing is selected, it is intended to convert indentation throughout the current file. The number of spaces used for each tab is taken from the configured indent size for that file type.
To control future indentation, open the code style settings for the applicable language and set the tab and indent properties. In the same section, select the option to use spaces instead of tabs. This changes how new lines are formatted but does not by itself rewrite existing lines.
Check the output
After the conversion, move the cursor through previously indented lines and check that alignment looks stable. You can make whitespace visible in PhpStorm so that spaces appear as small dots and any remaining tabs appear as a different marker. This is useful for confirming that the file no longer contains tab characters.
Keep in mind that conversion changes indentation width for the affected lines. If a file previously mixed tabs and spaces, converted lines may now align consistently, but surrounding code that was already written with a different indent size may still look uneven.
Common problems and next steps
If the Convert Indents action appears unavailable, the file may be read-only, or the editor may not recognize the file type that owns the indentation settings. Unlock or check the file type first. In version-controlled files, review the diff before committing because an indentation conversion can create extensive changes even when the code content is identical.
If only part of a file should change, select the target lines before opening the menu. The action then limits its effect to the selection. When a project uses tabs elsewhere, converting only one file can create inconsistency across the codebase; in that case, agree on the project indentation convention before applying a broad replacement.
In older versions of PhpStorm the command may be labelled differently or may be available under a different indentation action. If you cannot find Convert Indents, check the editor context menu or the documentation for the installed version. Avoid applying a bulk find-and-replace for tab characters as a first choice because it may also change tabs inside strings or other non-indentation content.