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”
Eclipse 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.
Eclipse 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
As 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”.
For 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”.
When 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”.
By 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”.
Eclipse 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”.
Eclipse 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”.
I 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”.
If 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”.
During 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
When 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
I 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
One 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
Eclipse 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”.
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 ;).
Latest posts by Holger Staudacher (see all)
- An Apache Cordova hook to auto bump iOS CFBundleVersion and Android versionCode - April 7, 2015
- Brand your Tabris.js app - April 2, 2015