views:

5454

answers:

6

Introduction

I've always been searching for a way to make Visual Studio draw a line after a certain amount of characters:

Picture of the guidelines

Below is a guide to enable these so called guidelines for various versions of Visual Studio.

Visual Studio 2010

  1. Install Paul Harrington's Editor Guidelines extension.
  2. Open the registry at:
    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor
    and add a new string called Guides with the value RGB(100,100,100), 80. The first part specifies the color, while the other one (80) is the column the line will be displayed.
  3. Or install the Guidelines UI extension, which will add entries to the editor's context menu for adding/removing the entries without needing to edit the registry directly. The current disadvantage of this method is that you can't specify the column directly.

Visual Studio 2008 and Other Versions

If you are using Visual Studio 2008 open the registry at HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor and add a new string called Guides with the value RGB(100,100,100), 80. The first part specifies the color, while the other one (80) is the column the line will be displayed. The vertical line will appear, when you restart Visual Studio.

This trick also works for various other version of Visual Studio, as long as you use the correct path:

2003: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.1\Text Editor
2005: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Text Editor
2008: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor
2008 Express: HKEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\Text Editor

This also works in SQL Server 2005 and probably other versions.

+2  A: 

The registry path for Visual Studio 2008 is the same, but with 9.0 as the version number:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor
Rory MacLeod
Thank you, I added it to the post.
xsl
+22  A: 

This is originally from Sara's blog.

It also works with almost any version of Visual Studio, you just need to change the "8.0" in the registry key to the appropriate version number for your version of Visual Studio.

The guide line shows up in the Output window too. (Visual Studio 2010 corrects this, and the line only shows up in the code editor window.)

You can also have the guide in multiple columns by listing more than one number after the color specifier:

RGB(230,230,230), 4, 80

Puts a white line at column 4 and column 80.

Be sure to pick a line color that will be visisble on your background. This color won't show up on the default background color in VS. This is the value for a light grey: RGB(221, 221, 221).

Here are the registry keys that I know of:

Visual Studio 2010: HKCU\Software\Microsoft\VisualStudio\10.0\Text Editor

Visual Studio 2008: HKCU\Software\Microsoft\VisualStudio\9.0\Text Editor

Visual Studio 2005: HKCU\Software\Microsoft\VisualStudio\8.0\Text Editor

Visual Studio 2003: HKCU\Software\Microsoft\VisualStudio\7.1\Text Editor

For those running Visual Studio 2010, you may want to install the following extensions rather than changing the registry yourself:

These are also part of the Productivity Power Tools, which includes many other very useful extensions.

Scott Dorman
I didn’t know the original source, because a fellow co-worker told me how to do it. I added the blog as a reference.
xsl
Is there any way to enable this for only certain types of code? For instance, I may want it for C# files but not ASPX files.
Larsenal
@DLarsen: No, it's not possible to do this only for certain types of code. This is an "all or nothing" trick.
Scott Dorman
Looks like the line appears in the output window, the search results, etc., as well as when editing code
OJW
@OJW: Yes, this does cause the line to appear in the output window, search results, etc.
Scott Dorman
Update for people with 64 bit OS's or at least Windows 7 (in my case). This doesn't work. The registries keys are under "Wow6432Node" and for somereason when you make the change there it doesn't change anything. It also has a TextEditor without a space and I tried both with no luck. Also I tried created "Text Editor" under the normal path outside of "Wow6432Node" and still no good.
Rodney Foley
@Creepy Gnome: I'm running Win7 64-bit and had no problems accessing these registry keys.
Scott Dorman
I seem to have a similar problem as Creepy Gnome. It works with VS 2008, but not 2010. My OS is Win7 x64, but I can't say if that actually means anything.
Mark Seemann
+6  A: 

If you are a user of the free Visual Studio Express edition the right key is in HKEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\Text Editor {note the VCExpress instead of VisualStudio) but it works! :)

Thank you, I added it to the post.
xsl
It doesn't seem to work with Visual Studio 2010 Express C++.
Adam Badura
+3  A: 

This works for SQL Server Management Studio also.

Keith Walton
Thank you, I added it to the post.
xsl
The link you added to the post gives me a page not found error.
Keith Walton
I changed the link, thank you for pointing that out.
xsl
+6  A: 

This will also work in Visual Studio 2010 (Beta 2), as long as you install Paul Harrington's extension to enable the guidelines from the VSGallery or from the extension manager inside VS2010. Since this is version 10.0, you should use the following registry key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor

Also, Paul wrote an extension that adds entries to the editor's context menu for adding/removing the entries without needing to edit the registry directly. You can find it here: http://visualstudiogallery.msdn.microsoft.com/en-us/7f2a6727-2993-4c1d-8f58-ae24df14ea91

Noah Richards
Thank you, I added it to the post
xsl
+2  A: 

If you don't want to edit any registry keys, and don't mind the other features installed with the extension, you could simply install the Productivity Power Tools extension and you get guideline functionality out of the box.

after installation just right click on the desired column while in the editor window and choose the add guide line option.

rony l