DEV Community

Riya Dattani
Riya Dattani

Posted on

IntelliJ Shortcuts (for Mac)

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

  1. SHIFT + SHIFT - the IntelliJ search for anything including files, actions, symbols etc... press tab to be more specific.
  2. 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.
  3. 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!

  1. CMD + B - declarations of the variable/function
  2. CMD + OPTION + B - implementations of the interface/function
  3. CMD + U - go UP to the interface it implements
  4. CMD + E - got to recent files
  5. F2 - go to next error
  6. CMD + 1 - view project sidebar
  7. CMD + [ - back
  8. CMD + ] - forward
  9. CMD + F12 - view the structure of the file
  10. CMD + SHIFT + BACKSPACE - go to the last edited bit of code
  11. CTRL + SHIFT + DOWN/UP KEY - hop down or up the methods in the file
  12. CMD + UP - navigate up the hierarchy
  13. CMD + , - IntelliJ settings
  14. OPTION + F12 - go to terminal
  15. CMD + W - close tab

Refactoring

Ninja developer level.

  1. 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)
  2. CMD + SHIFT + V - extract to a variable
  3. CMD + SHIFT + N - inline variable
  4. CMD + SHIFT + M - extract to a method
  5. CMD + F6 - change signature of the function (it will automatically update it everywhere it's used)
  6. SHIFT + F6 - rename variable
  7. F6 - move class/interface/function to a different file
  8. CTRL + OPTION + O - (not zero but the letter "O") to optimise imports
  9. CMD + SHIFT + DOWN - when your cursor is on the name of the function/class, use this to move the whole block
  10. CMD + SHIFT + ENTER - IntelliJ will autocomplete the block like "if" or "when"
  11. CMD + OPTION + SHIFT + L - reformat the whole file
  12. OPTION + OPTION + DOWN KEY - multiple curses in the same location on the next line
  13. OPTION + UP/DOWN KEY - Expand/shrink highlighted code within bounded contexts
  14. CMD + SHIFT + F - find all
  15. CMD + SHIFT + R - replace all
  16. 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

  1. CMD + R - re-run the previous test
  2. CMD + SHIFT + R - run the test your cursor is on
  3. CMD + N - in the test class, this shortcut will provide you with a menu of options to create test/setup/teardown func
  4. 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

  1. CMD + T - git stash, git rebase/merge, git pop - done automatically
  2. CMD + OPTION + N - when you are on the git window, use this shortcut to create a branch
  3. CMD + K - commit
  4. 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$
}
Enter fullscreen mode Exit fullscreen mode

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

  1. CMD + T - new tab
  2. CMD + SHIFT + T - re-open closed tab
  3. CMD + [ - back
  4. CMD + ] - forward
  5. CTRL + TAB - hop to next tab
  6. CMD + W - close tab
  7. CMD + N - new Chrome window
  8. CMD + BACKTICK - tab to other Chrome window
  9. F12 - open developer tools
  10. CMD + TAB - go to different application

If you know any other exciting shortcuts, leave a comment.

Top comments (0)