Eclipse Cheat Sheet: Shortcuts

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

ECLIPSE CHEAT SHEET


This cheat sheet is aimed at people with some experience in eclipse but who may not be aware of many of its features.

SHORTCUTS
These are some of the most useful shortcuts in eclipse. You can find others listed beside their function in eclipses menus.
Menu

Key Combination

Use

Source

Ctrl+Space
Ctrl+1
Ctrl+D
Ctrl+Alt+Up
Alt+Up
Alt+Shift+Z
Ctrl+I
Ctrl+Shift+F
Ctrl+/
Alt+Shift+M
Alt+Shift+R
Ctrl+Shift+G
Ctrl+H
Alt+Shift+X, J
Alt+Shift+X, D

Auto-complete / Content Assist


Quick Fix (on current selection)
Delete Current Line
Copy Lines Up
Move Lines Up
Surround (current selection) With
Fix Indentation (on selection)
Fix Formatting (on selection)
Toggle Comments (on selection)
Extract Method
Rename
Find All References (of selection)
Advanced Search
Run Current Class
Debug Current Class

Refactor
Search
Run

AUTO-COMPLETE
These are some of the most useful options given to you after using the Ctrl+Space auto-complete shortcut.
Text Written So Far

What the Auto-Complete Function Does

<start of variable/method name>


main
public / private
randomstring
sysout
syserr
for
foreach
while
try

<end of variable/method name>


Creates a new main method
Creates a new public/private method
Creates a new void method named randomstring
Creates a new System.out.println();
Creates a new System.err.println();
Creates a new for loop
Creates a new iterator loop
Creates a new while loop
Creates a new try-catch block

You can also create your own auto-complete statements. Go to Window->Preferences, then on the left pane go to
Java->Editor->Templates

For example the following template creates a println outputting the contents of a specific variable:
NAME:
debug
PATTERN: System.err.println("${word_selection}: " + ${word_selection}); ${cursor}
This can be used now in eclipse by selecting a variable and pressing Ctrl+Space, then typing debug and pressing enter.
1

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

Figure 1: Creating a new auto-complete template

VIEWS IN ECLIPSE
Eclipse displays various views on the left and bottom of the screen that you may find useful. You can add new views if they are
not already displayed by going to Window->Show View, or by clicking on the following icon at the bottom left of your
workspace:

TASK MANAGEMENT
The task pane (pictured below) is a useful way of keeping track of incomplete sections of code, or places where code needs
tidied up.

Figure 2: Tasks Pane

Comments will automatically be shown in the task pane if you start a comment with either XXX or TODO.
You can also create your own custom markers by clicking on the down arrow in the top right of the task pane and opening
Configure Contents. Duplicate the TODO task you can then use your own custom tag by changing the description section.
2

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

PROBLEMS
The problems tab displays compiler warnings and errors.

Figure 3: Problems Pane

You can filter the contents of this tab so that it only displays local problems by clicking on the down arrow (in the top right) and
opening Configure Contents. Here you can change the scope of the problems shown for various types of errors and warnings.

PACKAGE EXPLORER VIEW


The package explorer displays projects in your workspace, with java files organized by package structure. You can choose to view
packages flat or in a hierarchy.
To link the currently open java file with the contents of the package explorer select the link with editor option.

Figure 4: Package Explorer Pane

You can also filter the projects and classes that are shown in the package explorer to allow you to focus on only relevant classes.
To do this click on the down arrow at the top of the package explorer and click on SELECT WORKING SET (shown above in
Figure 4). You can then create new working sets that filter on various conditions. For example, you can filter certain projects or
show on classes with specific debugging breakpoints. The menu with these options is illustrated below in Figure 5.

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

Figure 5: Working Sets

BREADCRUMBS
To enable the breadcrumb feature in eclipse, click on the

icon at the top of the workspace.

Breadcrumbs can be a quicker way of navigating between methods, classes, or packages in eclipse (as shown below).

Figure 6: Breadcrumbs

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

MENU OPTIONS
The next couple of pages summarise some of the most useful menu options that eclipse provides.

THE SOURCE MENU


Used for cleaning up source files and generating code.

Correct indentation
and spacing for the
current selection.

Gets rid of unused


imports among other
things.
A much more
comprehensive
formatter that can be
run on multiple
classes at once.

Avoid repetition in writing


constructors and creating
fields.

You need to implement Object.hashCode() and/or Object.equals


to be able to add your own objects to hash-based data structures
(hashmaps, hashsets) and perform object comparisons
repspectively, but you dont need to write them yourself.

This function places the contents


of a specified set of strings in a
properties file. It is a simple way
of avoiding magic constants in
your code.

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

THE REFACTOR MENU


Used for making changes to code without breaking the program (changes are reflected everywhere so, for example, renaming a
public field will change the fields name everywhere it is accessed).
Rename all occurrences
of a variable, method,
class, or package.

Move a method or field


to a different location.

Create a constant field


from a selected
expression.

Create an interface for


this class based on the
current set of methods.

Wrap a number of
method parameters into
a single class.
Add a selected
expression as a
parameter to a method
call.

Attempts to add types to


generic interfaces/classes
such as List and Map.

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

THE NAVIGATE MENU


Used for navigating between classes.

Shows the super-classes


and sub-classes of a
given class.

Shows which methods


call a given method,
which methods call those
methods, and so on.

Jumps to the method


which implements a
method from an
interface.

Jumps to the last line


which was edited.
Jumps to the
previous cursor
location.

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

THE SEARCH MENU


Used for searching for text and specific operations in Java classes.

Search for text


occurring in all files in
your project.

Shows all references to a


particular class, method, or
field.

Shows all locations


where a particular
type is declared.

Shows all read accesses to a


particular field or variable.
Lists all occurrences of
a field or method in a
file.

University of St Andrews (2010)

http://blogs.cs.st-andrews.ac.uk/angus/2010/09/eclipse-cheat-sheet/

THE RUN MENU


Used to start programs and debug them at runtime.

Run a program.
Debug a program.
Analyse execution
time, memory
utilization (requires
profiling plugin).

Breakpoints stop
execution of a program
at the line on which
they are added.
Stop execution of a
program when a
specified variable is
declared or accessed.

Stop the program when


a particular exception is
thrown.

Stop execution of the


program when a
particular class is
loaded.

[debug] Examine the


state of all instances of
the specified class.

[debug] Show the


current state of a
particular object.

You might also like