Visual Studio Shortcuts

29 October 2017

I always want to be as efficient as possible when I’m using my everyday tools. When Visual Studio 2015 and 2017 came to Unity I immediately switched to it, knowing that VS is way better IDE than MonoDevelop. In my search for efficiency, I found many shortcuts that made my life way easier than before. I can profoundly assume that my efficiency of coding has been increased by 30-40% in terms of speed after I started using these shortcuts. It takes a bit time and dedication to get used to them, but once you do it, you will thank me. My recommendation is to skim through the document and pick shortcuts that suits best to you. Then you can look for more if the need arises.

When you are coding, try to use these shortcuts to register them to your muscle memory. As I’ve said before, it may take a bit time to get used to them so try to be patient.

Before you start, I’ve written shortcuts’ names as headings, so you can find them easily in Tools > Options > Environment > Keyboard. If you want to change the shortcut, you can easily do it in there typing the name of the shortcut.

Snippets | String shortcuts for some operations, you can create your own snippets tooKnown But Forgotten | Most probably known shortcuts, but they are not widely used but very useful

Navigation

Edit.GoToAll

Enables you to navigate through your project. To search specifically, type one of these and hit space before searching :

Symbols | #

Files | f

Members | m

Types | t

Lines | : (colon)

Default Shortcut : CTRL + ,(comma)

View.NavigateForward & View.NavigateBackward

You can return to your previous line or jump to your next line in the history. This makes easier to find your way in a single big class.

Navigate Backward : CTRL + –(minus)

Navigate Forward : CTRL + SHIFT + –(minus)

Intellisense

You know the intellisense, but there is a chance that you didn’t notice the bottom context in intellisense. If you forgot a method name or a property name, you can take a look at list of these types in intellisense, saves some time of looking a method’s name or something else.

Default Shortcut : CTRL + J

You can also pop intellisense in an empty place with CTRL + Space. CTRL + Space is actually Edit.CompleteWord but it pops intellisense when used in empty space.

Edit.FindAllReferences

Find all references of a method.

If this does not work on you, check if you have GeForce Experience installed. A global shortcut for toggling FPS counter on/off is assigned in GeForce Experience that prevents SHIFT + F12 from working in Visual Studio. Press ALT + Z while GeForce Experience is running, find Settings(gearbox image in the bottom right corner) and Press Keyboard shortcuts. You can change FPS counter on/off from there.

Default Shortcut : SHIFT + F12

If you want to go to the definition of a method directly, use F12.

Edit.Find

You might probably know this but there are some details that you might not know. You can narrow your search to:

Match case

Match whole word

Or even Use Regular Expressions! The regex used in the gif is searching for a valid email address.

You can search within the context of:

Selection

Current Document

All Open Documents

Current Project

Entire Solution

Most of the time using Edit.Find yields unwanted results so using these options might accurately help what you want to find and also speeds up the process too.

Default Shortcut : CTRL + F

Editing

Edit.PeekDefinition

Enables you to change/peek a member without navigating to there.

Default Shortcut : ALT + F12

Window.Split

Split the window in half to make modifications into two different place.

When you close the split window, the screen will be in the place where the focused split window was on(see the gif)

Default Shortcut : CTRL + D

Edit.LineDelete

Delete the whole line without effort.

Default Shortcut : CTRL + SHIFT + L

Edit.Cut & Edit.Copy & Edit.Paste

Effortlessly cut, copy and paste lines.

If you have don’t have any selection, usual CTRL + C, CTRL + V acts like a line copy-paste

Edit.Cut |Edit.LineCut : CTRL + X | CTRL + L

Edit.Copy : CTRL + C

Edit.Paste : CTRL + V

The difference between Edit.Cut and Edit.LineCut is that Edit.LineCut cuts the lines no matter the selection. If you select some part of multiple lines and do LineCut, it will cut all selected lines. Whereas Edit.Cut only cuts the selected parts.

Edit.MoveSelectedLinesUp & Down

Move lines up and down with ease. You can select an area and move it entirely too.

Edit.MoveSelectedLinesUp : ALT + Up Arrow

Edit.MoveSelectedLinesDown : ALT + Down Arrow

Edit.LineOpenBelow & Edit.LineOpenAbove

Open new lines below or above, in the middle of the line.

Edit.LineOpenBelow : CTRL + SHIFT + ENTER

Edit.LineOpenAbove : CTRL + ENTER

Edit.CommentSelection & Edit.UncommentSelection

One thing that might not be known by some of you is that you can comment out or uncomment a line if you only stay in that line without selecting anything, other than that this is widely known.

Edit.CommentSelection : CTRL + K + CTRL + C

Edit.UncommentSelection : CTRL + K + CTRL + U

Edit.SurroundWith

Surrounds selection with desired block, for example if, for, foreach, while etc. You can also surround a class with namespace and many other things.

Default Shortcut: CTRL + K + CTRL + S

Edit.FormatSelection & Edit.FormatDocument

Formats the selection area or entire document, both has different shortcuts of course.

Edit.FormatSelection : CTRL + K + CTRL + F

Edit.FormatDocument : CTRL + K + CTRL + D

Refactoring

Refactor.Rename

Changes the name of all occurrences of a selected member in entire project. So for example if you want to change a variable name that has been used in 20 different place, all you have to do is this, all of them are automatically updated.

Default Shortcut : CTRL + R + CTRL + R

Refactor.ExtractMethod

Extracts selected area to a new method.

Beware that newly created method is a static one, you may want to change that.

Default Shortcut : CTRL + R + CTRL + M

Refactor.ReorderParameters & Refactor.RemoveParameters

With the dialog box, you can reorder the parameters(if there are more than 1 parameters) and remove parameters. All occurrences will update.

Use shortcut inside a method.

Default Shortcut : CTRL + R + CTRL + O | CTRL + R + CTRL + V

Refactor.EncapsulateField

Suppose you have a private field that you want to convert to public get private set property. That field has been already used in many places and you want some of occurrences to use the private field, and some of them to use its property. This is what it does exactly.

Default Shortcut : CTRL + R + CTRL + E

Refactor.ExtractInterface

Suppose you created a concrete class and its methods, properties and fields. And later on you decided that this class could be an interface. This is the easiest way to do that.

Use shortcut inside a class.

Default Shortcut : CTRL + R + CTRL + I

EditorContextMenus.CodeWindow.QuickActionsForPosition

This is useful for many situations, the gif is just one example. You can encapsulate fields using or not using property, create a new class by having a reference to a non-existent class, generate a non-existent field,fix many misusages and warnings.

Default Shortcut : CTRL + .(comma)

Other Useful Shortcuts

Snippets

Insert preconfigured snippets to save some time writing them. Snippets can be inserted by writing these and hitting TAB button :

switch

if

for

forr(reverse for)

while

prop

These are frequently used ones. If you want to see them all, press CTRL + K + CTRL + X select Visual C# and you can see all saved snippets there. You can even create your snippets! Follow this link.