Visual Studio Shortcuts
29 October 2017 • Dogukan Erkut
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.
Want to find your way in your project or easily navigate through your scripts? Perhaps you want to find specific classes, methods, fields? Look here!
Edit.GoToAll | Find anything within the project very fast
View.NavigateForward & View.NavigateBackward | Get to previous and next cursor point in the history
Intellisense | Tips of using intellisense
Edit.FindAllReferences Find all reference used anywhere within the project
Edit.Find | Advanced search, usually for strings and things that can’t be found with GoToAll
Easily modify and format your document. This is the place you will use most when you are coding.
Edit.PeekDefinition | Check/modify the definition of a type
Window.Split | Split the window in half to make modifications in two different places
Edit.LineDelete | Delete whole line with ease
Edit.Cut & Copy & Paste | Cut, copy and paste whole lines
Edit.MoveSelectedLinesUp & Down | Move a line up or down
Edit.LineOpenBelow & Above | Open a line below or above, even when you are in the middle of a line
Edit.CommentSelection | Comment selected lines
Edit.SurroundWith | Wrap a snippet around selected area
Edit.FormatSelection & Document | Format selection or document to make it look tidy
Refactor methods, parameters, fields, all type names, do auto fixes, additions without almost no efford.
Refactor.Rename | Rename types and all its occurrences(references)
Refactor.ExtractMethod | Easily create a method out of selected lines
Refactor.ReorderParameters | Reorder or remove parameters from a method and all its occurrences
Refactor.EncapsulateField | Automatically convert a field to a property, select which occurrences will be converted
Refactor.ExtractInterface | Automatically create an interface with methods and properties used in the class
EditorContextMenus.CodeWindow.QuickActionsForPosition | Quick actions for many things
- 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)
- 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.
- 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.
- 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:
- 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
- Enables you to change/peek a member without navigating to there.
- Default Shortcut : ALT + F12
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- Insert preconfigured snippets to save some time writing them. Snippets can be inserted by writing these and hitting TAB button :
- forr(reverse for)
- 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.
Known But Forgotten
- Edit.WordDeleteToStart :
- Delete a word to the left side of the cursor.
- Default Shortcut : CTRL + Backspace
- Edit.WordDeleteToEnd :
- Delete a word to the right side of the cursor.
- Default Shortcut : CTRL + Delete
- Edit.WordPrevious :
- Bring cursor at the start of previous word.
- Default Shortcut : CTRL + Left Arrow
- Edit.WordNext :
- Bring cursor at the end of next word.
- Default Shortcut : CTRL + Right Arrow
- Edit.Redo :
- Reverts changes made by undo(CTRL + Z).
- Default Shortcut : CTRL + Y