Eclipse global preferences

Eclipse is good, but like any other tool: it gets better after I have it customized for my special needs. Eclipse stores a lot of settings in the workspace, see my article about Copy my workspace settings. But is there a way to apply some settings to every workspace? At least to the new ones? Because importing/exporting the settings can get really tedious as I have many workspace.  And indeed, there are global settings in eclipse. And I want to have them changed…

Warning: changing eclipse global preferences might break an eclipse installation. So better have a backup of the changed files at hand!

I’m using here the eclipse based CodeWarrior for MCU10.2, but things are pretty much the same for any eclipse based product (see the documentation in Defining your own global preferences).

Question: where are the global preferences stored? The first thing to check is the eclipse\configuration\.settings folder: Here some plugins store their global preferences. For example: the recent workspace settings are in org.eclipse.ui.ide.prefs.

#Fri Apr 06 16:46:14 CEST 2012
RECENT_WORKSPACES_PROTOCOL=3
MAX_RECENT_WORKSPACES=10
SHOW_WORKSPACE_SELECTION_DIALOG=true
eclipse.preferences.version=1
RECENT_WORKSPACES=C\:\\tmp\\wsp_test\nC\:\\tmp\\wsp_10.2

But what about all the other settings? Looking at the CodeWarrior installation, inside the eclipse folder, I find the cwide.ini file.

cwide.ini file

cwide.ini file

This file defines the eclipse startup options for launching the IDE (cwide.exe for CodeWarrior). The interesting part is this line:

-Declipse.pluginCustomization=cwide.properties

This tells eclipse to use the cwide.properties as a default configuration file. If I inspect that file, it has the following content:

org.eclipse.debug.ui/org.eclipse.debug.ui.switch_perspective_on_suspend=always
org.eclipse.debug.ui/org.eclipse.debug.ui.switch_to_perspective=always
org.eclipse.ui.editors/spellingEngine=org.eclipse.cdt.internal.ui.text.spelling.CSpellingEngine

OK, that gives me an idea how settings could look like. But the question is: how to know the settings and syntax? What works (most of the time) is following approach:

  1. Launch eclipse with a new workspace
  2. Export the settings using File > Export > General > Preferences to a file
  3. Change the setting in Window > Preferences
  4. Export the settings using File > Export > General > Preferences  to a different file
  5. Compare/Inspect the exported information and find the settings
  6. Apply the settings to the cwide.properties file, without the /instance/ part
  7. Restart the IDE and check if it works with a new workspace

The last check is necessary as not all settings might work that way, see this forum post.

This is maybe best illustrated with an example. I have configured my workspace to use 2 for tab width and to insert spaces for tabs:

Changed Preferences for Tabs

Changed Preferences for Tabs

If I compare the two exported .epf files, this gives me:

Diffing Eclipse Preference Files

Diffing Eclipse Preference Files

That means the two following lines are configuring what I have changed:

/instance/org.eclipse.ui.editors/tabWidth=2
/instance/org.eclipse.ui.editors/spacesForTabs=true

For the cwide.properties file I need to cut off the /instance/ part, so I have this added to the cwide.properties:

# Set tab width to 2
org.eclipse.ui.editors/tabWidth=2
# Using spaces for tabs
org.eclipse.ui.editors/spacesForTabs=true

Note: Preferences are applied in following order: global preferences, then local (workspace) preferences

This does NOT overwrite an existing setting of my workspace. As I can see from above diff, my initial workspace settings do not have any settings for tabWidth and spacesForTabs. Creating a new workspace use and apply my new settings. But once I have the them, they will not be overwritten with new global ones. Which makes sense: the local settings are winning.

Note: Post a comment if you know an elegant way how to enforce/overwrite workspace settings with global ones.

Happy Changing 🙂

6 thoughts on “Eclipse global preferences

  1. Pingback: Customize my Workspace Perspectives | MCU on Eclipse

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.