Eclipse 语法高亮首选项保存和恢复

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/372837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 18:34:04  来源:igfitidea点击:

Eclipse syntax highlighting preferences save and restore

eclipseidesyntax-highlighting

提问by foxdonut

I spend some time customizing the colors for syntax highlighting in Eclipse (Java, JSP, HTML, CSS, etc.) but whenever I try to export these settings via File|Export|General|Preferences and reimport them, the settings never completely get imported back. Some colors are restored and others are left unchanged, leaving me in an 'in between' state - very frustrating.

我花了一些时间在 Eclipse(Java、JSP、HTML、CSS 等)中自定义语法突出显示的颜色,但是每当我尝试通过 File|Export|General|Preferences 导出这些设置并重新导入它们时,这些设置永远不会完全导入背部。一些颜色被恢复,而另一些颜色保持不变,让我处于“介于两者之间”的状态——非常令人沮丧。

I'm using Eclipse 3.4 Ganymede, by the way.

顺便说一下,我正在使用 Eclipse 3.4 Ganymede。

Has anyone found a reliable way to save and restore Eclipse syntax highlighting settings?

有没有人找到一种可靠的方法来保存和恢复 Eclipse 语法高亮设置?

回答by foxdonut

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 .epffile, change just one single setting, export again, and compare the files. To my surprise, trying to import settings from a minimal .epffile did not work reliably either.

我只是想事先提到,我确实尝试从全新的 Eclipse 安装开始,将首选项导出到.epf文件,仅更改一个设置,再次导出并比较文件。令我惊讶的是,尝试从最小.epf文件导入设置也不能可靠地工作。

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

对我有用的解决方案是复制这些文件: {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.

我在另一台机器上尝试了一个全新的 Eclipse 安装,在复制这些文件后,我的所有设置都完美地恢复了。

回答by Michael Bosworth

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

解决方案是将一些(而不是全部)文件从{workspace}/.metadata/.plugins/org.eclipse.core.runtime/.settings/*.prefs我的另一个工作区中复制。

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

特别是(根据https://stackoverflow.com/questions/96981/color-themes-for-eclipse线程):

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.
  1. 在获得正确的语法着色之前,我不得不多次复制上述文件对。
  2. 确保在复制文件之前关闭工作区(如果它在 Eclipse 中打开)。

This worked with Eclipse Helios.

这适用于 Eclipse Helios。

回答by Santino

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

如果您想对迁移的内容进行更细粒度的处理,语法突出显示规则是工作空间-indigo/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse 上以semanticHighlighting 开头的行.jdt.ui.prefs

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

这样做,我能够将我的语法突出显示从 Helios 迁移到 Indigo

回答by ?ɑ??????

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

我将 JBoss Developer Studio 10 与 Eclipse Neon 4.6 引擎一起使用。

All .prefsfiles are inside this path:

所有.prefs文件都在此路径中:

/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

更新:我在这条路径上也发现了类似的结构:

\RedHat\JBossDev\studio\configuration\.settings

这是我的 IDE 文件夹加上 \configuration\.settings

I recommend search for org.eclipse.*ui*.prefsinstead *.prefsto refine your result.

我建议org.eclipse.*ui*.prefs改为搜索*.prefs以优化您的结果。

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
  • org.eclipse。jdt.ui.prefs
    • Java 语法颜色设置
  • org.eclipse.ui。编辑器.prefs
    • 文本编辑器设置
  • org.eclipse。cdt.ui.prefs
    • 格式化程序设置
  • org.eclipse.wst。jsdt.ui.prefs
    • JavaScript 语法颜色设置
  • 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. Copythe files above
  2. Createa new workspace
  3. Copy and Replacethat files in your new workspace
  1. Copy上面的文件
  2. Create一个新的工作空间
  3. Copy and Replace新工作区中的文件

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

这将完美地恢复您的自定义编辑器颜色设置。对我来说工作得很好。

回答by Oliver

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

Eclipse CDT 将“语法着色”存储在文件org.eclipse.cdt.ui.prefs 中

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

例如,它位于此处: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

复制并粘贴到新 Eclipse 实例中的顶部。当从 3.4 移动到 3.5 时,这对我有用

回答by VonC

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:

这样,您就可以将 Eclipse 首选项文件的特定规则隔离到一个较小的文件中,并且:

  • 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.

这种策略可以进一步细化为几个小的设置文件(一个用于 Java,一个用于 JSP、HTML、CSS 等),以便在重新导入这些设置时更好地分析潜在的副作用。

回答by st.never

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

我通过复制文件成功地导入了 Eclipse Helios 的语法高亮规则:

.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.

从源工作区到目标工作区。该文件似乎还包含 Eclipse 的代码格式化程序配置文件和代码模板。

Environment:

环境:

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

回答by WesternGun

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

  • 首先,这些文件包含与语法着色无关的行。
  • 其次,其他编辑器的语法着色位于别处,例如 XML 文件的语法着色位于

    org.eclipse.wst.xml.ui.prefs

and those of HTMLfiles:

和那些HTML文件:

    org.eclipse.wst.html.ui.prefs

JSP pages?

JSP 页面?

    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 *.preffiles in path

如果我们*.pref在路径中搜索文件

/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.

我们可以找到所有首选项文件,我们可以在其中找到所有着色设置行。但是将所有这些文件复制粘贴到另一个工作区也会引发问题,因为它们不仅仅与语法着色相关。而且,当我们在两个版本的 Eclipse 之间切换时,可能会出现意想不到的问题。

So, the safest way is:

所以,最安全的方法是:

  • Create a new workspace if you don't have one.
  • Open all *.preffiles 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.
  • 如果没有,请创建一个新工作区。
  • *.pref我们在工作区中找到的所有文件一一打开,
  • 复制那些包含颜色代码的行,
  • 在新工作区中找到相同的文件,
  • 用现有的颜色部分替换颜色部分。或者,通过根据属性名称假设相应的选项,在 Eclipse 中设置颜色。所有颜色代码均基于 RGB。

EDIT: (2017.02.24)

编辑:(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:

Eclipse Mars 有一个Oomph插件,可以记录你的偏好设置,提供你的偏好无缝传输。当您激活它时,每次更改一个值时,它都会提示您是否要在 Oomph 中记录它,并为您提供存储新值的相应文件中的确切行。因此,当您安装 Oomph 时,您可以:

  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.)
  1. 更改字体、字体大小、背景颜色等的设置。
  2. 在 Oomph 的提示窗口中,记下新设置的位置。(因为如果你告诉 Oomph 记住你的设置,它不会再提示,所以你可能只看到一次这个窗口。)

回答by Erhan Bagdemir

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

几天前我遇到了同样的问题。恢复默认值的最简单方法是再次导入默认主题,您可以在以下位置找到:http: //eclipsecolorthemes.org/?view=theme& id=790

回答by Mohan Narayanaswamy

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

我从以下目录中删除了最近更改的 *.prefs 文件 \myworkspace.metadata.plugins\org.eclipse.core.runtime.settings\ 并导入了现有的导出首选项。

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

我是第一个根据我的知识回答这个问题的人:),因为即使我也很挣扎。

Thanks

谢谢