You are on page 1of 8

Eclipse Cheat Sheet

by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Core Generate

Ctrl+1 Quickfix Alt+⇧S​hift+S, R Generate Getters and Setters

Ctrl+3 Open "​Quick Access​" search


Movement
Ctrl+␣ Content Assist

Alt+⇧S​hift+Z Surround with (do, for, if, try, ..) Alt+↑/↓ Move current line or selection up or down

Ctrl+Z Undo Ctrl+←/→ Jump one word to the left / right

Ctrl+⇧​Shift+Z Redo Ctrl+⇧Shift+↑/↓ Jump to previous / next method

Ctrl+L Jump to Line Number. To hide/show line


Testing numbers, press Ctrl+F10 and select 'Show Line
Numbers'
Alt+⇧S​hift+X, T execute Tests
Ctrl+Q Jump to last location edited
Ctrl+R execute Tests moreUnit
Ctrl+./, Jump to next / previous warning or error
Ctrl+J jump to test or implem​ent​ation moreUnit
Ctrl+↑ Scroll up

Comment Ctrl+↓ Scroll down

Ctrl+⇧​Sh​​ift+P Go to the matching bracket


Ctrl+/ Comment / uncomment line or selection (adds '//')
Alt+⇧S​h​i​ft+↑/↓ Select the previous / next syntac​tical element
Ctrl+⇧​​Sh​ift+7 Add Block Comment around selection (adds '/... */')
Alt+⇧Sh​ift+↑/↓/←/→ Extending / reducing the selection of the previous
Ctrl+​​⇧Sh​ift+ß Remove Block Comment
/ next syntac​tical element
Alt+⇧S​hift+J Add Element Comment (adds '/** ... */' JavaDoc)
Tip: Use bookmarks. Add them on left margin of the code view (where

Text Editing you set the breakp​oints) with "​right click → Add bookma​rk". Add the
Bookma​rks​-View (Window → Show View → Bookma​rks).
Ctrl+⇧Shift+Y lowercase selected text

Ctrl+⇧​Shift+X uppercase selected text Selection

Ctrl+D Delete line Alt+⇧S​hift+↑ Expand selection to current element


Ctrl+⇧Shift+Del Delete until end of line Alt+⇧S​hift+↓ Reduce previously expanded selection by one step
Ctrl+Del Delete next element

Ctrl+⌫ Delete previous element Search / Inform​ation

Ctrl+A​lt+↓/↑ Copy line below/​above Ctrl+⇧​Shift+ Open Type


T
Alt+/ Propose word completion - after typing at least one
letter. Repeatedly press until reaching correct name Ctrl+⇧​Shift+ Open Type In Hierarchy
H
Alt+⇧S​h​ift+A Column (block) selection, Multiline block editing

⇧Sh​if​t+Enter Adds a blank line below the current line Ctrl+⇧​Shift+ Open Resource
R
Ctrl+⇧​Sh​​ift​+Ent Adds a blank line above the current line
Ctrl+O Show Outline (second press shows the inherited
er
members)

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 1 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Search / Inform​ation (cont) Cleanup

F2 Open class, method or variable inform​ation (tooltip text) Ctrl+⇧​Shift+O Organize Imports

F3 Open Declar​ation: Jump to Declar​ation of selected Ctrl+⇧​Shift+F Format Source


class, method or parameter
Ctrl+I Intend selected source
F4 Open Type Hierarchy window for selected item Ctrl+⇧​Shift+M Add Import / also static imports
Ctrl+T Show Quick Type Hierarchy (toggles between
supertypes and subtypes when pressed again) Refact​oring

Ctrl+U Find occurr​ences of expression in current file Alt+⇧S​hift+R Rename Element


Ctrl+mouse Open Declar​ation or Implem​ent​ation Ctrl+2, R Rename locally (in file), faster than Alt+⇧S​hift+R
over method
Alt+⇧S​hift+L Extract to local variable
Ctrl+⇧Shift+L List of shortcuts (depending on the context)
Alt+⇧S​hift+M Extract to method
Ctrl+⇧​S​h​if​t+␣ Method cursor is located at the parameter
Alt+⇧S​hift+T Opens the contex​t-s​ens​itive refact​oring menu
Parameter specif​​ic​ation for method reference
Hints Alt+⇧S​hift+R Rename

Ctrl+⇧Shift+G Search workspace for references to selected method or Alt+⇧S​hift+V Move


variable Alt+⇧S​hift+C Change Method Signature
Ctrl+G Search workspace for declar​ations of to the item under Alt+⇧S​hift+M Extract Method
the cursor
Alt+⇧S​hift+L Extract Local Variable
Ctrl+F Quick search
Alt+⇧S​hift+I Inline
Alt+↵ Show properties (in Package or Project Explorer)

Editor Window

F12 Jump to Editor Window

Ctrl+P​gDn​/ Next / previous Editor - in theorder of their tabs in the


PgUp editor area

Ctrl+M Maximize or un-max​imize current Editor Window

Ctrl+E Show list of open Editors. Use arrow keys and enter to
switch

Alt+←/→ Backward / Forward editor navigation history

Alt+- Open Editor Window Option menu

Ctrl+F6 Next Editor - if released it immedi​ately, Eclipse will take you


to the last active editor

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 2 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Editor Window (cont) Templates (Java → Editor → Templates) (cont)

Ctrl+⇧​Shi​ft+F6 Previous Editor sysout, syserr, systrace Creates System.out...

Ctrl+E Quick Switch Editor strf Format string here

Alt+F7 Multipage editor - next Page if if null/if not null

Alt+⇧S​hift+F7 Multipage editor - previous Page for iterate over map

Ctrl+- Toogle Split Editor old: Ctrl+_ static​_final static final field
(Horiz​ontal) - since before junit before method
Luna
after junit after method
Ctrl+< Toogle Split Editor old: Ctrl+{
before​class junit before​class method
(Vertical) - since Luna

Ctrl+⇧​Shi​ft+​"N Collapse all code blocks afterclass junit afterclass method

um Keypad /" quote surround selection with quotes here


Ctrl+⇧​Shi​ft+​"N Open all code blocks Tip: It is possible to select text and use completion (Ctrl+␣) including
um Keypad *"
typing of template name
⇧Shift (and Show source (in settings: Window →
hover over tooltip) Prefer​ences → Java → Editor Changed Eclipse Keybin​dings
element) → Hovers
Windows → Prefer​ences → General → Keys
Required modifi​cations due to the german QWERTZ keyboard layout:
Outline View
1. Add Block Comment - new: Ctrl+⇧​Shi​ft+7, old: Ctrl+⇧​S​h​ift+/
Reorder class members Disable "Sort Order" - otherwise not 2. Remove Block Comment - new: Ctrl+⇧​Shi​ft+ß, old: Ctrl+⇧​S​h​ift+\
with Drag & Drop possible
3. Toogle Split Editor (Horiz​​ontal) - new: Ctrl+⇧​Shi​ft+-, old: Ctrl+_
Automatic reorde​ring: Select the class, 4. Toogle Split Editor (Vertical) - new: Ctrl+⇧​Shi​ft+​<, old: Ctrl+{
Source → Sort Members Update 12/2016: had to add ⇧Shift to 3. and 4. because of new Eclipse
Neon Zoom functionality with Ctrl+-
Package / Project Explorer

Alt+F5 Maven → Update Project... Project Specific Config​uration

1. Import project Java formatter config​ura​tion


Problems View
2. Download Chec​kstyle config​ura​tion file from sonar server and
Configure to view only warnings Problems View - Configure Contents reference the config file as a file resource url
and errors associated with a e.g. select "on any element in same
3. Download Findbugs config​ura​tion file from sonar server and add the
particular resource or group of projec​t" to restrict to current selected
config file under "​include filter files"
resources project
4. Download PMD config​ura​tion file from sonar server and first "​clear
all" existing rules and then import the config file
Templates (Java → Editor → Templates)

test Created test method Plugins


for Creates for loop
Testing Support moreUnit
new Creates new instance
Infinitest
try Creates try..catch
Test Coverage EclEmma

Source Code Analyzer FindBugs

Checkstyle

PMD Update-Site

Usus

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 3 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Plugins (cont) XUbuntu specific Config​uration Changes

 SonarCube or Ignore certain warnings with Delete following keybin​dings in XFCE Settings → Window Manager →
SonarLint //NOSONAR or Keyboa​rd:
@Suppr​ess​War​nin​gs(​"​squ​id:​S0 1. Ctrl+A​lt+↓/↑
0​112​") 2. Ctrl+F6
Refact​oring JDeodorant 3. Alt+F5

Subversion Subclipse
Eclipse Team
If running IBus​-Ap​plet delete keybinding definition for "​Ctr​l+S​pac​e"
Provider
(Content Assist) in IBus-S​ettings
Plugin

use Subclipse instead of Subversive because it is much


faster Use gnom​e-c​olo​r-c​hoo​ser and change options:
use JavaHL native/JNI provider 1. This only works for Eclipse < 4.5, because Eclipse Mars 4.5 and
higher uses GTK3 by default (gtkrc-2.0 settings will not be used).
Task based Mylyn
working You can force Eclipse 4.5 and higher to use GTK2 with the following
export or change GTK3 theme options: export SWT_GTK3=0
Nice: Task-focused Change Sets
2. Tooltip colors (backg​round: yellow, foregr​ound: black)
Subclipse includes an optional Mylyn connector 3. Global colors → Input field selected (foreg​round: black)
JavaDoc JAutoDoc

Maven M2Eclipse (m2e)


Disable "​pin​k/p​urple highli​ght​s" in Xubuntu 14.10 and higher: disable
integr​ation
custom hightl​igh​t-color in gtk-​the​me-​con​fig
add needed m2e m2e project config​urators for
connec​tors. follow Eclipse WTP
Settings
pom.xml
hints/​pro​blems. e.g: show "." files in "P​ackage Explorer → View Menu → Filters →
package uncheck .*" or "​Package Explorer → Customize
m2e connector for
explorer View… → Filters → uncheck .*"
build-​hel​per​-ma​ven​-plugin

m2e connector for the Eclipse Package Link file to package explorer
JDT Compiler Explorer Option
"Link with
m2e connector for the Maven
editor​"
Dependency Plugin
Favorites Windows → Prefer​ences → Java → Editor → x¹
Groovy​-Ec​lipse m2e
Imports Content Assist → Favorites, New Type...
integr​ation
Add types for Assertion library Hamcrest and/or
Decompiler Eclipse Class Decompiler
AssertJ, Mockito and JUnit-​Assert

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 4 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Settings (cont) Settings (cont)

Show line numbers Window → Prefer​ences → General → Editors → Formatter Window → Prefer​ences → Java here
Text Editors → "Show line number​s" Options → Code Style → Formatter →
Off/On Tags for
Show print margin Window → Prefer​ences → General → Editors →
Text Editors → "Show print margin​" //@for​mat​ter:off and
//@for​mat​ter​:on
Paste multiline Window → Prefer​ences → Java → Editor → Typing
strings → "​Escape text when pasting into a string litera​l" Check the Never join lines here
preference accessible on the
Import code x²
Line Wrapping and the
templates
Comments tabs of the Java
collection
Formatter preference page
Import code x²
template Improve Window → Prefer​ences → Valida​tion, Disable All

"​sur​round with Perfor​manc

quotes" e

Add -Xve​rif​y:n​one to tell the VM not to


MoreUnit Test source folder: "​src​/te​st/​jav​a"
eclips​e.ini validated all the .class
Config​uration
files it is loading
Test Type: "​Jun​it4​"
Window → Prefer​ences remove plugins not
uncheck "Use test-p​refix for test-m​eth​ods​"
→General → Startup and needed
Rule for naming test files → Pattern: ${srcF​ile​} Shutdown
(T​est​|IT​|IT​Case)
increase -Xms and -Xmx heap e.g. -Xms512m -
if you have legacy tests with Test prefix:Rule for memory options (start and max) Xmx2048m
naming test files → Pattern: (Test)​${s​rcF​ile​} in eclipse.ini
(T​est​|IT​|IT​Case)
increase -XX:MaxPermSize e.g. -
option (if java < 1.8) XX:MaxPermSize=512m

Enable Window → Prefer​ences → Java set to Warning and


inform​ative → Compiler → Errors​/Wa​rnings keep sub checkboxes
Eclipse checked (if any)
Compiler
Warnings

Potential Program
​ ming Potential resource leak
problems

Unnec​essary code Value of parameter is


not used

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 5 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Settings (cont) Settings (cont)

Unused type parameter Code Style • "Use blocks in if/whi​le/​for/do statem​ent​s"

Unnece​ssary declar​ation of • Use lambda where if you use Java


thrown exception possible >= 8
Unnece​ssary 'else' statement Add final modifier to • Add final modifier to private fields
Unnece​ssary cast of private fields*
'insta​nceof' operation • Add final modifier to local parameter
Generic types Redundant type arguments • Add final modifier to local variables
(1.7 and higher)
Unused Code • Remove unused imports
Annot​ations Unhandled token in
• Add missing '@Over​ride' annota​tions
'@Supp​res​sWa​rnings' set to
"I​gno​re" • Add missing '@Over​ride' annota​tions to
impleme
​ nt​ations of interface methods
Null analysis Redundant null check
• Add missing '@Depr​ecated' annota​tions
Indent Window → Prefer​ences → Select "​Indent using spaces​"
• Remove unnece​ssary casts
using XML Files → Editor and set "​Ind​ent​ation Size: 4"
spaces • Remove unnecessary '$NON-NLS$' tags

Window → Prefer​ences → Set "​Dis​played tab width: 4" Limit maximum Window → Prefer​ences → General → Editors
General → Editors → Text and select "​Insert spaces for number of open editors
Editors tabs"
check "​Close editors automa​tic​all​y"
Save Window → Prefer​ences →Java →Editor → Save Actions
choose value (e.g. 20) for "​Number of opened
Actions
editors before closin​g"
check "​Perform the selected actions on save"

check "​Format source code", "​Format all lines"

check "​Org​anize import​s"

check "​Add​itional action​s" and add the follow​ing:

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 6 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Settings (cont) General

JDT Window → Prefer​ences → if you use Java < 8 (cannot use Refresh all In Package Explorer Ctrl+A, F5
Core/Null Java → Compiler → Optional) and cannot use Projects (with
Analysis Errors​/Wa​rnings, Section Guava Optional e.g. for legacy some closed in
to avoid Null analysis projects between)
NPEs
Use Working Package Explorer → open the drop-down menu →
check "Enable annotation- you can use the Eclipse Sets for better Select Working Set
based null analysis" annotations, the JSR-305 perfor​mance
annotations (old), custom ones
If Ctrl+⇧​S​h​ift+R and Ctrl+⇧​S​h​ift+T does not reflect
or the JSR-308 annotations
active Working Set check the small arrow on the top
from Checker Framework
right of the dialogue to select Working Set
Maven Window → Prefer​ences → Maven → User Interface

check "Open XML page in Reas​on: show pom.xml Troubl​esh​ooting Projects


the POM editor by defaul​t" source code is faster than
Maven try without eclipse [Project] → Properties →
loading the "​Ove​rvi​ew" tab all
dependency project resolu​tion Maven
the time
issues
JUnit Window → Prefer​ences → enable JVM assertions by
uncheck "​​Re​solve
Java → JUnit enable "Add default
depend​​encies from Workspace
'ea' to VM arguments when
projec​​ts​" to check with jars
creating new JUnit launch
from local ~/.m2 repository
config​ura​tio​n"
instead of eclipse projects
Show Window → Prefer​ences → enable "Show heap status​" within worksp​ace​/wo​rki​ngset
heap General
clean projects don't mix usage of maven CLI
memory
and m2e eclipse plugin
status
if mixed - make a mvn
Enable Window → Prefer​ences → enable checkboxes and select
eclips​e:c​lean (CLI) and
"Quick General → Editors → Text correct reference source option
Diff" Editors → Quick Diff import again in eclipse

Error message The find project with .clas​spath


x¹: TDD-Style mockito: org.mockito.Mockito, BDD-Style mockito:
org.mockito.BDDMockito, org.junit.Assert, org.hamcrest.Matchers, archive: file where old/wrong jar is

org.assertj.core.api.Assertions <pa​th_​to_​jar​_fi​le> referenced


x²: Java → Editor → Templates which is
referenced by the
classpath, does
not exist.

make a mvn
eclips​e:c​lean (CLI) and
import again in eclipse

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 7 of 8. http://crosswordcheats.com
Eclipse Cheat Sheet
by Oliver Paulus (oli.p) via cheatography.com/19982/cs/2862/

Troubl​esh​ooting Projects (cont)

you can use this command to search for the projects refere​ncing old jar:
find -name '.clas​spath' -exec grep -Hin
'examp​le-​1.2.3.jar' {} \;

By Oliver Paulus (oli.p) Published 27th December, 2014. Sponsored by CrosswordCheats.com


cheatography.com/oli-p/ Last updated 25th January, 2017. Learn to solve cryptic crosswords!
www.code-project.org Page 8 of 8. http://crosswordcheats.com

You might also like