Saturday 16 March 2013

The Definitive Guide to Learn JetBrains ReSharper Shortcuts in Visual Studio

JetBrain ReSharper is an amazing tool that enhance the productivity of writing code and brings it at a completely new level.

I am working with ReSharper from a while now and I realized that I was not taking full advantage of it. One of the reason is because I didn't know all the possible shortcuts available and I often relied on the mouse to accomplish a task.

The typical excuse is (from the The Productive Programmer Book):
I know there's a keyboard shortcut that does this, but I'm in a hurry, so I'll use the mouse instead and look up that keyboard shortcut late. 
The fact is that:
Later never comes.
OK, good. I don't want to be lazy. It's time to learn it.

What do you do?

You go to the ReSharper Official Website and you download the ReSharper 7 Keymap. You spend some time experimenting and you decide to print the Keymap and keep it close to your desk. You try to use the keymap as much as you can, but after a while you are already completely immersed in your work that you forget to look at it and you continue to do the same as before. Maybe you just learnt only a  single shortcut.

Why this happens?

Because learning shortcuts in that way and all of them together is extremely boring. Even if you are completely aware that learning them would make you a more productive developer you don't do that because it is so boring.

Why then not learning the shortcuts while you work without upfront preparation?

It doesn't work! You know what will be the excuse at the end. In addition, you might not even know that in some situation there is a ReSharper functionality available to help you in that particular context.

I think that the way to go is the middle and the process can be split in two steps:
  1. Learn what are the ReSharper features and the most important shortcuts
  2. Learn new shortcuts while you work
OK, but what are the most important shortcuts?

This is finally the right question to ask!

Because learning shortcuts is extremely boring why not consider to learn first the shortcuts that gives you access to other shortcuts based on the current context? In that way, you could learn new shortcuts during your work. This, in some way, is similar to have a person close to you telling what the shortcut is.

You don't need to print a Keymap in that case!

You know how to see a contextual Keymap straight in the editor while you work that is much better!

OK, at this point let's see the 10 Most Important Shortcuts you need to learn.

1) Navigate To: ALT + `

This shortcut satisfy all your navigation needs based on where the caret is in the code editor.


2) Generate Code: ALT + INS

3) Refactor This: CTRL + SHIFT + R

This shortcut satisfy all your refactoring needs based on where the caret is in the code editor.

4) Go To Type: CTRL + T

This shortcut is fundamental to jump immediately to a specific type in your code base. In ReSharper 7 you also need to be able to jump to a specific symbol or file using two additional shortcuts. I am not reporting these shortcuts here because JetBrain announced that ReSharper 8 will add this ability using this single shortcut as a Go To Everything feature.

5) Quick Fix: ALT + ENTER

While you code, this shortcut provides you a context menu with the list of possible quick fixes.

6) Go To Next/Previous Member: ALT + Up/Down

These shortcut allows you to quickly move between members in a class.


7) Insert Live Template: CTRL + E, L

This shortcut allows you to insert a live template (included your custom templates).
8) Inspect This: CTRL + SHIFT + ALT + A

This is a shortcut to the code exploration features.

9) Run Unit Tests: CTRL + U, L

Runs all the unit tests in the solution.


10) Go Back
: CTRL + -

This is an interesting shortcut that I find very useful. When you navigate to a declaration or implementation after your exploration you often want to come back to the original location. This shortcut allows you to go back to the previous caret position. 

I can't work anymore without this shortcut.
Open ReSharper Menu: ALT + R

This shortcut is not actually a ReSharper shortcut but the simple Visual Studio Shortcut to the ReSharper Menu. All the previous shorcuts that I presented open the door to almost all the ReSharper features but not all of them. This is why it is important sometimes to visit the ReSharper Menu to check what are the others available shortcuts. This in some why represent your Keymap always available to you inside the editor. Keep it in mind.


Complete List

I hope that you found this post useful.

For convenience, this is the list of all the most important shortcuts together:
  1. Navigate To: ALT + `
  2. Generate Code: ALT + INS
  3. Refactor This: CTRL + SHIFT + R
  4. Go To Type: CTRL + T
  5. Quick Fix: ALT + ENTER
  6. Go To Next/Previous Member: ALT + Up/Down
  7. Insert Live Template: CTRL + E, L
  8. Inspect This: CTRL + SHIFT + ALT + A
  9. Run Unit Tests: CTRL + U, L
  10. Go Back: CTRL + -
  11. Open ReSharper Menu: ALT + R
OK, now is time to work and be productive ;)