Convert Tabs to Spaces in IntelliJ IDEA

Step-by-step instructions for converting tabs to spaces in IntelliJ IDEA, including editor settings, existing file conversion, and verification.

Before you start

IntelliJ IDEA handles tab-to-space conversion locally through its editor settings. You do not need a plugin or external service for the basic conversion. Make sure you know whether you want to change only the current file or apply indentation settings to the whole project. For existing files, conversion usually happens when you reformat code or run the explicit conversion action.

Step-by-step instructions

First, open the settings dialog. On Windows or Linux, choose File, then Settings. On macOS, choose IntelliJ IDEA, then Settings, or use the keyboard shortcut Command plus comma.

Go to Editor, then Code Style. Select the language or code style that applies to your file, such as Java, Kotlin, Python, JavaScript, or another language listed in the Code Style section. In some versions, you can also select the general code style for a project.

Open the Tabs and Indents tab. Find the setting called Use tab character. Clear this checkbox so IntelliJ IDEA uses spaces instead of tabs when indenting code. Set the Tab size and Indent fields to the number of spaces you want for each indentation level. Many projects use four spaces, but the correct value should match the coding standard for your project.

Apply the setting and close the dialog. This controls new indentation and formatting, but it does not automatically replace every existing tab in a file by itself.

To convert existing tabs in an open file, reformat the file. From the Code menu, choose Reformat File. IntelliJ IDEA will apply the current code style settings to the file. Depending on your settings and file type, this can replace indentation tabs with spaces throughout the file.

A more targeted option is to select the text you want to change, open the Edit menu, choose Convert Indents, and then choose To Spaces. This action converts indentation in the selected lines. If no text is selected, the action may apply to the current file, but the exact behavior can vary by version, so check only the lines you intended to change.

If you want to convert tabs in multiple files at once, make sure the relevant files are part of the current project and that the project code style is set to use spaces. Use the Reformat Code action for a wider scope, or run a code cleanup if your IntelliJ IDEA edition includes it. Review the affected scope before running a bulk operation.

Check the output

After conversion, visually inspect indented lines to confirm that leading whitespace is spaces. You can make whitespace visible by opening the View menu, selecting Active Editor, and choosing Show Whitespace, or by using the equivalent option in your version. Spaces typically appear as small dots, while tabs use a different marker.

If your file is stored in a plain text format, you can also open it in another editor that displays whitespace. Keep in mind that conversion affects indentation, not every whitespace character. Spaces inside strings or other content are not tabs and should not be changed by these actions.

Check the project configuration after conversion. The editor setting should show that Use tab character is off, and the Indent value should match the expected number of spaces. If you converted a file manually, repeat the check after a reformat to make sure the setting remains active.

Common problems and next steps

If reformatting does not replace existing tabs, confirm that the correct code style scheme is selected for the file. A file can use a different language setting or a project-specific scheme. IntelliJ IDEA also uses indentation detection when you open a file, which can influence how editing behaves. If the file still seems to contain tabs, use Show Whitespace to identify the exact lines.

When you select Convert Indents and choose To Spaces, the action targets the indentation portion of lines. Lines with tabs in other positions may need additional cleanup. Make sure you have selected the intended range before running it if your version supports selection-based conversion.

For team projects, align the code style settings with the shared project configuration. If the project uses an EditorConfig file, its indentation settings may override or interact with the IDE settings. Check whether the file specifies indent_style and indent_size; if it does, keep those values consistent with the IntelliJ IDEA code style tab.

Finally, test the change on one file before bulk reformatting many files. Compare the file in version control to verify that only intended whitespace changed. If the result is not as expected, reopen the Tabs and Indents settings and repeat the conversion. The process is reversible only if you have a backup or version history, so it is safer to keep the change narrow until the result is confirmed.