374

Introduction

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

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

Visual Studio 2013 or later

Install Paul Harrington's Editor Guidelines extension.

Visual Studio 2010 and 2012

  1. Install Paul Harrington's Editor Guidelines extension for VS 2010 or VS 2012.
  2. Open the registry at:
    VS 2010: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor
    VS 2012: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.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 is also a part of the Productivity Power Tools), 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.

24
  • 1
    This has no effect whatsoever on my computer. Any ideas? Mar 5, 2009 at 20:11
  • 9
    This registry trick does not seem to work with Visual C++ 2010 Express. Can anyone else confirm or provide a solution for this? Apr 13, 2010 at 9:22
  • 2
    Hey, a bit of a tangent, but you can make that code a bit more efficient. Since you have the hex string, you know ahead of time the upper limit of how many bytes you'll need. Instead of a List<byte>, you can simply declare a byte[hexString.Length/2], or even fancier, byte[(hexString.TrimStart('0').Length+1)/2] to account for leading zeroes. Jul 15, 2011 at 17:52
  • 7
    Does not work on win7 x64 vs2010 Oct 2, 2012 at 7:53
  • 3
    Why is the installation of Editor Guidelines extension required (at least for VS2012). The Guides registry key alone doesn't work. What is this extension exactly doing?
    – elmattic
    Feb 4, 2014 at 10:59

15 Answers 15

104

For those running Visual Studio 2015 or later, the best solution is to install the Editor Guidelines by Paul Harrington rather than changing the registry yourself.

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. This should be the value of a string value Guides in "Text Editor" key (see bellow).

Be sure to pick a line color that will be visible 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

Productivity Power Tools includes guidelines and other useful extensions for older versions of Visual Studio.

18
  • 1
    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
    Sep 17, 2008 at 15:31
  • 4
    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. Nov 15, 2009 at 4:06
  • 3
    Any idea for Visual Studio 2015? The registry hack doesn't seem to work anymore.
    – Joanis
    Mar 22, 2016 at 15:35
  • 2
    How do you do this with vs2017?
    – Demodave
    Mar 17, 2017 at 15:01
  • 3
    @Demodave the Microsoft DevLabs Editor Guidelines extension has been deprecated for VS2017; the related Marketplace page currently recommends using Paul Harrington's Editor Guidelines extension.
    – plr108
    May 2, 2019 at 12:51
84

Without the need to edit any registry keys, the Productivity Power Tools extension (available for all versions of visual studio) provides guideline functionality.

Once installed just right click while in the editor window and choose the add guide line option. Note that the guideline will always be placed on the column where your editing cursor is currently at, regardless of where you right click in the editor window.

enter image description here

To turn off go to options and find Productivity Power Tools and in that section turn off Column Guides. A reboot will be necessary.

enter image description here

4
  • 1
    I used this extension for months and had no idea that i had to right click! This works as a charm, however, AFAIK you cannot install extensions on the express (aka free) edition of VS. Apr 9, 2012 at 21:44
  • 2
    Here's the link for the VS 2012 version.. visualstudiogallery.msdn.microsoft.com/… Feb 18, 2013 at 17:43
  • I second this answer. Also been using this tool-set for months, never knowing this feature exists! Besides, I would recommend Productivity Power Tools to anyone; it's a great tool! :-D Mar 6, 2014 at 11:10
  • 3
    The guidelines feature of this extension for the 2017/2019 version only works for Visual Studio 2017 (not 2019) as per the documentation. If you only want guidelines you can use the Editor Guidelines extension: marketplace.visualstudio.com/…
    – Aage
    Sep 5, 2019 at 8:20
64

Visual Studio 2017 / 2019

For anyone looking for an answer for a newer version of Visual Studio, install the Editor Guidelines plugin, then right-click in the editor and select this:

Add guidelines in Visual Studio 2017

Visual Studio 2022

Same author as the package above but seems he had to split the extension to work with 2022.

https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelinesPreview&ssr=false#overview

4
  • 6
    FYI: The cursor (not only the mouse!) needs to be positioned at your desired column count for this to work without having to use config files. Aug 6, 2019 at 16:42
  • 4
    Guidelines do not work Visual Studio 2019 in the Productivity Power Tools (version 2017/2019). If you want guidelines, Editor Guidelines is the better option.
    – Aage
    Sep 5, 2019 at 8:26
  • Unclear how to adjust the position of the guideline, looks like it requires adding or editing some kind of configuration file? But it's unclear where it goes or how to access it. Jul 6, 2020 at 17:14
  • @TylerShellberg cursor position when you make right click is the answer !!!
    – Dani
    Mar 23 at 10:39
19

There is now an extension for Visual Studio 2012 and 2013:

http://visualstudiogallery.msdn.microsoft.com/da227a0b-0e31-4a11-8f6b-3a149cf2e459

3
  • Of proposed solutions, this was the easiest for 2012, not requiring registry editing. After installing, 1) simply right click the workspace at the length you want a guideline to show. 2) ??? 3) Profit.
    – Tor
    Mar 27, 2015 at 16:53
  • Is there a way to make this line a solid?
    – Demodave
    Jul 14, 2015 at 15:24
  • @Demodave I don't know about the built-in guides, but you may be able to modify the source provided for an extension here to create solid guides: jeff.wilcox.name/2010/02/visualstudio2010guides Jul 15, 2015 at 1:25
11

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! :)

0
7

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

0
6

This works for SQL Server Management Studio also.

0
6

I found this Visual Studio 2010 extension: Indent Guides

http://visualstudiogallery.msdn.microsoft.com/e792686d-542b-474a-8c55-630980e72c30

It works just fine. enter image description here

1
  • Thanks for mentioning this extension. It's hard to find because it doesn't show up in searches for "column", "line", or "block". The fixed page width marker(s) are also nice to have. Great complement to the individually-set editor guidelines, now built into VS2015.
    – Suncat2000
    Feb 20, 2017 at 19:39
4

With VS 2013 Express this key does not exist. What I see is HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0 and there is no mention of Text Editor under that.

1
  • 1
    Need to expand 12.0 there is another directory
    – Demodave
    Jul 14, 2015 at 15:31
4

For those who use Visual Assist, vertical guidelines can be enabled from Display section in Visual Assist's options:

enter image description here

2

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
0
1

NOTE. This answer is surely not working for versions <17.7, but it should work for the mentioned versions.

Visual Studio (2022, etc)

This solution works probably for all versions of Visual Studio that support guidelines. It was applied exactly at Visual Studio 2022 17.5.1 through 17.6.2

Open Command Window, and enter the following commands:

Edit.AddGuideline <NumberPosition>

enter image description here

From the Menu: View > Other Windows > Command Window

Here's the result:

enter image description here

For changing the color, go to Tools > Options > Environment > Fonts and Colors > In "Disaplay items:" select: > Guideline > Change the color using "Item background:"

enter image description here

For VSCode

If you're looking for a solution for Visual Studio Code (and you're a little lost in your search), I'm adding the solution here as a bonus to this answer.

In settings.json add this example code:

{
    "editor.rulers": [
        {
            "column": 75,
            "color": "#fffb01"
        },
        {
            "column": 120,
            "color": "#01ffc8"
        }
    ],
}

The result (at Visual Studio Code 1.76.20):

enter image description here

7
  • 1
    I'm on 17.6.2, and there is no such command. Jun 4 at 2:13
  • I've just checked in my VS22, 17.6.2, and the command is there. I've added a screenshot to the answer. Feel free to colaborate to the answer, since it is a community wiki.
    – carloswm85
    Jun 5 at 11:39
  • When I type "Edit.A", the available commands are AddEventHandler, Add.Resource and Add.Row. The two other in the screenshot shown here, are missing from my VS'es. I use VS Pro. I'm researching now. Jun 5 at 12:14
  • Command "Edit.AddGuideline" is not valid. Aug 11 at 18:47
  • @GabrielAnderson it seems to be such command is deprecated in VS22 17.7 In my system says, Command "Edit.AddGuideline" is not available.. Please, if you find out what happened and any other alternative to this problem, do let me know. I won't try to solve it later this year (probably).
    – carloswm85
    Aug 12 at 0:46
0

For VS 2019 just use this powershell script:

Get-ChildItem "$($env:LOCALAPPDATA)\Microsoft\VisualStudio\16.0_*" | 
Foreach-Object {
  $dir = $_;
  $regFile = "$($dir.FullName)\privateregistry.bin";
  Write-Host "Loading $($dir.BaseName) from ``$regFile``"
  & reg load "HKLM\_TMPVS_" "$regFile"
  New-ItemProperty -Name "Guides" -Path "HKLM:\_TMPVS_\Software\Microsoft\VisualStudio\$($dir.BaseName)\Text Editor" -Value "RGB(255,0,0), 80" -force | Out-Null;
   
  Sleep -Seconds 5; # might take some time befor the file can be unloaded
  & reg unload "HKLM\_TMPVS_";
  Write-Host "Unloaded $($dir.BaseName) from ``$regFile``"
}
0

The extension named EditorConfig Guidelines for Visual Studio 2022 will, as the name suggests, take advantage of your .editorconfig file(s) to keep the settings.

-1

You might be looking for rulers not guidelines.

Go to settings > editor > rulers > and give an array of character counts to provide lines at the specified values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.