Column guides for Visual Studio 2010: An extension

Posted 26 February 2010  

Here’s a helpful editing tool I’ve been using on the Silverlight team while coding. I’ve authored this simple Visual Studio 2010 extension that re-introduces column guidelines within the editor surface. The feature was undocumented in previous versions and isn’t in the new WPF-powered editor without a custom extension.

Note: Turns out Paul Harrington already wrote one. Since I’m at least throwing my source out in public, I figure this blog post may still have some value. If you’re looking for a more baked solution, with some level of extensibility available, I’d recommend his. I’m not planning on building in a UI or offering this in the online extension guide for VS at this time since his works well.

Download the extension

VisualStudioGuides.vsix [111 KB, Visual Studio Extension Package, Signed]

RedGuides
I’ve set the guides to be red in this screenshot to make it clear what the feature offers. In practice, the guides are typically very lightly colored, a dotted line, and quite small, so it doesn’t get in your way.

This works with all non-express SKUs of Visual Studio 2010 RC.

Why use guides?

On the Silverlight Toolkit team we always have had a high level of “engineering excellence”: like all developers, we love a good hearty discussion about code guidelines and style.

One thing we’re clear on is that comments should never extend beyond the 80th character of a line, though we don’t mind source code extending beyond that guide. Hyper-compressed code often ends up looking messy, but having comments always within your viewport, or when printing, is a help.

I’ve heard that the Common Language Runtime team here used to have a preference of no code running beyond 110 characters in a line. So perhaps a good default set of guides is 80 at a minimum, and 110 if you like that idea.

Here’s what the unsupported guides looked like in a previous Visual Studio version; this same dotted-line, lightly-colored behavior is present in my implementation.

VS2008

How the guides are set

Just as the old unsupported feature works, the registry contains these guide settings. There is a single string key that contains an RGB color definition, followed by any number of guides (integer column counts).

The format for the color is pretty self-explanatory.

In my implementation, if you don’t have any registry key set, it defaults to column 80 and gray.

If you want to easily add that decent default, save this text into a .reg file and execute it:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor]
"Guides"="RGB(220,220,220) 80"

If the tool does not find a guide in the 10.0 folder, then it will also look in the 9.0 folder (used for Visual Studio 2008).

Source

Extension source and project for RC [Zip, 51K]

Since the source is Ms-PL (Microsoft Public License), feel free to use it to learn more about the extension features. The starting point for me writing this was actually the Text Adornment project starting template included with the Visual Studio 2010 RC SDK – you need the SDK to author extensions.

Installing the extension

The VSIX format is super easy to use: it’s really just a zip/package file. Just open the .vsix, read the terms, and click Install.

Visual Studio Extension Installer

Managing Extensions

The improved extension system in 2010 is great: just go to Tools | Extension Manager, and you can uninstall, disable, and even find new extensions in the integrated online extension browser.

Jeff Wilcox is a Principal Software Engineer at Microsoft in the Open Source Programs Office, helping Microsoft scale to 10,000+ engineers using, contributing to and releasing open source.

comments powered by Disqus