Be an expert at using your tools so you can concentrate on solving problems! I couldn't find a short and practical IntelliJ shortcuts cheat sheet, so here are the ones I generally use, categorised by activity.
The OG shortcuts
-
SHIFT + SHIFT
- the IntelliJ search for anything including files, actions, symbols etc... press tab to be more specific. -
OPTION + ENTER
- gives you a list of things you can do depending on where you are. For example, if you are in the middle of an argument list you can put all arguments in one line or multiple lines or add the argument names. This is one example of MANY. Just keep pressing it. -
CMD + SHIFT + V
- a log of all the recent things in your clipboard (this is interestingly one of the most useful things).
Navigating the code
Hopping around the codebase to follow a trail is probably what you spend a lot of your time doing. You
might as well be super efficient at it!
-
CMD + B
- declarations of the variable/function -
CMD + OPTION + B
- implementations of the interface/function -
CMD + U
- go UP to the interface it implements -
CMD + E
- got to recent files -
F2
- go to next error -
CMD + 1
- view project sidebar -
CMD + [
- back -
CMD + ]
- forward -
CMD + F12
- view the structure of the file -
CMD + SHIFT + BACKSPACE
- go to the last edited bit of code -
CTRL + SHIFT + DOWN/UP KEY
- hop down or up the methods in the file -
CMD + UP
- navigate up the hierarchy -
CMD + ,
- IntelliJ settings -
OPTION + F12
- go to terminal -
CMD + W
- close tab
Refactoring
Ninja developer level.
-
OPTION + T
- when your cursor is on the function, this shortcut will give you a menu of what you can do (some of the most common ones are listed below) -
CMD + SHIFT + V
- extract to a variable -
CMD + SHIFT + N
- inline variable -
CMD + SHIFT + M
- extract to a method -
CMD + F6
- change signature of the function (it will automatically update it everywhere it's used) -
SHIFT + F6
- rename variable -
F6
- move class/interface/function to a different file -
CTRL + OPTION + O
- (not zero but the letter "O") to optimise imports -
CMD + SHIFT + DOWN
- when your cursor is on the name of the function/class, use this to move the whole block -
CMD + SHIFT + ENTER
- IntelliJ will autocomplete the block like "if" or "when" -
CMD + OPTION + SHIFT + L
- reformat the whole file -
OPTION + OPTION + DOWN KEY
- multiple curses in the same location on the next line -
OPTION + UP/DOWN KEY
- Expand/shrink highlighted code within bounded contexts -
CMD + SHIFT + F
- find all -
CMD + SHIFT + R
- replace all -
CTRL + G
- highlight text and use this shortcut, it will find the next bit that matches that code one by one with a cursor and then you can edit it
Tests
-
CMD + R
- re-run the previous test -
CMD + SHIFT + R
- run the test your cursor is on -
CMD + N
- in the test class, this shortcut will provide you with a menu of options to create test/setup/teardown func -
CMD + SHIFT + D
- debug the test you are on
Actions
CMD + SHIFT + A
- the ultimate shortcut to access the IntelliJ action window. Once you are here you can search for any action you want to do. Here are some of the ones I use:
- Enable soft-wrap
- Split screen and move right
- Open blank diff window
- Zoom
Git
-
CMD + T
- git stash, git rebase/merge, git pop - done automatically -
CMD + OPTION + N
- when you are on the git window, use this shortcut to create a branch -
CMD + K
- commit -
CMD + SHIFT + K
- push
Create your own
Templates
You can do magic. You can create templates linked to particular words. For example, you can configure IntelliJ to spit out this code when you write the word "test":
@Test
fun `$NAME$`() {
$END$
}
The cursor will automatically be at $NAME$
so you can immediately type out the name. When you press enter, the cursor jumps to $END$
which will allow you to land in the right place to write your test.
P.s. this particular helper already exists in IntelliJ (listed above). Within a test class, use CMD + N
and a list of options will pop up to create a test / set up / tear down func.
Settings -> Editor -> Live templates -> Kotlin (for example) -> Add a template
Keyboard shortcuts
Settings -> Keymap
- this is tricky because there could be clashes with other MAC/IntelliJ shortcuts
Practice makes perfect
Refactoring golf is a fun exercise to practice!
Bonus - Google Chrome shortcuts
-
CMD + T
- new tab -
CMD + SHIFT + T
- re-open closed tab -
CMD + [
- back -
CMD + ]
- forward -
CTRL + TAB
- hop to next tab -
CMD + W
- close tab -
CMD + N
- new Chrome window -
CMD + BACKTICK
- tab to other Chrome window -
F12
- open developer tools -
CMD + TAB
- go to different application
If you know any other exciting shortcuts, leave a comment.
Top comments (0)