Sometimes, the source code needs to replace tabs with spaces in eclipse. And eclipse uses tabs for spaces by default.

Tabs are always dependent on the environment and use 4 spaces in windows.

If you use source code written with tab spaces, code is consistent across different environments.

It is always recommended to use spaces for consistency.

These tutorials show how to convert tabs into spaces in Eclipse.

How to convert tabs to spaces in Eclipse

Following are steps by steps to convert tabs to spaces.

We have different editors in eclipse java, default and HTML editors, etc.

  • Open Eclipse

  • Select Windows Menu > Preferences , It opens Preferences popup window.

  • if you want to change the java editor, select Java, if it is following languages, The following are options - java editor - Select Java tab and Code Style - XML editor - Select XML tab and Code Style - HTML editor - Select Web tab and select HTML Files - C++/C editor - Select C/C++ tab and Code Style

    Below are steps for a java editor

  • Go to the Java tab Select Code Style and select the Formatter option

  • Click on the Edit button

  • It opens the profile settings window

  • Select the Indentation tab

  • Change the tab policy from Tabs Only to Spaces Only

  • Click on the ok button to save the changes.

  • Click on the Apply and Close button on the preferences window to close

Please see the screenshot.

Eclipse java editor convert tabs to spaces

Steps for Eclipse default editor

  • Open Windows > Preferences, Opens Preferences window
  • Select General > Editors > Text Editors
  • Check Insert Spaces for Tabs
  • Click on Apply and Close button on preferences window to close

How to replace tab spaces in eclipse Editor for a single file

Sometimes, You want to replace a tab with spaces or commas or a new line in a single file.

Here are steps

  • Open Eclipse and open source code file in the code editor

  • Go to Find/Replace Menu or use Ctrl + F

  • It shows popup dialog with Find and Replace with text boxes

  • Check Regular Expressions

  • to convert tab to spaces Provide the below values and Click the Replace or Replace All button Find:


Replace with

  • to convert tab to comma Provide the below values and Click the Replace or Replace All button Find what:

Replace with

  • to convert tab to comma Find what:

Replace with


Here are characters that you can use with replacing tab character

\b is a backspace character
\n\r is a new line with return end
\t is the tab character