eclipse - working - replace all tab characters in this file by sequences of white-spaces sonarqube




How do I change Eclipse to use spaces instead of tabs? (14)

Java Editor

  1. Click Window » Preferences
  2. Expand Java » Code Style
  3. Click Formatter
  4. Click the Edit button
  5. Click the Indentation tab
  6. Under General Settings, set Tab policy to: Spaces only
  7. Click OK ad nauseam to apply the changes.

[Note: If necessary save profile with a new name as the default profile cannot be overwritten.]

Default Text Editor

Before version 3.6:

Window->Preferences->Editors->Text Editors->Insert spaces for tabs

Version 3.6 and later:

  1. Click Window » Preferences
  2. Expand General » Editors
  3. Click Text Editors
  4. Check Insert spaces for tabs
  5. Click OK ad nauseam to apply the changes.

Note that the default text editor is used as the basis for many non-Java editors in Eclipse. It's astonishing that this setting wasn't available until 3.3.

C / C++

  1. Click Window » Preferences
  2. Expand C/C++ » Code Style
  3. Click Formatter
  4. Click the New button to create a new profile, then OK to continue
  5. Click the Indentation tab
  6. Under General Settings, set Tab policy to: Spaces only
  7. Click OK ad nauseam to apply the changes.

HTML

  1. Click Window » Preferences
  2. Expand Web » HTML Files
  3. Click Editor
  4. Under Formatting, select the Indent using spaces radio button
  5. Click OK to apply the changes.

CSS

Follow the same instructions for HTML, but select CSS Files instead of HTML Files.

JSP

By default, JSP files follow the formatting preferences for HTML Files.

XML

XML files spacing is configured in Preferences.

  1. Click Window » Preferences
  2. Expand XML » XML Files
  3. Click Editor
  4. Select Indent using spaces
  5. You can specify the Indentation size if needed: number of spaces to indent.

By default Eclipse indents with a hard tab character. How do I change it to spaces?


Eclipse IDE for C/C++ Developers, Version: Helios Service Release 2

You need to create new profile by pressing New button inside "Window->Preferences->Code Style"

Go to Indentation tab and select "Tab policy = Space only"


Eclipse IDE for C/C++ Developers, Version: Kepler Service Release 1

Follow the path below to create new profile: "Window > Preferences > C/C++ > Code Style > Formatter"

Go to Indentation tab and select "Tab policy = Space only"



And don't forget the ANT editor

For some reason Ant Editor does not show up in the search results for 'tab' or 'spaces' so can be missed.

Under Windows > Preferences

  • Ant > Editor > Formatter > Tab size: (set to 4)
  • Ant > Editor > Formatter > Use tab character instead of spaces (uncheck it)

Be sure to check the java formater since it overwrites the "insert spaces for tabs" setting. Go to:

Java->Code Style"->Formatter->Edit->Identation

Note: you will need to create a custom format to be able to save your configuration.


Don't miss Tab policy for both of * Spaces only * Use spaces to indent wrapped lines

I checked only the latter thing and left the Combobox as Tabs Only which kept failing CheckStyle.. FYI, I'm talking about Preferences > Java > Formatter > Edit...


For the default text editor:

  • General > Editors > Text Editors > Insert spaces for tabs (check it)

For PHP:

  • PHP > Code Style > Formatter > Tab policy (choose "spaces")
  • PHP > Code Style > Formatter > Indentation size (set to 4)

For CSS:

  • Web > CSS > Editor > Indent using spaces (select it)
  • Web > CSS > Editor > Indentation size (set to 4)

For HTML:

  • Web > HTML > Editor > Indent using spaces (select it)
  • Web > HTML > Editor > Indentation size (set to 4)

For XML:

  • XML > XML Files > Editor > Indent using spaces (select it)
  • XML > XML Files > Editor > Indentation size (set to 4)

For Javascript:

  • Javascript > Preferences > Code Style > Formatter > Edit > Indentation (choose "spaces only")
  • Rename the formatter settings profile to save it

For Java:

  • Java > Preferences > Code Style > Formatter > Edit > Indentation (choose "spaces only")
  • Rename the formatter settings profile to save it


I found the solution this problem very simple and which works always. It is change the eclipse setting file.

For example (change HTML indentation size):

  1. Found org.eclipse.wst.html.core.prefs file which should be in your_workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/
  2. Add/Change to line in file:

    indentationChar=space

    indentationSize=4


In Eclipse go to Window->Preferences then search for Formatter.

You will see various bold links, click on each bold link and set it to use spaces instead of tabs.

In the java formatter link, you have to edit the profile and select the tab policy, spaces only in indentation tab


Just a quick tip for people stumbling across this thread; there is one more place where this setting can also be set, in your project!

Eclipse supports project-specific settings, and some projects will use their own, un-managed tabs/spaces settings, which won't show up anywhere except the current project Properties.

This can be managed through:

  • Right-Click current Project in Package Explorer;
  • Properties -> Java Code Style
  • Turn off all the project-specific options

This will generally only be an issue if you import someone else's code into your Eclipse.


When I faced this problem I had "use spaces for tabs" set to true everywhere I could find, and yet I was still getting tabs. It ended up being because tabs were used elsewhere in the file and it was trying to do smart indentation or something frustrating.

It was resolved by selecting the entire contents of the file and pressing, on a mac, command+shift+f. This applies the given formatting to a file. I do not know the same keybinding on windows, but give that a try. At that point I begin getting the expected behavior.


in eclipse format xml : for tab :

<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="tab"/>

for space:

<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>

  • Click Window » Preferences
  • Expand Java » Code Style
  • Click Formatter
  • click new
  • Select the profile name
  • Click ok
  • Click the Edit button
  • Click the Indentation tab
  • Under General Settings, set Tab policy to: Spaces only
  • Click OK.




whitespace