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!
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.
This file defines the eclipse startup options for launching the IDE (cwide.exe for CodeWarrior). The interesting part is this line:
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:
- Launch eclipse with a new workspace
- Export the settings using File > Export > General > Preferences to a file
- Change the setting in Window > Preferences
- Export the settings using File > Export > General > Preferences to a different file
- Compare/Inspect the exported information and find the settings
- Apply the settings to the cwide.properties file, without the /instance/ part
- 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:
If I compare the two exported .epf files, this gives me:
That means the two following lines are configuring what I have changed:
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.