Adding a guideline to the editor in Visual Studio
Asked Answered
A

15

376

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.

Auer answered 17/9, 2008 at 15:4 Comment(25)
This has no effect whatsoever on my computer. Any ideas?Ceporah
It doesn't seem work in Visual Studio 2010 Beta 2.Brittanybritte
This registry trick does not seem to work with Visual C++ 2010 Express. Can anyone else confirm or provide a solution for this?Garvin
@xsl: Would you be willing to post a settings export with the color scheme that you use? I think I really like those colors.Sapota
Color scheme: #3014420Auer
The current disadvantage of this method is that you can't specify the column directly. This isnt true, the guideline appears in whichever column the cursor is currently in. You can change the colour too.Slumber
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.Posticous
Hrm, I'd also like that color scheme. The link that you posted in the (now-deleted) question is dead. Mind uploading it again? And please don't post it as a new question (wouldn't be on-topic). Just leave a comment and ping me back using @Cody at the beginning. Thanks for your time; sorry to be a bother.Shallow
@Cody: Sorry for the delay, but I've been away from work for some time. Here is the link: speedshare.org/download.php?id=8834FD7611 Feel free to do everything you want with it. The color-scheme supports ReSharper, but the web developing part is most likely incomplete, because I had no time to test it. If you want to fix it and host it somewhere else I would be glad.Auer
Thanks; no worries about the delay. When I get a chance, I'll upload it to studiostyl.es.Shallow
Does not work on win7 x64 vs2010Equivalency
@CzarekTomczak: I use the same setup and can confirm that it works.Auer
What is the suggested guideline location? 80 looks too narrow, I heard about 110, is there a best practice?Titty
@Recep: 80 columns is the standard width of the command promptDivebomb
Can someone fix that broken image? I'd do it myself, but I don't know what the original is.Incapacious
@Mystical: The original was an image displaying a sample guideline with some code. You are welcome to add it and expand the question to further Visual Studio versions.Auer
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?Alage
Microsoft need to add an menu option within Visual Studio to achieve this common goal which programmers will benefit from greatly. Under no circumstances is it acceptable for MS to expect users to edit the registry simply to make a guideline appear in their editor. This has been a difficult issue for a very long time. It is time that somebody from MS fixed the problem properly rather than have us all desperately searching for registry entries. Mine is the real solution to the problem. Everything else is a hack.Toth
MS have BILLIONS of dollars - surely they can pay somebody to do the single days work that it will take and fix this problem once and for all for all users. PS I am using Visual Studio 2012 and it is 2014 now. Still you cannot easily make a vertical guideline appear. Is it really that difficult for MS to implement this feature correctly?Toth
Installed the aforementioned "Paul Harrington's Editor Guidelines extension for VS 2013". Is working on Visual Studio Professional 2015 as well.Goniometer
Vertical guides ('rulers') are available from VS Code 0.10: https://mcmap.net/q/45176/-vertical-rulers-in-visual-studio-codeGladiatorial
FYI Paul Harrington's Editor Guidelines works with Visual Studio 2017 Community Edition.Mistrial
How on God's Green Earth is it acceptable to have something that should be available in editor settings only modifiable by a registry key or a special plugin?Mukul
Works fine on Visual Studio 2017 / v.15.3.5 / Windows 10Naidanaiditch
The instructions don't work for Visual Studio 2022Devoir
K
106

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.

Kristofer answered 17/9, 2008 at 15:26 Comment(18)
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.Auer
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.Killen
@DLarsen: No, it's not possible to do this only for certain types of code. This is an "all or nothing" trick.Kristofer
Looks like the line appears in the output window, the search results, etc., as well as when editing codeUnmeasured
@OJW: Yes, this does cause the line to appear in the output window, search results, etc.Kristofer
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.Expiration
@Creepy Gnome: I'm running Win7 64-bit and had no problems accessing these registry keys.Kristofer
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.Theorist
2012/2013 link - visualstudiogallery.msdn.microsoft.com/…Dar
maybe i am dumb, but what value do i need to add to this Text Editor key?Preponderant
@jheriko: By looking at the linked blog entry, I've determined that the value is named Guides. I should, of course, not have needed to do this. (What if the link had broken? Not exactly unheard of for MS blogs...)Malodorous
Any idea for Visual Studio 2015? The registry hack doesn't seem to work anymore.Vestiary
I'm new to VS and I wanted to avoid adding dependencies... But as it doesn't support ctrl+click either, I'll give a try to Productivity Power Tools 2015 visualstudiogallery.msdn.microsoft.com/… These are really basic features. It's baffling that you need an extension for that (but hey... Microsoft!).Vestiary
@Vestiary visualstudiogallery.msdn.microsoft.com/…Undertaking
How do you do this with vs2017?Stegosaur
@Stegosaur Use the Editor Guidelines extension - marketplace.visualstudio.com/…Kristofer
@Stegosaur the Microsoft DevLabs Editor Guidelines extension has been deprecated for VS2017; the related Marketplace page currently recommends using Paul Harrington's Editor Guidelines extension.Lisa
@Lisa I think I ended up using the one you suggested. Waiting to install vs2019 to see if it is the same.Stegosaur
C
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

Cirrate answered 17/9, 2008 at 15:4 Comment(4)
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.Epistyle
Here's the link for the VS 2012 version.. visualstudiogallery.msdn.microsoft.com/…Isola
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! :-DBurden
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/…Sunlit
U
64

Visual Studio 2015, 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 above but seems he had to split the extension to work with 2022: Editor Guidelines plugin.

Urticaceous answered 17/9, 2008 at 15:4 Comment(4)
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.Peat
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.Sunlit
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.Morelos
@TylerShellberg cursor position when you make right click is the answer !!!Holds
M
19

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

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

Munsey answered 17/9, 2008 at 15:4 Comment(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.Goniometer
Is there a way to make this line a solid?Stegosaur
@Stegosaur 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/visualstudio2010guidesMunsey
D
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! :)

Deepfry answered 11/11, 2008 at 16:11 Comment(0)
H
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

Homs answered 17/9, 2008 at 15:4 Comment(0)
R
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

Robbyrobbyn answered 17/9, 2008 at 15:4 Comment(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.Acetophenetidin
T
6

This works for SQL Server Management Studio also.

Tchao answered 5/12, 2008 at 16:28 Comment(0)
T
4

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

enter image description here

Transition answered 17/9, 2008 at 15:4 Comment(0)
D
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.

Demonetize answered 17/9, 2008 at 15:4 Comment(1)
Need to expand 12.0 there is another directoryStegosaur
E
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
Eudora answered 17/9, 2008 at 15:15 Comment(0)
E
1

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.

Expound answered 17/9, 2008 at 15:4 Comment(0)
I
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

Immersion answered 17/9, 2008 at 15:4 Comment(7)
I'm on 17.6.2, and there is no such command.Expound
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.Immersion
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.Expound
Command "Edit.AddGuideline" is not valid.Manny
@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).Immersion
I still can see in my VS22 the guidelines I had added in previous versions, so it seems to be that the command has been moved somewhere else or changed somehow.Immersion
This command is added by Paul Harrington's extension. If it is not installed you won't have it.Marandamarasca
S
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``"
}
Speechless answered 17/9, 2008 at 15:4 Comment(0)
K
-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.

Kalevala answered 17/9, 2008 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.