Show Menu
Cheatography

Eclipse Cheat Sheet by

Eclipse Cheat Sheet

Core

Ctrl+1
Quickfix
Ctrl+3
Open "­Quick Access­" search
Ctrl+␣
Content Assist
Alt+⇧S­hift+Z
Surround with (do, for, if, try, ..)
Ctrl+Z
Undo
Ctrl+⇧­Shift+Z
Redo

Testing

Alt+⇧S­hift+X, T
execute Tests
Ctrl+R
execute Tests
Ctrl+J
jump to test or implem­ent­ation

Comment

Ctrl+/
Comment / uncomment line or selection (adds '//')
Ctrl+⇧­­Sh­ift+7
Add Block Comment around selection (adds '/... */')
Ctrl+­­⇧Sh­ift+ß
Remove Block Comment
Alt+⇧S­hift+J
Add Element Comment (adds '/** ... */' JavaDoc)

Text Editing

Ctrl+⇧Shift+Y
lowercase selected text
Ctrl+⇧­Shift+X
uppercase selected text
Ctrl+D
Delete line
Ctrl+⇧Shift+Del
Delete until end of line
Ctrl+Del
Delete next element
Ctrl+⌫
Delete previous element
Ctrl+A­lt+↓/↑
Copy line below/­above
Alt+/
Propose word completion - after typing at least one letter. Repeatedly press until reaching correct name
Alt+⇧S­h­ift+A
Column (block) selection, Multiline block editing
⇧Sh­if­t+Enter
Adds a blank line below the current line
Ctrl+⇧­Sh­­ift­+Enter
Adds a blank line above the current line

Generate

Alt+⇧S­hift+S, R
Generate Getters and Setters

Movement

Alt+↑/↓
Move current line or selection up or down
Ctrl+←/→
Jump one word to the left / right
Ctrl+⇧Shift+↑/↓
Jump to previous / next method
Ctrl+L
Jump to Line Number. To hide/show line numbers, press Ctrl+F10 and select 'Show Line Numbers'
Ctrl+Q
Jump to last location edited
Ctrl+./,
Jump to next / previous warning or error
Ctrl+↑
Scroll up
Ctrl+↓
Scroll down
Ctrl+⇧­Sh­­ift+P
Go to the matching bracket
Alt+⇧S­h­i­ft+↑/↓
Select the previous / next syntac­tical element
Alt+⇧Sh­ift+↑/↓/←/→
Extending / reducing the selection of the previous / next syntac­tical element
Tip: Use bookmarks. Add them on left margin of the code view (where you set the breakp­oints) with "­right click → Add bookma­rk". Add the Bookma­rks­-View (Window → Show View → Bookma­rks).

Selection

Alt+⇧S­hift+↑
Expand selection to current element
Alt+⇧S­hift+↓
Reduce previously expanded selection by one step

Search / Inform­ation

Ctrl+⇧­Shift+T
Open Type
Ctrl+⇧­Shift+H
Open Type In Hierarchy
Ctrl+⇧­Shift+R
Open Resource
Ctrl+O
Show Outline (second press shows the inherited members)
F2
Open class, method or variable inform­ation (tooltip text)
F3
Open Declar­ation: Jump to Declar­ation of selected class, method or parameter
F4
Open Type Hierarchy window for selected item
Ctrl+T
Show Quick Type Hierarchy (toggles between supertypes and subtypes when pressed again)
Ctrl+U
Find occurr­ences of expression in current file
Ctrl+mouse over method
Open Declar­ation or Implem­ent­ation
Ctrl+⇧Shift+L
List of shortcuts (depending on the context)
Ctrl+⇧­S­h­if­t+␣
Method Parameter Hints
cursor is located at the parameter specif­­ic­ation for method reference
Ctrl+⇧Shift+G
Search workspace for references to selected method or variable
Ctrl+G
Search workspace for declar­ations of to the item under the cursor
Ctrl+F
Quick search
Alt+↵
Show properties (in Package or Project Explorer)

Cleanup

Ctrl+⇧­Shift+O
Organize Imports
Ctrl+⇧­Shift+F
Format Source
Ctrl+I
Intend selected source
Ctrl+⇧­Shift+M
Add Import / also static imports

Refact­oring

Alt+⇧S­hift+R
Rename Element
Ctrl+2, R
Rename locally (in file), faster than Alt+⇧S­hift+R
Alt+⇧S­hift+L
Extract to local variable
Alt+⇧S­hift+M
Extract to method
Alt+⇧S­hift+T
Opens the contex­t-s­ens­itive refact­oring menu
Alt+⇧S­hift+R
Rename
Alt+⇧S­hift+V
Move
Alt+⇧S­hift+C
Change Method Signature
Alt+⇧S­hift+M
Extract Method
Alt+⇧S­hift+L
Extract Local Variable
Alt+⇧S­hift+I
Inline

Editor Window

F12
Jump to Editor Window
Ctrl+P­gDn­/PgUp
Next / previous Editor - in the order of their tabs in the 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
Ctrl+⇧­Shi­ft+F6
Previous Editor
Ctrl+E
Quick Switch Editor
Alt+F7
Multipage editor - next Page
Alt+⇧S­hift+F7
Multipage editor - previous Page
Ctrl+-
Toogle Split Editor (Horiz­ontal) - since Luna
old: Ctrl+_
Ctrl+<
Toogle Split Editor (Vertical) - since Luna
old: Ctrl+{
Ctrl+⇧­Shi­ft+­"Num Keypad /"
Collapse all code blocks
Ctrl+⇧­Shi­ft+­"Num Keypad *"
Open all code blocks
⇧Shift (and hover over element)
Show source (in tooltip)
settings: Window → Prefer­ences → Java → Editor → Hovers

Outline View

Reorder class members with Drag & Drop
Disable "Sort Order" - otherwise not possible
 
Automatic reorde­ring: Select the class, Source → Sort Members

Package / Project Explorer

Alt+F5
Maven → Update Project...

Problems View

Configure to view only warnings and errors associated with a particular resource or group of resources
Problems View - Configure Contents e.g. select "on any element in same projec­t" to restrict to current selected project
 

Templates (Java → Editor → Templates)

test
Created test method
for
Creates for loop
new
Creates new instance
try
Creates try..catch
sysout, syserr, systrace
Creates System.out...
strf
Format string
if
if null/if not null
for
iterate over map
static­_final
static final field
before
junit before method
after
junit after method
before­class
junit before­class method
afterclass
junit afterclass method
quote
surround selection with quotes
Tip: It is possible to select text and use completion (Ctrl+␣) including typing of template name

Changed Eclipse Keybin­dings

Windows → Prefer­ences → General → Keys

Required modifi­cations due to the german QWERTZ keyboard layout:
1. Add Block Comment - new: Ctrl+⇧­Shi­ft+7, old: Ctrl+⇧­S­h­ift+/
2. Remove Block Comment - new: Ctrl+⇧­Shi­ft+ß, old: Ctrl+⇧­S­h­ift+\
3. Toogle Split Editor (Horiz­­ontal) - new: Ctrl+⇧­Shi­ft+-, old: Ctrl+_
4. Toogle Split Editor (Vertical) - new: Ctrl+⇧­Shi­ft+­<, old: Ctrl+{

Update 12/2016: had to add ⇧Shift to 3. and 4. because of new Eclipse Neon Zoom functi­onality with Ctrl+-

Project Specific Config­uration

1. Import project Java formatter config­uration
2. Download Checkstyle config­uration file from sonar server and reference the config file as a file resource url
3. Download Findbugs config­uration file from sonar server and add the config file under "­include filter files"
4. Download PMD config­uration file from sonar server and first "­clear all" existing rules and then import the config file

Plugins

Testing Support
 
Test Coverage
Source Code Analyzer
 
 
 
 
Ignore certain warnings with //NOSONAR or @Suppr­ess­War­nin­gs(­"­squ­id:­S00­112­")
Refact­oring
Subversion Eclipse Team Provider Plugin
 
use Subclipse instead of Subversive because it is much faster
 
Task based working
 
 
Maven integr­ation
 
add needed m2e connec­tors. follow pom.xml hints/­pro­blems. e.g:
m2e project config­urators for Eclipse WTP
   
m2e connector for build-­hel­per­-ma­ven­-plugin
   
m2e connector for the Eclipse JDT Compiler
   
m2e connector for the Maven Dependency Plugin
   
Groovy­-Ec­lipse m2e integr­ation
Decompiler

XUbuntu specific Config­uration Changes

Delete following keybin­dings in XFCE Settings → Window Manager → Keyboard:
1. Ctrl+A­lt+↓/↑
2. Ctrl+F6
3. Alt+F5


If running IBus-A­pplet delete keybinding definition for "­Ctr­l+S­pac­e" (Content Assist) in IBus-S­ettings


Use gnome-­col­or-­chooser and change options:
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). You can force Eclipse 4.5 and higher to use GTK2 with the following export or change GTK3 theme options: export SWT_GTK3=0
2. Tooltip colors (backg­round: yellow, foregr­ound: black)
3. Global colors → Input field selected (foreg­round: black)


Disable "­pin­k/p­urple highli­ght­s" in Xubuntu 14.10 and higher: disable custom hightl­igh­t-color in gtk-th­eme­-config

Settings

show "." files in package explorer
"­Package Explorer → View Menu → Filters → uncheck .*" or "­Package Explorer → Customize View… → Filters → uncheck .*"
Package Explorer Option "Link with editor­"
Link file to package explorer
Favorites Imports
Windows → Prefer­ences → Java → Editor → Content Assist → Favorites, New Type...
 
Add types for Assertion library Hamcrest and/or AssertJ, Mockito and JUnit-­Assert
Show line numbers
Window → Prefer­ences → General → Editors → Text Editors → "Show line number­s"
Show print margin
Window → Prefer­ences → General → Editors → Text Editors → "Show print margin­"
Paste multiline strings
Window → Prefer­ences → Java → Editor → Typing → "­Escape text when pasting into a string litera­l"
 
 
MoreUnit Config­uration
Test source folder: "­src­/te­st/­jav­a"
 
Test Type: "­Jun­it4­"
 
uncheck "Use test-p­refix for test-m­eth­ods­"
 
Rule for naming test files → Pattern: ${srcF­ile­}(T­est­|IT­|IT­Case)
 
if you have legacy tests with Test prefix: Rule for naming test files → Pattern: (Test)­${s­rcF­ile­}(T­est­|IT­|IT­Case)
Formatter Options
Window → Prefer­ences → Java → Code Style → Formatter → Off/On Tags for //@for­mat­ter:off and //@for­mat­ter:on
 
Check the Never join lines preference accessible on the Line Wrapping and the Comments tabs of the Java Formatter preference page
Improve Perfor­mance
Window → Prefer­ences → Valida­tion, Disable All
 
Add -Xveri­fy:none to eclips­e.ini
tell the VM not to validated all the .class files it is loading
 
Window → Prefer­ences →General → Startup and Shutdown
remove plugins not needed
 
increase -Xms and -Xmx heap memory options (start and max) in eclipse.ini
e.g. -Xms512m -Xmx2048m
 
increase -XX:MaxPermSize option (if java < 1.8)
e.g. -XX:MaxPermSize=512m
Enable inform­ative Eclipse Compiler Warnings
Window → Prefer­ences → Java → Compiler → Errors­/Wa­rnings
set to Warning and keep sub checkboxes checked (if any)
 
Potential Progra­mming problems
Potential resource leak
 
Unnece­ssary code
Value of parameter is not used
   
Unused type parameter
   
Unnece­ssary declar­ation of thrown exception
   
Unnece­ssary 'else' statement
   
Unnece­ssary cast of 'insta­nceof' operation
 
Generic types
Redundant type arguments (1.7 and higher)
 
Annota­tions
Unhandled token in '@Supp­res­sWa­rnings' set to "­Ign­ore­"
 
Null analysis
Redundant null check
Window → Prefer­ences → XML Files → Editor
Select "­Indent using spaces­" and set "­Ind­ent­ation Size: 4"
 
Window → Prefer­ences → General → Editors → Text Editors
Set "­Dis­played tab width: 4" and select "­Insert spaces for tabs"
Save Actions
Window → Prefer­ences →Java →Editor → Save Actions
 
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 following:
Code Style
"Use blocks in if/whi­le/­for/do statem­ent­s"
 
Use lambda where possible
if you use Java >= 8
Add final modifier to private fields*
Add final modifier to private fields
 
Add final modifier to local parameter
 
Add final modifier to local variables
Unused Code
Remove unused imports
 
Add missing '@Over­ride' annota­tions
 
Add missing '@Over­ride' annota­tions to implem­ent­ations of interface methods
 
Add missing '@Depr­ecated' annota­tions
 
Remove unnece­ssary casts
 
Remove unnecessary '$NON-NLS$' tags
Limit maximum number of open editors
Window → Prefer­ences → General → Editors
 
check "­Close editors automa­tic­all­y"
 
choose value (e.g. 20) for "­Number of opened editors before closin­g"
Window → Prefer­ences → Java → Compiler → Errors­/Wa­rnings, Section Null analysis
if you use Java < 8 (cannot use Optional) and cannot use Guava Optional e.g. for legacy projects
 
check "Enable annotation-based null analysis"
Maven
Window → Prefer­ences → Maven → User Interface
 
check "Open XML page in the POM editor by defaul­t"
Reason: show pom.xml source code is faster than loading the "­Ove­rvi­ew" tab all the time
JUnit
Window → Prefer­ences → Java → JUnit enable "Add 'ea' to VM arguments when creating new JUnit launch config­ura­tio­n"
enable JVM assertions by default
Show heap memory status
Window → Prefer­ences → General
enable "Show heap status­"
Window → Prefer­ences → General → Editors → Text Editors → Quick Diff
enable checkboxes and select correct reference source option
x¹: TDD-Style mockito: org.mockito.Mockito, BDD-Style mockito: org.mockito.BDDMockito, org.junit.Assert, org.hamcrest.Matchers, org.assertj.core.api.Assertions
x²: Java → Editor → Templates

General

Refresh all Projects (with some closed in between)
In Package Explorer
Ctrl+A, F5
Use Working Sets for better perfor­mance
Package Explorer → open the drop-down menu → Select Working Set
 
If Ctrl+⇧­S­h­ift+R and Ctrl+⇧­S­h­ift+T does not reflect active Working Set check the small arrow on the top right of the dialogue to select Working Set

Troubl­esh­ooting Projects

Maven dependency issues
try without eclipse project resolution
[Project] → Properties → Maven
   
uncheck "­­Re­solve depend­­encies from Workspace projec­­ts­" to check with jars from local
~/.m2
repository instead of eclipse projects within worksp­ace­/wo­rki­ngset
 
clean projects
don't mix usage of maven CLI and m2e eclipse plugin
   
if mixed - make a
mvn eclips­e:clean
(CLI) and import again in eclipse
 
Error message
The archive: <pa­th_­to_­jar­_fi­le> which is referenced by the classpath, does not exist.
find project with
.classpath
file where old/wrong jar is referenced
   
make a
mvn eclips­e:clean
(CLI) and import again in eclipse
   
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' {} \;
                               
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet