Increasing Productivity in Visual Studio

by Danielvg 29. January 2010 20:57

There are a lot of ways to increate productivity, this post will focus on some of the stuff that can be used within visual studio to code a bit faster. The plan is to keep updating this post so it can be used as a reminder/encyclopedia for myself and anyone interested. NB: The stuff below works in vs2010 but should also work with vs2008, at least if you are using ReSharper.

Key bindings:

Keys Description
Ctrl+Alt+L Focus on Solution Explorer
Ctrl+½+M Focus on Team Explorer
Ctrl+Tab Tab open documents within visual studio
Ctrl+Shift+A Add new item
Ctrl+M –> Ctrl+O Collapse everything in the document
Ctrl+M –> Ctrl+L Expand everything
Ctrl+M –> Ctrl+M Collapse/Expand a block
   
Ctrl+F5 Start without debugging
Shift+F5 Stop debugging
   
Ctrl+. Resolve
Ctrl+i Incremental search
Ctrl+, Quick search
   
Ctrl+K -> Ctrl+F Auto format selected
Ctrl+K -> Ctrl+C Comment out selected
Ctrl+K -> Ctrl+U Uncomment selected
Ctrl+R -> Ctrl+R Rename
Ctrl+R -> Ctrl+M Extract Method
Ctrl+R -> Ctrl+E Encapsulate field
Ctrl+Shift+V Paste by cycling through latest clipboards

I am not really a fan of bookmarks so they have been left out until someone says they are the best thing in the world.

Macros:
Macros are a way of recording and playing a set of key strokes, they can be used to ease the work of tedious tasks. Some sample macros come with visual studio but the most useful feature, at least for me, is temporary macros.

In visual studio to help speed up the process and use the temporary macros more often I bind the following keys:
Ctrl+Shift+R - to start recording
Ctrl+Shift+E – to stop recording

and of cause use the default ctrl+shit+P to play the macro.

If you are not already using macros, try them out!

Snippets:
Creating your own snippets is of cause always a good thing, here are some of the default snippets:
(if your new to snippets, type the name of the snippet and press tab a few times)

Name Outcome
prop
public int MyProperty { get; set; }
propg
public int MyProperty { get; private set; }
propfull
private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
}

for
for (int i = 0; i < length; i++)
{
}
forr
for (int i = length - 1; i >= 0 ; i--)
{
}
foreach
foreach (var item in collection)
{
}
invoke
EventHandler temp = MyEvent;
if (temp != null)
{
    temp();
}
cw
Console.WriteLine();
mbox
global::System.Windows.Forms.MessageBox.Show("Test");
ctor
public NameOfMyClass()
{

}

try
try
{

}
catch (Exception)
{
    throw;
}

tryf
try
{

}
finally
{

}

testm
[global::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethod]
public void MyTestMethod()
{
}
propnew

private int myVar;
public int MyProperty
{
    get
    {
        if (myVar == null)
        {
            myVar = new int();
        }
        return myVar;
    }
    set { myVar = value; }
}

Other:

Method/Class/.. Comments
Typing 3 times “/” creates the default comment template:


Automatically turns into: 

 

Box select
The newly added box select has been surprisingly useful, simply hold the “Alt” key and select with the mouse. 

 

 

On a somewhat related note; a blog post, that can be found here, raises some pretty interesting questions about your font type, m-mz says that you can read 14% faster with a proportional font when compared with a fixed width font. Maybe it is worth a try?

UPDATE
4/2-2010: Added custom snippet; propnew - propnew.snippet (1,30 kb)

--------

Did I miss that one perfect shortcut or something else? Let me know and I will add it!

To be updated!