Top 10 (not so popular) Eclipse Shortcuts
May 19th, 2009 Handerson Gomes, Consultant
I’m fortunate enough to spend a good part of my days writing code in an IDE and I believe that we can always be more efficient even if that means reaching the mouse less frequently.
I’m an earlier Eclipse user, and throughout the years I’ve learned a lot of helpful shortcuts. Most of them are very popular like the ctrl+s to save and F3 to open declaration. Here are my top 10 not so popular shortcuts available in Eclipse 3.x and by consequence IBM Rational Application Developer 6 (RAD) and newer versions.
These shortcuts not only allow me to navigate easily through the source code, but also helps me stay focus on the code I’m writing and making refactoring a second nature, which by the end of the day tends to improve the overall quality of the software.
1. Open Resource (ctrl+shift+r)
This one is probably the biggest time saver of all shortcuts. This shortcut allows you to open any file in your workspace by only typing the first letters of a file name or a mask, like applic*.xml. The only drawback of this shortcut is that it is not available in all perspectives. 
2. Quick Outline (ctrl+o)
Do you want to view the methods of the current class or navigate to a specific method without having to scroll down the code or use the find function? ctrl+o is the answer. It will list all methods and attributes of the current class and you can just start typing the name you want and then press enter to navigate directly to that method or attribute.

3. Quick Switch Editor (ctrl+e)
This one will help you navigate through the open editors. You can use ctrl+page down or ctrl+page up to navigate to the next and previous tabs, but ctrl+e will be more effective when you have a lot of files opened.

4. Assign to local variable (ctrl+2, L)
During development I’m used to first write the method invocation, like Calendar.getInstance(), and then assign the return of the method to a local variable using this shortcut. It saves me the time to enter the class name, variable name and also the import declaration. The ctrl+2, F is similar but will assign the return of a method to a field in the class.
5. Rename (alt+shift+r)
Renaming attributes and methods was a big deal years ago, using a combination of search and replace that frequently would lead to broken code. Every modern Java IDE today provides refactoring capabilities and Eclipse is not different. It is so easy to rename variables and methods names that once you get used to it you’ll be renaming it every time you think it is necessary or when a better name is recommended in code review sessions. To use this shortcut just move the cursor to the attribute or method name and press alt+shift+r, enter the new name and press enter. Done! All references to this method in every class in the project will be renamed automatically. If you’re renaming an attribute of a class you can press alt+shift+r twice, it will display the Refactor Dialog which allows you to automatically rename the gets and set methods also when refactoring an attribute.
6. Extract Local Variable (alt+shift+l) and Extract Method (alt+shift+m)
Refactoring also includes extracting variables and methods from blocks of code. These two shortcuts allows us to do exactly that. Do you want to create a constant from that String? Just select the text and hit alt+shift+l. If that same string is in other places on the same class it will automatically be replaced there. The Extract Method is also very helpful and clever enough to know (in most cases) the arguments that must be used when you want a section of your code to be exposed as a new method. Breaking larger methods in smaller well defined methods is one of the best ways to reduce cyclomatic complexity and also to improve testability of your code.
7. shift+enter and ctrl+shift+enter
Shift+enter adds a new blank line right above moving the cursor to the new line. The difference between a regular enter is that the cursor doesn’t need to be at the end of a line. The ctrl+shift+enter does the same thing adding the line right before the current line.
8. Alt+arrow keys
This one is a big time saver too. It will move the current line or selection up or down. Very helpful when moving sections of code in try/catch blocks.
9. ctrl+m
We all know how productive a big screen is and the ctrl+m shortcut will maximize the editor view.
10. Next Error (ctrl+.) and Quick Fix (ctrl+1)
ctrl+. moves the cursor to the next error or warning in the current file. I use this almost always in conjunction with ctrl+1 which is the suggestion shortcut. New versions of Eclipse are pretty clever on the suggestions, helping you sort out a lot of problems like missing arguments in methods, throw/catch exception, unimplemented methods, etc.
If you want to view more shortcuts you can type ctrl+shift+L in Eclipse.
Feel free to share your favorites shortucts using the comments.
Entry Filed under: Software Development







15 Comments Add your own
1. James Ervin | May 19th, 2009 at 3:20 pm
I had to mention one that you forgot to mention. I always tend to you Ctrl-Shift-T, which is open type instead of open resource. From a java coding perspective, I think it is far more useful.
2. Peter Hendriks | May 19th, 2009 at 3:25 pm
My favorite is the Ctrl+3 shortcut: open views, prefs, etc. all in one shortcut!
3. Vadim Berezniker | May 19th, 2009 at 7:56 pm
I was going to mention Ctrl+3 as one of the best unknown shortcuts/features, but someone beat me to it
4. teo | May 20th, 2009 at 3:35 am
OMG! I’ve been looking for “go to the next error” for sooo long!
Thanks!!
5. jakob | May 20th, 2009 at 5:58 am
My “refactoring combo”::
Alt+Shift+Arrow keys to select a Java expression, then Alt+Shift+(L|M|T) to extract a variable, method or to open the refactoring menu.
6. Handerson Gomes | May 20th, 2009 at 8:12 am
I would like to thank you all for the contribution. The Ctrl+3 is really a neat shortcut.
7. Ignacio Coloma | May 20th, 2009 at 2:46 pm
Shift + Alt + S, R -> Generate getters and setters.
Shift + Alt + S, O -> Generate Constructor using fields.
Ctrl + Alt + Arrow keys -> Duplicate selected code.
It’s funny, I had to open eclipse to find these out. I don’t know the keys, only the arcane gestures over the keyboard
8. Eduardo | May 20th, 2009 at 3:32 pm
The shortcut I use more often is “Next Editor”, however, its default key bind is not intuitive: Ctrl+F6. Change it to Ctrl+Tab and be happy
9. PRSoluções » Blog&hellip | May 20th, 2009 at 6:49 pm
[...] http://www.summa-tech.com/blog/2009/05/19/top-10-not-so-popular-eclipse-shortcuts/ [...]
10. kodeninja | May 21st, 2009 at 6:47 am
One very nice feature (although not a shortcut) in the Eclipse editor is the ability to automatically escape the data being pasted into a String literal. It’s disabled by default, so you need to enable it under Window -> Preferences -> Java -> Editor -> Typing.
Quite helpful when pasting, say, file/directory paths under Windows, which use ‘\’
Cheers!
-kodeninja
11. Alipio Krohn | May 26th, 2009 at 12:28 pm
Great Handerson !!!
Congratulations for the new blog. Excellent !
Alipio.
12. cmars | May 26th, 2009 at 5:25 pm
F3 -> Open Declaration
Ctrl-Alt-H -> Open Call Hierarchy
Invaluable when getting to know a new codebase.
13. Rahul Kamra | June 1st, 2009 at 8:29 am
My personal favorite Ctrl + D : Delete the current line , very handy when you want to remove white spaces
14. Suresh Reddy | June 18th, 2009 at 12:31 am
hi your shortcuts are very help ful
thank you very much
15. shortcut-finder | February 22nd, 2010 at 10:07 am
this is a good list of eclipse shortcuts
http://shortcut-finder.appspot.com/?query=eclipse
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed