Convert Tabs to Spaces in Eclipse

Learn how to convert tabs to spaces in Eclipse for a single file or an entire project, then verify the result and avoid common indentation problems.

Before you start

Eclipse performs this conversion locally in the editor and workspace. No web service or upload is required. Make sure the file is open in an Eclipse editor so the conversion command can apply to the selected text or the whole file.

Eclipse can convert indentation in an entire file by using the current editor, but the result depends on the project's text file and formatter settings. A project-wide cleanup can also convert tabs to spaces when the active formatter profile is configured for spaces.

Step-by-step instructions

To convert tabs in one open file, first make sure the file is shown in an Eclipse editor. If you want to change only part of the file, select that section; otherwise leave nothing selected to work with the complete file.

Use the editor command

Open the Source menu and look for a command that converts tabs to spaces. The wording may vary between Eclipse versions and language editors, but the action is usually reached through the Source menu in the Java editor rather than through a global Edit menu.

When Eclipse uses the project's formatter settings, the conversion may replace tabs according to the configured tab size. Check the formatter profile in the project properties if the result does not match the displayed indentation.

Set further files to use spaces

To keep new indentation consistent, open the relevant editor preferences or formatter profile and set the tab policy to use spaces only. In the Java formatter this is part of the indentation settings; for generic text files, display settings for tab width are separate from conversion.

You can run a source cleanup across a project, source folder, or package to replace tab indentation in multiple files. Use the Clean Up action with a profile that includes the tab-to-space correction, and review the profile before running it on shared code.

Check the output

Turn on whitespace display in the toolbar if you need visual confirmation. Tabs appear differently from spaces, making it easier to find remaining tab characters in the file or selected region.

For a stricter check, use the Find or Replace dialog with a regular expression that searches for a tab character. A zero-result search in the converted area indicates that Eclipse replaced the expected tabs.

Remember that some file types may be excluded from the editor command or formatter cleanup. Check the file's editor and project nature if the conversion appears to succeed but later searches still find tabs.

Common problems and next steps

The Source menu command is unavailable

The command is not available for every file type. Open the file with an editor that supports source actions, or use Find and Replace to insert spaces directly in plain text files.

The file still contains tabs after cleanup

Project cleanups depend on the selected profile. Confirm that the profile includes whitespace conversion and that the project is associated with the profile you edited. A global editor preference alone may not override a project formatter setting.

Indentation looks different after conversion

Tabs and spaces can render at different widths. Set the tab size and formatter indentation size to the same value, then run the conversion again so existing indentation matches the intended layout.

Keep the change reversible

Work on a local copy or use version control so the whitespace change can be reviewed separately. Avoid mixing large whitespace changes with functional edits in the same commit, because the whitespace-only diff is easier to evaluate.