Tag: shortcuts

My Mac OSX custom Intellij shortcuts

Navigate: class cmd O, additional ctrl shift T
Navigate file: cmd shift O, added ctrl shift R (removed run context configuration)
Navigate declaration, cmd B, added F3 (removed toggle bookmark)

Find usages: alt F7, added ctrl + shift + G (removed: unselect occurrences)

Find: cmd +F, added ctrl+ F (removed: right in editor actions)
Navigate File structure: cmd + F12, added ctrl + O (removed: override methods)

Refactor this: ctrl +T , added alt + shift + T (removed: switch task)
Rename: shift + F6, added alt + shift + R (removed: rerun tests)
Extract variable: alt+cmd+V, added alt + shift + L
Extract method: alt+cmd + M, added alt + shift + M
Duplicate line: added: alt+shift+D (removed cmd+D)
Hide all tool windows: shift + cmd + F12, added ctrl + M (removed: move caret to matching brace and commit message history)
Preferences: cmd + , added ctrl + alt + s
Show intention actions: alt + enter, added ctrl + 1 (Remove Go to bookmark 1)
Next highlighted error: F2, added ctrl+ . (removed: Choose lookup item and insert dot), added alt + .
Previous highlighted error: shift + F2, added ctrl+ , added alt + .
Reformat code: alt + cmd + L, added: ctrl + shift + F
Inline: added: alt + shift + I
Inline: alt + cmd + N, added alt + shift + I (removed: inspect code with editor settings)
Source code generate: cmd + N, ctrl + Enter, additionally: alt + shift + S
Extract field: alt + cmd + F, additionally alt + shift + F(removed: add to favorites)
Extract constant: alt + cmd + C, additionally: alt + shift + C (removed: recent changes)
**Extend/shrink selection: original: alt + up arrow/alt + down arrow changed to: alt + shift + arrow Up/Down, added additionally ctrl +W / ctrl + shift + W
Find in path: shift + cmd + F, added additionally: ctrl + alt + shift + F
Replace in path: shift + cmd + R, added additionally: ctrl + alt + shift + R
**Move line up: original: alt + shift + arrow Up/Down changed to: alt + arrow Up/Down
Organize imports: ctrl + alt + O, additionally: ctrl + shift + O, alt+shift+O
Navigate to Test/Junit (junit) added: ctrl + shift + J (removed: join lines), ctrl+shift+alt+T
Join lines: added: alt+shift+J
Navigate type declaration: shift + cmd + B (removed shift + ctrl +B), added: shift + ctrl + D
Navigate declaration: added F3
Navigate Super method: added: ctrl + shift + U or added: ctrl + shift + M
Navigate bookmark show: added shift + ctrl + B, added alt + shift + B, S
Bookmark add: added ctrl + B, added alt+ shift +B, A
Navigate bookmark menu: added ctrl + shift + alt + B, added alt+ shift +B, B (removed navigate type declaration)
Complete statement: ctrl + shift + Enter
Navigate to last edit location: ctrl + shift + E
Navigate line number: ctrl + shift + L

** Rename: alt + shift + R (removed: rerun tests)

** Run/Debug context configuration original: run context configuration alt + shift + R,(removed: run/debug in main menu)

ctrl+R/D – run/debug selected class in editor
ctrl+alt+R/D – run selected class in run/debug menu
ctrl+alt+cmd+R/D – serun/debug from menu

Added cmd+0, alt+0 terminal

Existing:
cmd + shift + T: navigate/create test
ctrl + Enter -> accept highlighted button in popup

VCS
Update: added cmd + U, added ctrl + U or added alt + shift + V, U
Diff: existing cmd + D (compare with local in vcs view)
Compare with same repository version: cmd+shift+D
Compare with local version: alt+shift+V, D
Compare with latest repo version: alt+shift+V, Shift+D

Prev/next difference: added ctrl + alt + ,/.
Push: existing alt + shift + K, or added: alt + P, or added: alt + shift + V, P
Revert: added alt + shift + V, R or added alt + R
History: added alt + H or added: alt + shift + H

Existing: View Parameter Info: cmd + P, added ctrl + P

Run: alt + shift + X, R
Run…: alt + shift + X, Shift + R
Debug: alt + shift + X, D
Debug…: alt + shift + X, Shift + D
Rerun tests: alt + shift + X, T
Rerun failed tests: alt + shift + X, Shift + T or alt + shift + X, F

Quick documentation: ctrl + Q
Navigate back/forward: added ctrl+alt+left/right arrow, added: alt+cmd+left/right arrow
Navigate Last edit location added: ctrl+shift+L
Navigate to line: cmd + L or added ctrl + L
Navigate bookmark: added ctrl + shift + B
Navigate to recently edited files: cmd+shift + E, ctrl+shift+E
Navigate to recent files: cmd+E, ctrl+E

Highlight usages in file: ctrl + F, ctrl + G

Generate source: added alt + shift + G
Find by action: added ctrl + shift + A
Ctrl + N added: new (Java, Scala)

Project Defaults -> Project Structure -> search sdk

Scala
Preferences-> Languages and Frameworks/Scala -> Show type info on mouse hover
Alt+Enter when cursor on valu/method -> Add type annotation to value definition
run scala console: cmd+shift+S

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