My Custom Intellij Shortcuts and Live Templates (some based on Eclipse)

My Custom Intellij Keymap Shortcuts.doc

Navigate to Type Ctrl+Shift+T/Ctrl+N
Navigate to File/Resource Ctrl+Shift+F/Ctrl+Shift+R/Ctrl+Shift+N
Navigate to Symbol Ctrl+Shift+S/Ctrl+Shift+Alt+N
Navigate to JUnit Ctrl+Shift+J
Navigate to Last edit location Ctrl+Shift+L/Ctrl+Shift+Backspace
Navigate back // forward Alt+Left/Ctrl+Alt+Left  // Alt+Right/Ctrl+Alt+Right
Navigate next // previous error Alt+. // Alt+,
Navigate to Type // Call Hierarchy F4 // Ctrl+H // Ctrl+Alt+H
Navigate/Go to Line Ctrl+L/Ctrl+G
Navigate to declaration F3/Ctrl+B
Navigate to implementation Ctrl+T/Ctrl+Alt+B
Navigate to Bookmark – Show // Toggle/Add Alt+Shift+B,B/S /  Shift+F11 // Alt+Shift+B,T/A /  F11
Go to references/Find usages Ctrl+Shift+G /Alt+F7
Find in file // Find in paths Ctrl+F/Alt+F3 // Ctrl+Alt+Shift+F
Search everywhere Shift x2 (double Shift)
Quick Documentation Ctrl+D/Ctrl+Q/Ctrl+2ndButton Click
Quick Outline (File Structure) Ctrl+O/Ctrl+F12
Quick switch Editor rEcent open//modified files Ctrl+E/Ctrl+Tab // Ctrl+Shift+E
Quick error description Ctrl+2/Ctrl+F1
Structured selection extend // shrink Alt+Shift+Up/Ctrl+W // Alt+Shift+Down/Ctrl+Shift+W
Refactor This Alt+Shift+T/Ctrl+Shift+Alt+T
Rename Alt+Shift+R/Shift+F6
Extract Method Alt+Shift+M/Ctrl+Alt+M
Change method Signature Alt+Shift+C/Ctrl+F6
Extract Local (Variable) Alt+Shift+L/Ctrl+Alt+V
Source generate Alt+Shift+S/Alt+Insert
Move line down/up Alt+Down/Up
Inline Alt+Shift+I/Ctrl+Alt+N
Join lines Alt+Shift+J
Extract Field Ctrl+Alt+F
Extract Constant Ctrl+Alt+C
Auto-Indent Ctrl+Alt+I
Organize/Optimize imports Ctrl+Shift+O/Ctrl+Alt+O
Template // Surround by template Ctrl+Alt+T / Ctrl+J // Ctrl+Alt+J
Replace // Replace in paths Ctrl+R // Ctrl+Alt+Shift+R
Re-Format // Re-format dialog Ctrl+Shift+F / Ctrl+Alt+L // Ctrl+Alt+Shift+L
Statement completion Ctrl+Shift+Enter
File rename F2
Quick fix (Intention) Ctrl+1/Alt+Enter
New – Java/Class //Package/Directory//File Ctrl+Alt+N,J/C // P/D // F
Run already selected // Choose and Run Alt+Shift+X,R/Shift+F10//Alt+Shift+X,Shift+R/Alt+Shift+F10
Run Test // Rerun Failed Tests Alt+Shift+X,T/Shift+F10//Alt+Shift+X,Shift+T/Alt+Shift+X,F
Run Inspection Alt+Shift+X,I/Ctrl+Alt+Shift+I
Debug already selected // Choose and Debug Alt+Shift+X,D/Shift+F9//Alt+Shift+X,Shift+D/Alt+Shift+F9
VSC-VSC dialog/Commit/Update/History/Revert/Push Alt+Shift+V,V/C/U/H/R/P
Diff // Next change // Previous change Ctrl+D // Ctrl+Alt+./Ctrl+Shift+.  // Ctrl+Alt+,/Ctrl+Shift+,
Maximize/Minimize editor Ctrl+M/Ctrl+Shift+F12
Close tool window Shift+Escape
Code folding expand (+)/collapse all () Ctrl+Shift+Plus/Minus
Settings Ctrl+Alt+S
Switch Keymap/color/code style scheme… Ctrl+`
Go to Tool Window e.g. Project/VCS Alt+ e.g. Alt+1 / 9
Find by Action Ctrl+Shift+A

Live templates:
1. abbreviation: logger; description: SLF4J logger template text:

private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger($CLASS_NAME$.class);$END$

applicable: in Java declaration; edit template variables: name: CLASS_NAME, expression: className(), default value: , skip if defined: checked;

2. abbreviation: mock; description: Mockito.mock, template text:

$TYPE$ $VAR$ = org.mockito.Mockito.mock($TYPE$.class);

applicable: in Java statement, declaration; edit template variables: name: TYPE, expression: expectedType(), default value: “java.lang.Object”, skip if defined: checked; name: VAR, expression: suggestVariableName(), default value: “mock”, skip if defined: not checked;

3. abbreviation: test; description: Given-When-Then Junit template, template text:

@org.junit.Test
public void $TEST_METHOD_NAME$() {
 // given
 $END$

 // when

 // then

}

applicable: in Java declaration; edit template variables: name: TEST_METHOD_NAME, expression: , default value: “should”, skip if defined: not checked

4. abbreviation: list; description:Arrays.asList, template text:

java.util.List<$TYPE$> $VAR$ = java.util.Arrays.asList($END$);

applicable: in Java statement, declaration; edit template variables: name: TYPE, expression: expectedType(), default value: String, skip if defined: checked, name: VAR, expression: suggestVariableName(), default value: list, skip if defined: not checked

5. abbreviation: arraylist; description: create ArrayList, template text:

java.util.List<$TYPE$> $VAR$ = new java.util.ArrayList<>($END$);

applicable: in Java statement, declaration; edit template variables: name: TYPE, expression: expectedType(), default value: String, skip if defined: checked, name: VAR, expression: suggestVariableName(), default value: list, skip if defined: not checked

6. abbreviation: hashmapdescription: create HashMap, template text:

java.util.Map<$KEY_TYPE$, $VALUE_TYPE$> $VAR$ = new java.util.HashMap<>($END$);

applicable: in Java statement, declaration; edit template variables: name: KEY_TYPE and VALUE_TYPE, expression: expectedType(), default value: String, skip if defined: checked, name: VAR, expression: suggestVariableName(), default value: map, skip if defined: not checked

7. abbreviation: private static final, template text:

private static final $END$;

8. abbreviation: private final, template text:

private final $END$;

9. abbreviation: foreach (copy of Intellij iter)
10. abbreviation: sysout (copy of Intellij sout)
11. abbreviation: main (copy of Intellij psvm)

Intellij fix suggestions (out of the box):
– redundant explicit array creation for calling varargs method (suggests to change new String[] { "arg1", "arg2" } to "arg1", "arg2" )
– duplicate code, offers navigation to  duplicate
– namespace declaration never used (suggestion to remove)
– find usages of a file (Ctrl+Shift+G /Alt+F7)
– inject Language/Reference (inside string double quotes press Ctrl+F1/Alt+Enter) and choose regex or html etc, then inside regex string press again Ctrl+F1/Alt+Enter to check sample text against the defined regex.

autocompletion: either camel case letters (e.g. ‘np’ for stringNamePatterns) or part of the name  (e.g. ‘Collectors.lis’ for ‘Collectors.toList()’)

parameter name hints for literals and null values in method call annotated by parameter name:

 string.split(<em>regex:</em> " ")

enabled by default

Additional Intellij setup:
Settings/Editor/General/Auto Import/
check: Optimize imports on the fly
check: Add unambiguous imports on the fly

Settings/Editor/Code Style/Java: Wrapping and Braces tab: Chained method calls: change from: ‘Do not wrap’ to ‘Chop down if long’ and check ‘Align when multiline’

Settings/Editor/Inspections/Java/Language level migration aids: check ‘foreach loop can be collapsed with Stream API’, ‘Raw use of parameterized class’

Customizing ubuntu to make cmd button work like ctlr button:
1. System settings -> Text Entry -> Add input source: English (Macintosh) and remove other languages
2.sudo apt-get install gnome-tweak-tool

open gnome-tweak-tool -> typing -> Alt/Win key behavior -> choose: ctrl is mapped to Win keys

Alternatively make Intellij use cmd (win/super) key in virtual box:
1. System settings -> Text Entry -> Add input source: English (Macintosh) and remove other languages
2. sudo apt-get install compizconfig-settings-manager and remove laucher (empty text) for
3. Intellij -> Help -> Edit custom properties -> add line: keymap.windows.as.meta = true

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s