Eclipse Preferences You Need to Know

Lately there have been many discussions regarding Eclipse preferences because of sites like ihateeclipse.com. The Number 1 complaint on this site is that Eclipse’s resources get out of sync with the file system and, as a result, the user has to press F5. I’ve also run into this more than once ;). Anyway, since I’m pretty much an Eclipse power user I have spent some time putting together my personal Eclipse default preferences. With this post I want to share them with you. They might help you with some small efficiencies or better, can maybe act as a kind of template for new Eclipse defaults. So, let’s get our hands wet…

Refresh on Access aka “out of sync with file system”

refresh on access 150x150 Eclipse Preferences You Need to KnowEclipse offers a few ways to deal with files that have changed outside of Eclipse. It can poll changes or use native OS hooks to refresh them. My favorite is the “Refresh on access” option which can be found under “General” -> “Workspace”. This instructs Eclipse to “press F5″ automatically when opening a file.

Workspace Encoding

workspace encoding 150x150 Eclipse Preferences You Need to KnowEclipse uses the default OS encoding for encoding text files. Here at EclipseSource we have a very heterogeneous environment. This means we work with Macs, Windows machines and Linux machines. So, having a common encoding would be very useful ;). Luckily there is UTF-8 and we can set it as the default. You can find the preference under “General” -> “Workspace”.

Tabs vs. Spaces

tabs vs spaces 150x150 Eclipse Preferences You Need to KnowAs you may know there is a holy war between people that favor spaces and those who favor tabs for spacing in source code files. At EclipseSource we have agreed to use spaces ;). But, by default Eclipse uses tabs. We can change this under “Editors” -> “Text Editors”.

Line Numbers

line numbers 150x150 Eclipse Preferences You Need to KnowFor me, line numbers are a must in any text editor. Sadly the Eclipse default does not show them. The good news here is that if you want line numbers you can activate them for all text editors by changing the preference in “Editors” -> “Text Editors”.

Print Margin

print margin 150x150 Eclipse Preferences You Need to KnowWhen you work in a team you probably have some coding standards. We have some regarding the max characters in a line. While I don’t like auto formatted code I would like to see how long a line is without checking the bottom status bar. For this we can add a Print Margin to our text editors that is always visible at the specified length. You can find the preference under “Editors” -> “Text Editors”.

Default Launchers

launching 150x150 Eclipse Preferences You Need to KnowBy default Eclipse tries to find the associated launchers when you try to shortcut-launch from within a file . However, this is not what I want. I would like Eclipse to always use the launcher that I used the last time. The reasons are that when I’m working on a team project, I usually share the launch configuration and I use it myself all the time. You can change this preference under “Run/Debug” -> “Launching”.

Appearance

appearance 150x150 Eclipse Preferences You Need to KnowEclipse 4 came with a new default look and feel. From my point of view this design does not fit my needs. The big tabs and frameless areas do not look so great on my Mac and I think they are disturbing in an IDE. So, what I always do with a new workspace is reset Eclipse to use the old Eclipse 3 look and feel. With the same change I also deactivate animations as a small performance tweak. You can find the preference under “General” -> “Appearance”.

Open Perspective

open perspective 150x150 Eclipse Preferences You Need to KnowEclipse has the concept of perspectives. E.g. you have a perspective for Java development and one for debugging. I found myself switching between those perspectives all the time. This was pretty annoying! As you might know, a perspective is nothing more than a collection of views. As a result you can add any view to any perspective. With this, I can use only one perspective for both development and debugging. So, I don’t want Eclipse to ask me every time if I want to open another perspective. You can deactivate this by changing the preference under “Run/Debug” -> “Perspectives”.

Spell Checking

spell checking 150x150 Eclipse Preferences You Need to KnowI do not write emails with Eclipse, do you? I didn’t think so! I write code with Eclipse and while writing code I don’t need spell checking. Eclipse has it enabled by default. You can disable it by changing the preference under “General” -> “Editors” -> “Text Editors” -> “Spelling”.

Java: Semicolons

semi colons 150x150 Eclipse Preferences You Need to KnowIf you are a Java developer,  you might find it disturbing to always insert semicolons by hand. So, Good News everyone! Eclipse can add the semicolon for us automatically. Just enable the preference under “Java” -> “Editor” -> “Typing”.

Java: Templates

templates 150x150 Eclipse Preferences You Need to KnowDuring development you may find yourself writing the same code over and over again. I’m not talking about application code. If you write application code over and over again read some books about Object-Orientation :). I’m talking about boilerplate code like the method signature of a test method or something similar. Luckily you can define templates using the Eclipse preferences that can be accessed using the content assist. You can add new templates under “Java” -> “Editor” -> “Templates”.

Java: Content Assist Favorites

content assist favorites 150x150 Eclipse Preferences You Need to KnowWhen using static utilities like JUnit’s assertions, Guava’s preconditions or Mockito’s mock methods you probably use static imports. If not please consider it ;). The bad thing is that Eclipse doesn’t know anything about these methods and it can’t add it to your content assist. But you can add it once and use it over and over again by adding the types you want to use in your content assist favorites under “Java” -> “Editor” -> Content Assist” -> “Favorites”.

Java: Type Filters

type filters 150x150 Eclipse Preferences You Need to KnowI use Eclipse’s content assist all the time. I barely type code except for method, type and variable names. One thing that I always found disturbing was that when I’m developing for example, an SWT application I also see the AWT code in my content assist. Of course I don’t want to mix frameworks. So, I was looking for a way to exclude AWT from my content assist. Eclipse knows about type filters that do exactly this. You can filter out whole packages by adding them under “Java” -> “Appearance” -> “Type Filters”.

Java: Save Actions

save actions 150x150 Eclipse Preferences You Need to KnowOne of the coolest things in Eclipse is save actions. Are you managing your Java imports manually or do you replace unnecessary whitespaces by hand? If you answered yes, save actions will be your new best friends. You can perform nearly anything when saving a file like organizing imports, removing whitespaces and much more. By default save actions are disabled but you can enable them under “Java” -> “Editor” -> “Save Actions”.

Web Development: Default Browser

browser 150x150 Eclipse Preferences You Need to KnowEclipse comes with its own browser view that opens by default when you access, for example, an html file or something similar. From my point of view this browser is just trash and can’t be used for web development. As you might know one of the most important things for a web developer are the Firebug/Chrome Developments Tools. You simply can’t use them together with the built-in browser. But you can change how Eclipse handles browser resources under “General” -> “Web Browser”.

That’s it…

A colleague of mine wrote a post a few months ago about debugging in Eclipse and how to become more productive with Eclipse. I recommend reading them because he has described other useful preferences which are not in this post. If you know about other cool preferences please share them with us in a comment. And as always, feel free to disagree ;).

8 Responses to “Eclipse Preferences You Need to Know”

  1. james says:

    Nice post, I agree on a lot of the things mentioned however I think spell checking can be advantageous, but that’s just my opinion. Also could you post some of the boiler plate templates you use, may be handy to myself and others, unless they are to specific to your code base. Thanks

  2. Hi James,
    I posted a junit 4 template a while ago: http://eclipsesource.com/blogs/2012/03/20/simple-junit4-templates-for-eclipse/

    My other templates are not ready for public I think ;). Maybe I can refactor them and create an separate post. But please give me some time ;)

  3. Tim says:

    Sadly not all editors and formatter respect the tabs/spaces settings in “Text Editors”. With all the plugins I have there are at least the following places I can set the default indention character(s):

    General -> Editors -> Text Editors
    General -> Editors -> AnyEdit Tools -> Auto – Convert
    Amateras (“Use soft tabs”)
    Ant -> Editor -> Formatter
    Java -> Code Style -> Formatter -> Edit -> Indention
    VJet -> Formatter -> Edit -> Indention
    XML -> XML Files -> Editor

    Thats just for the plugins I use. If you have more/others, it can be a good idea to search the settings for keywords like “tabs”, “formatter”, “save actions”, “idention”, “editor”, etc.

    In addition, some of these settings can be overwritten in the project properties, so sometimes you might have to search there also…

  4. Fredrik Attebrant says:

    Great blog!
    However, setting all these preferences leaves you with the need to share them to avoid having to do it over and over again. And Eclipse do really suck in not supporting sharing of preferences OOTB as someone wrote on ihateeclipse.com …

    Luckily there’s some alternative approaches for sharing preferences, which I blogged about here:

    http://fredrikattebrant.blogspot.se/2011/03/controlling-eclipse-preferences.html

    –Fredrik

  5. xAltD says:

    Run > Debug/Launching
    -> Always run previously launched applications

    Much better workflow for me, as I can rely on the keyboard shortcut for launching [Ctrl+]F11. Otherwise from time to time Eclipse will try to launch some other configuration, then you start to use the mouse again .. and lose time ;)

  6. Szymon Ptaszkiewicz says:

    Regarding comment 4: this is exactly the reason why the Workspace Encoding section is a bad recommendation. Eclipse does allow to share preferences without any additional action if they are correctly set per project.

    A lot of preferences can be set in different scopes. Encoding is the best example: you can set it per workspace as described in the article (so called instance scope), but then all developers in your company need to do the same in all of their workspaces in order to have consistent settings everywhere. Much better (and actually the best choice for encoding preference) is to set it per project (so called project scope). This way encoding preference is shared in SCM together with the project and there is no need to ask all of your developers to set the encoding preference in their workspaces. A preference set per project always overrides workspace preference so even if a developer changed his/her workspace defaults, encoding set per project will override it for this project. Note that you also don’t need to care about operating system your developer will use.

    Another big advantage is that when a new developer joins the team, you don’t need to teach him all the tips how to prepare defaults for a new workspace. He just need to checkout a project from SCM and the correct preferences will already be there. Of course, per project settings can (and should) be used also in case of other preferences like JDT settings and many others.

  7. Gilles says:

    I think the step-filtering under Java->Debug is quite handy. Excluding java.lang.ClassLoader, simple getters, simple setters makes the step debugging quite smooth.

  8. Robin says:

    +1 to Szymon Ptaszkiewicz (comment 6). I have seen both worlds and configuring the settings on the project and sharing it via repository is much better than having them per-workspace with a “please configure Eclipse like this” guide.

8 responses so far

Written by . Published in Categories: Planet Eclipse, Planet OSGi