Visual Studio 2015 Tips & Tricks

I’ve been using Visual Studio daily for a very long time now and I think I learnt a thing or two about getting the most out of it and be as productive as I can be.
In today’s post I will present a few of them that I find myself using a lot and I find extremely useful but are less known (based on my observations)

The tips below apply to Visual Studio 2015, but some of them are available in older versions as well.

1. Duplicate control styles

When designing and building UIs in UWP or any XAML based system one of the key things you’ll need to do is to modify the default styles of the common controls. This was easily done in Blend in the past and a bit more challenging in Visual Studio. With Visual Studio 2015, a lot of Blend has come into the VS editor and one of the features I like most is the ability to edit the styles and templates of the controls directly from the designer.
Simply right click on the control and look for Edit Template, or Edit Additional Templates. This will expose the default style of the control as a StaticResource that you can edit and update as you like.

The feature is also available from the Document Outline window, for controls that are not easily accessible from the designer (like child templates).

2. Free form selection

This is probably my favourite feature, it’s been available since at least Visual Studio 2005 and I like it because it works so beautifully. It’s not something that you’d use every day, but when you need it it’s such a time saver.
So the idea is that if you select text while holding the ALT key, the selection will be free-form, so you can select text across line endings.
What’s even nicer is that you can then type and the text will be replicated across all selected lines.
Here are some neat examples:

Changing private to public across a large number of fields:

Sure you can argue that you could do that with a find and replace, but what happens when the text you need to delete/change is not static? Like when you mistakenly copy code with the line numbers included?

3. Paste JSON / XML as class

Often times when implementing a web service layer we have to create classes to represent the data that’s coming down the pipe in JSON or XML form. So the usual way would be to manually write the class based on the spec. This is time consuming and error prone.

Here comes Paste JSON as Classes. Simply create a new file in your project, put the JSON / XML string (not file) in you clipboard and use the Paste JSON as Classes from the Paste Special menu. See below the results

4. Keyboard shortcuts

What would a productivity post be without a few good keyboard shortcuts. I use these shortcuts every day so hopefully you either knew them already or if not you’ll find them useful (most of these have been in place since Visual Studio 2005)

  • Comment/Uncomment: Ctrl + K + C & Crtl + K + U
  • Surround with: Ctrl + K + S
    Select the text you want surrounded, use the shortcut and pick the code you want to use around you selection. i.e. introducing a try-catch statement is probably the one I use the most.
  • Toggle Outline: Ctrl + M + M
    Collapsing code is useful to make the code readable and having a way to collapse / expand code without reaching to the mouse is a great time saver. This shortcut will toggle the collapse/expand the method / region that has the keyboard Use in conjunction with Ctrl + M + O which toggles collapse state in the entire file.
  • Format: Ctrl + K + D
    We all like nicely formatted code and while Visual Studio does a nice job formatting code automatically, sometimes you need to force it manually. I have a bit of a habit to format code before I save and close a file and this shortcut is perfect for that.

5. Track active file in solution

If you’re working on a huge solution, it can be tough to find the context of the classes you’re in and where the files are. Use the sync active file to highlight the file you’re working on in the Solution Explorer.

The button itself is a new feature in Visual Studio 2015 but there’s a setting dating back from Visual Studio 2008 that automatically tracks the active file in the solution explorer.

I hope you enjoyed this quick Tips and Tricks. Which ones did you know about before? What are some of your favourite productivity tips? Feel free to leave them in the comments section,

Share Comments