Author: Brandon Pearman

The views expressed here are mine alone and do not reflect the view of my employer.

Many devs don't pair programme enough to see how efficient other devs are. When watching others write code you get to learn how they write the same code in different ways.

Some devs pride themselves on being faster typers and not needing to look a the keyboard but there are faster ways to code than being a fast typer. The fastest way to code is to reduce your key strokes ie type less. IDEs generally have shortcuts which allow you to speed up ten fold even as a slow typer. In this post I will be cover Visual Studio specifc shortcuts for C#.

  1. Copy paste
  2. Quick actions and refactorings
  3. Solution Explorer Control
  4. Navigation
  5. Snippets

Copy pasting large chunks of code is generally faster than typing out from scratch so try copy paste as much as possible. I also copy paste entire files and rename them. Copy pasting is such a huge part of of effiecient coding visual studio has added some conveniences.

The first convenience is the toolbox. The toolbox gives a menu of pasted code which you can view and easily use when need. In visual studio go to the "view" tab then to "toolbox". You will then get a new window where you can new tabs by right clicking then "Add tab". In tabs you can paste code that you regularly use.

Other shortcuts

ctrl shift v: get drop down liste to paste one of the past few copys eg use ctrl c on 3 different lines, you cna then paste the first line you copied

ctrl d: Duplicate the line your cursor is on

ctrl d (with highlighted text): Duplicate the highlighted text

ctrl l: Delete the line the cursor is on

alt up/down arrow: Move the current lineup or down

Visual Studio has easy quick actions and refactorings which radically improve development time.

ctrl . : This is gives recommendations and shorcuts. This speeds up many tasks. For some common uses to ctrl . your way to glory, try it on 1.highlighted code a class type "abc" a method type "abc = 0;" constructor parameters type "int abc" 5.any code which has squiggly lines underneath 6.on a class name 7.on an interface

ctrl R R: rename. Use this whenever renaming anything because it will automatically change the name everywhere. eg classes, methods, properties, variables

ctr shift f (replace in files tab): Advanced search and replace

ctrl k d:Auto clean up code

ctrl r g: Auto clean up using statements

Some examples of common uses

Cleaning up using statements: ctrl . on a greyed out one > remove unnecessary usings

Generate Interface: ctrl . on class name > extract interface

Implement Interface: ctrl . on interface name on class > implement interface

Move code into new method: ctrl . on highlighted code > Extract Method

Creating Constructors: "ctor tab tab" to create constructor > in the constructor parameters type the class you want to pass in and give it a name, then ctrl . > create and initialize field

The solution explorer window has a few quality of life features which many devs do not know about. Hover over the buttons in the solution explorer to see their names.

Collapse All: collapses everything for easy viewing

Show All Files: You may have noticed that some files exist but do not show in solution explorer. This button will show those files a bit transparent, which you can then right click and "include in project"

Sync With Active Document: go to open tabs file location in solution explorer. Greatly increases speed of finding files.

Switch views: Many people complain about Visual Studio's Solution Explorer not representing the file structure... well there is a button for that.

right click on folder => "Open Folder in file explorer" : This is a faster way of getting to the files on your OS.

Search (ctrl ;): Solution Explorer has got a search, which will pick up files, classes, methods, etc.

When typing, moving back and forth between the mouse and keyboard is a huge time waster. So in order to use the mouse as little as possible, it is essential to know how to navigate with the keyboard.

Moving cursor

left arrow Á right arrow: moves one space over and should be used only for short distances

ctrl left arrow Á ctrl right arrow: the cursor will jump whole words which is better to move larger ditances

Home Á End: moves to the beginning or end of the line (don't use arrows to do this... its takes too long)

ctrl -: navigate backward = go to previous cursor location

ctrl shift -: navigate forward = go to next cursor position (after having used navigate backward)

alt shift up Á alt shift down: multi-cursor on multiple rows

Highlighting text

shift up arrow Á shift down arrow: highlights one row at a time

shift left arrow Á shift right arrow: highlights one space at a time

ctrl shift left arrow Á ctrl shift right arrow: highlights wholes words which is better if you need to highlight entire words

shift home Á shift end: highlights from current position to the beginning or end of the line.

ctrl a: highlights everything

Class searching

F12: Go to implementation

ctrl F12: Go to definition

shift F12: Find all references

ctrl ;: search solution

ctrl f: simple find

ctrl shift f: advanced find

ctrl m o: close all methods in the class

ctrl m p: open all methods in the class

Navigate Visual Studio windows/tabs

ctrl tab (holding down ctrl and use arrows to navigate): selection of open windows/tabs

ctrl F4: closes current tab

Snippets are short hand for code, providing the ability to type less.

Basic snippet example

  • Select: place your cursor within a class
  • Type: prop (the snippet for a property)
  • Press: tab tab (to generate code from the snippet)

You should then see the below code: (don't press anything yet)

public int MyProperty { get; set; }

Notice "int" is highlighted and your cursor is blinking on it. When you type it will replace whatever is highlighted.

  • Type: string (to change the datatype)
  • Press: tab (to move to the next highligted part "MyProperty")
  • Type: Name (to change the name of your property)
  • Press: Enter (to complete the snippet and move to the end of the line)

Surround snippet example

Some snippets will generate blocks for you like an if statement:

  • Select: place your cursor within a method
  • Type: if
  • Press: tab tab

You should then see the below code:

if (true)

  • Type: 1 == 1
  • Press: Enter

Notice that after completing the snippet your cursor is conveniently set inside the block.

But what if you have already written your code, with the above usage you will have to cut and paste it into your new block. There is a better way to use this snippet if you already have the code to go inside the block.

  • Higlight: highlight the code you want inside an if block
  • Press: ctrl K S (opens the snippet selection)
  • Type: if
  • Press: tab tab

You should then see the below code:

if (true)
        // original code

Have to know snippets

  • prop - property
  • propfull - property with backing field
  • ctor - Constructor
  • class - Class
  • enum - enum
  • for - for loop
  • forr - reverse for loop
  • foreach - foreach loop
  • while - while loop
  • if - if condition
  • else - else condition
  • switch - switch case conditions
  • using - using block
  • try - try block
  • tryf - try finally blocks
  • cw - Console.WriteLine();

To see all available snippets use "ctrl k x". I do not use this on a regular basis because it is slow, but use it to find or remind yourself of existing snippets.

Check out these links for more info:

My C# language repo