Eclipse 语法突显首选项保存和恢复

我花了一些时间在 Eclipse 中定制语法突显的颜色(Java,JSP,HTML,CSS 等) ,但是每当我试图通过文件 | 导出 | 一般 | 首选项导出这些设置并重新导入它们时,这些设置从来没有被完全导入回来。一些颜色被恢复,另一些则保持不变,让我处于“中间”状态——非常令人沮丧。

顺便说一下,我用的是 Eclipse 3.4 Ganymede。

有人找到保存和恢复 Eclipse 语法突显设置的可靠方法吗?

58266 次浏览

I would export the preference before modifying the color, and then after.

That way, you would be able to isolate the specific rules of an eclipse preference file into one smaller file and:

  • check if some colors not restored are indeed represented by a rule
  • the import of a smaller preference has any effect on the previously unchanged settings.

That kind of strategy can be further refined into several small settings files (one for Java, one for JSP, HTML, CSS, ...), in order to better analyzing the potential side-effects when re-importing those settings.

I finally figured out how to do this.

I just wanted to mention beforehand that I did try to start with a fresh Eclipse install, export the preferences to a .epf file, change just one single setting, export again, and compare the files. To my surprise, trying to import settings from a minimal .epf file did not work reliably either.

The solution that worked for me was to copy these files: {Eclipse workspace directory}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs

I tried a fresh Eclipse install on another machine and after copying those files over, all my settings were restored perfectly.

I have deleted recently changed *.prefs file from the following dreictory \myworkspace.metadata.plugins\org.eclipse.core.runtime.settings\ and imported existing exported preference.

I am the first person, who answer for this question as per my knowledge :), Cause even I struggled lot.

Thanks

Eclipse CDT stores 'Syntax coloring' in the file org.eclipse.cdt.ui.prefs

This is located for example here: C:\eclipse\workspace.metadata.plugins\org.eclipse.core.runtime.settings\

Copy and paste over the top of the one in your new eclipse instance. This worked for me when moving from 3.4 to 3.5

I have had success in importing Eclipse Helios's syntax highlighting rules by copying the file:

.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs

from the source workspace to the target workspace. It seems this file also contains Eclipse's code formatter profiles and code templates.

Environment:

Version: Helios Release
Build id: 20100617-1415
(on linux)

The solution was to copy SOME - not all - of the files from {workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs into my other workspace.

In particular (per the https://stackoverflow.com/questions/96981/color-themes-for-eclipse thread):

org.eclipse.jdt.ui.prefs = Syntax Coloring
org.eclipse.ui.editors.prefs = Text Editors

Copying other files caused things to break.

There are a couple of notes to add:

  1. I had to copy the aforementioned pair of files several times before I got the correct syntax coloring.
  2. Be sure to close the workspace, if it's open in Eclipse, before copying the files.

This worked with Eclipse Helios.

If you want to be a little more fine grained on what you migrate, the syntax highlighting rules are the lines starting with semanticHighlighting on workspace-indigo/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs

Doing this, I was able to migrate my syntax highlighting from Helios to Indigo

I faced the same problem few days ago. The easiest way to restore the defaults is to import the default theme again, which you can find under: http://eclipsecolorthemes.org/?view=theme&id=790

Once Michael Bosworth's answer helped me to some extend and I voted up. But now I see some obligation to answer it myself, because copying these two files are not enough. Let me explain why.

  • First, these files contains lines irrevelente to syntax coloring.
  • Second, syntax coloring for other editors are located elsewhere, for example, those of XML files are in

    org.eclipse.wst.xml.ui.prefs

and those of HTML files:

    org.eclipse.wst.html.ui.prefs

JSP pages?

    org.eclipse.jst.jsp.ui.prefs

, etc.

  • Third, when we change font colors, usually we change background colors, line highlighting colors, etc. to get a clearer view of codes. This involves more files.

If we search *.pref files in path

/workspace/.metadata/.plugins

we can find all preferences files where we can locate all lines of coloring settings. But by copy-pasting all these files to another workspace can also trigger problems, for they are not exclusively syntax-coloring-related. Moreover, when we are switching between two versions of Eclipse, unexpected problems may arise.

So, the safest way is:

  • Create a new workspace if you don't have one.
  • Open all *.pref files we find in the workspace one by one,
  • Copy those lines containing color codes,
  • Find the same file in your new workspace,
  • Replace the color part by existing one. Or, set the colors in Eclipse, by assuming the corresponding options according to properties' name. All color codes are RGB based.

EDIT: (2017.02.24)

Eclipse Mars has a plugin Oomph, which can record your preference settings to provide seamless transmission of your preferences. When you activate it, every time you change a value, it prompts to ask you if you want to record it in Oomph, providing you the exact line in the corresponding file where your new value is stored. So, when you install Oomph, you can:

  1. Change the settings of your font face, font size, background color, etc.
  2. In the prompt windows of Oomph, take note of the location of your new settings. (Because if you tell Oomph to remember your settings, it will not prompt never again, so you may only see this windows once.)

I'm using JBoss Developer Studio 10 with the Eclipse Neon 4.6 engine.

All .prefs files are inside this path:

/workspace/.metadata/.plugins/org.eclipse.core.runtime/.sett‌​ings

Update: I found a similar structure on this path too:

\RedHat\JBossDev\studio\configuration\.settings

It's my IDE folder plus \configuration\.settings

I recommend search for org.eclipse.*ui*.prefs instead *.prefs to refine your result.

The principal config files are:

  • org.eclipse.jdt.ui.prefs
    • Java Syntax Color Settings
  • org.eclipse.ui.editors.prefs
    • Text Editor Settings
  • org.eclipse.cdt.ui.prefs
    • Formatter Settings
  • org.eclipse.wst.jsdt.ui.prefs
    • JavaScript Syntax Color Settings
  • org.eclipse.jst.jsp.ui.prefs
  • org.eclipse.wst.css.ui.prefs
  • org.eclipse.wst.html.ui.prefs
  • org.eclipse.wst.json.ui.prefs
  • org.eclipse.wst.dtd.ui.prefs
  • org.eclipse.wst.xml.ui.prefs
  • org.eclipse.wst.xsl.ui.prefs

If have a problematic workspace:

  1. Copy the files above
  2. Create a new workspace
  3. Copy and Replace that files in your new workspace

This will recover perfectly your custom editors color settings. For me worked very well.