0x2a.at

... and their answer to everything

More Eclipse Shortcuts You Should Know

posted on 2008-09-17, author: Michael Zoech

There is an excellent post about Eclipse navigation shortcuts at 10 Eclipse Navigation Shortcuts Every Java Programmer Should Know. Since this post only looks at navigation shortcuts, i thought i post some of my favourite Eclipse shortcuts i use every time in Eclipse to boost my productivity.

Look at next/previous error in current file

Use Ctrl + . or Ctrl + , to cycle through the errors in the current file. This marks the next or previous error. Hitting F2 shows the error description and the quick-fix menu. This is much faster than using the mouse to locate the error, float over and wait for the description to pop up. Note, this works for warnings too.

Error Description and Quickfix

Quick-Fix menu

The quick-fix menu provides you with the appropriate refactoring options for the current cursor position. This lets you add imports (see picture above), add unimplemented methods, extract marked expressions to local variables, … . Hit Ctrl + 1 to get it.

Show quickfix for unimplemented methods

Show quickfix extract to ...

Run jUnit tests of current file

Hitting Shift + Alt X T runs the jUnit tests found in the current file. Use Shift + Alt D T if you want to debug-run the tests.

Rerun jUnit Test

I often find myself in the need to run the same jUnit tests again and again. The jUnit plugin provides the ReRun Test button, i think i have hit a million times now.

ReRun JUnit Test Button

Luckily you can create a shortcut binding for this. Go to Window -> Preferences -> General -> Editors -> Keys and setup an appropriate binding. I have bound this command to Ctrl + Alt R R. This makes it really easy to write tests, jump back and forth to the production code and rerun the same test files over and over again.

Surrounding code parts with try-catch, if, for, …

Surrounding already existing code with something like a try-catch block or a for loop is often tedious and error-prone. Not any longer. Mark the code you want to move inside the block or loop, hit Shift + Alt Z and select the type of surrounding block.

Before

Selected expression Integer.parseInt(input);

After

Expression surrounded by try-catch block

Rename variable, method, class, …

Hitting Shift + Alt + R lets you rename a variable, method or class name at the current cursor position. The renaming happens not only in the current file, but takes care of all references to the variable, method or class in other files of the project.

Renaming a method

Note that the renaming fixes the reference in the other method.

The Content Assist Menu

Hitting Ctrl + Space shows the Content Assist menu for the current cursor position. E.g. writing ‘‘for’’ and hitting Ctrl + Space shows the following:

Content Assist Menu

Selecting the first template (for - iterate over array) replaces the ‘‘for’’ with this:

Content Assist for

There are many predefined templates. Go to Window -> Preferences -> Java -> Editor -> Content Assist -> Templates to find out about templates and to create your own templates. My favourite one is ‘‘Test’’ for creating an empty jUnit test method.

Show all shortcuts

Shift + Ctrl + L shows a list of all shortcuts. Although i do not use this on a daily basis you may find even more interesting shortcuts there.

Show Key Asist

blog comments powered by Disqus