I’ve had to recently renew my personal license for Resharper Ultimate and I realised it’s been almost 8 years now since I started using Resharper with Visual Studio. Yes, 8 years. This tool is so good I can’t code (and therefore live) without Resharper installed. I know that Visual Studio 2017 has upped its game with regards to Productivity (about time!) but it still comes behind Resharper in that side of things.
So this post is dedicated to Resharper where I will go through my top 5 favourite Resharper shortcuts.
Ctrl+T – go to any Thing
Instead of heading to the Solution Explorer and expanding a thousand times to get to a class file, you can just let Resharper do some work for you:
- Ctrl+T and type the name of the file
- Ctrl+T and type the initials of the file
- Ctrl+T and type the folder + <space> + View name (i.e. StandardPage Index)
- Ctrl+T will retrieve the latest opened files
Your brain needs to focus on what you’re developing. Ain’t got time for remembering which project, folder, subfolder, your class belongs to. I probably use this command at least 20x a day. If each time you navigate within the tree is equivalent to one minute of savings (you need to consider this momentum killer cos by the time you find the class you probably already forgot why you had to go there), that’s 20 mins of savings each day.
Alt+Enter – quick fixes
This feature is very useful. Resharper does on-the-fly analysis of your code and when it thinks there’s an error or a better way of doing things, it underlines your code with various colours (depending on severity) to which you can Alt+Enter to. Resharper will then bring up a list of suggestions of how you may improve/fix the code. Hitting enter again will allow Resharper to fix your own code. Here are a some examples:
- Unresolved references are fixed
- Redundant/unused code is removed
- Non-existent classes/methods/files are generated
- Class/method/variable naming are of standard
- Code is refactored, including shortening code if possible
The list could easily grow very long and this is one of the main reasons why I need Resharper. All the boring stuff it can do for you as you’re coding. Again, your brain needs to focus on the more important stuff. Just like Mark Zuckerberg’s same shirt day policy. The brain is too important for deciding which clothes to wear for the day.
Ctrl E+C – clean up and format code
I don’t know why they chose those combinations but the way I made it stick to me is that E+C means EASY on the eye. Whenever you feel like your HTML is unreadable because of the messy indents, just highlight your code and hit Ctrl E+C. It will clean up your code, which includes:
- Applying file layout (indents applied, extra empty lines removed, etc)
- Adding/removing braces for “if/else”, “for”, “foreach”, etc
- Removing redundant parentheses
- Removing code redundancies
- Arrange qualifiers
The rules above are configurable. So if you have a big team and would like the code to look like there’s not 16 different people who wrote it but one, then it’s probably a good idea to get all your devs to start using the formatting feature of Resharper. I’ve been part of a project where there really was 16 devs at one time in a project and this feature really helped.
Ctrl R+R – Refactor + Rename
There are times when you’ve written a few lines of code and realise your variable name needs to be renamed. The longest way to do it is obviously just to simply go thru each occurrence and rename it. And that’s fine but imagine yourself halfway thru the rename and a co-worker just disrupted your focus and your code’s broken and you just want to curse that colleague of yours cos you lost track of where you were.
Of course most editors also have that “replace” feature which you sure can you use. But it’s replace function is dumb cos it can also rename those that shouldn’t. Resharper’s rename function is smarter as it only renames those that should because it understands your code (i.e. references, even comments if you allow it to)
- Ctrl R+R will highlight your variable/method/class
- You then type the new name and hit Enter
- Resharper will also rename all valid references
Ctrl R+M – Refactor + extract to Method
Okay this command I probably can live without but I am including it here because I do use this from time to time. It’s like that 2nd coffee for the day you can live without (I’m not talking to you coffee addicts) but you still end up having pretty much every single day.
This feature comes useful when you write several lines of code and realise later that those lines of code can be reused and are better off in a whole new method. Instead of manually copy/pasting these lines outside and changing the method call, Resharper allows you to refactor your code by automating the extract to a method. If you haven’t used this before, you should try it once! You probably won’t resort to manual copy/pasting anymore.
There’s a bunch of refactoring shortcuts in Resharper that are available:
- Ctrl R+D – Safe delete variables/methods/classes. Resharper will only continue deleting if it’s unused
- Ctrl R+I – Inlining where possible
- Ctrl R+V – Introduce variable
And that’s only touching 2% of it
Resharper has so much more to offer. It has code generation techniques and various kinds of code templates. It also can generate a report about the quality of your code which is amazeballs. It has a powerful unit test runner for those TDD experts. It has language-specific intellisense. Seriously I could go on all day here.
If you want to find out more about the features, head up to the Resharper Features page.
Feel free to post your favourite Resharper shortcut on here! 🙂