371

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.

ESCE
  • 123
  • 1
  • 6
xsl
  • 17,116
  • 18
  • 71
  • 112
  • 1
    This has no effect whatsoever on my computer. Any ideas? – Instance Hunter Mar 05 '09 at 20:11
  • It doesn't seem work in Visual Studio 2010 Beta 2. – Jivko Petiov Nov 07 '09 at 20:16
  • 9
    This registry trick does not seem to work with Visual C++ 2010 Express. Can anyone else confirm or provide a solution for this? – Ashwin Nanjappa Apr 13 '10 at 09:22
  • 1
    @xsl: Would you be willing to post a settings export with the color scheme that you use? I think I really like those colors. – James McNellis May 21 '10 at 00:31
  • Color scheme: http://stackoverflow.com/questions/3013920/color-scheme-smooth-dark-closed – xsl Jun 10 '10 at 13:21
  • `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. – Nobody Nov 13 '10 at 13:00
  • 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, you can simply declare a byte[hexString.Length/2], or even fancier, byte[(hexString.TrimStart('0').Length+1)/2] to account for leading zeroes. – King Skippus Jul 15 '11 at 17:52
  • Hrm, I'd also like that color scheme. The [link](http://www.file-upload.net/download-2588083/Smooth-Dark.vssettings.html) 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. – Cody Gray - on strike Jul 26 '11 at 09:45
  • @Cody: Sorry for the delay, but I've been away from work for some time. Here is the link: http://www.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. – xsl Aug 08 '11 at 08:15
  • Thanks; no worries about the delay. When I get a chance, I'll upload it to http://studiostyl.es. – Cody Gray - on strike Aug 08 '11 at 09:48
  • 7
    Does not work on win7 x64 vs2010 – Czarek Tomczak Oct 02 '12 at 07:53
  • @CzarekTomczak: I use the same setup and can confirm that it works. – xsl Oct 22 '12 at 09:50
  • What is the suggested guideline location? 80 looks too narrow, I heard about 110, is there a best practice? – Recep Apr 17 '13 at 08:13
  • @Recep: 80 columns is the standard width of the command prompt – jvstech Jun 13 '13 at 19:47
  • Can someone fix that broken image? I'd do it myself, but I don't know what the original is. – Mysticial Oct 30 '13 at 20:54
  • @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. – xsl Oct 31 '13 at 12:19
  • 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 04 '14 at 10:59
  • Installed the aforementioned "Paul Harrington's Editor Guidelines extension for VS 2013". Is working on Visual Studio Professional 2015 as well. – Tor Dec 03 '15 at 13:48
  • Vertical guides ('rulers') are available from VS Code 0.10: http://stackoverflow.com/a/29972073/2293756 – Josh Milthorpe Feb 05 '17 at 23:43
  • FYI Paul Harrington's Editor Guidelines works with Visual Studio 2017 Community Edition. – Endy Tjahjono Jul 15 '17 at 10:34
  • 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? – froggythefrog Aug 09 '17 at 03:22
  • Works fine on Visual Studio 2017 / v.15.3.5 / Windows 10 – hdoghmen Feb 23 '18 at 21:19
  • 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. – user859400 Jul 09 '14 at 04:03
  • 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? – user859400 Jul 09 '14 at 04:03

15 Answers15

103

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.

Scott Dorman
  • 42,236
  • 12
  • 79
  • 110
  • 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 '08 at 15:31
  • 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 Dec 04 '08 at 17:28
  • 1
    @DLarsen: No, it's not possible to do this only for certain types of code. This is an "all or nothing" trick. – Scott Dorman Dec 10 '08 at 19:37
  • Looks like the line appears in the output window, the search results, etc., as well as when editing code – OJW Dec 12 '08 at 14:07
  • @OJW: Yes, this does cause the line to appear in the output window, search results, etc. – Scott Dorman Dec 29 '08 at 19:19
  • 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. – Rodney S. Foley Nov 15 '09 at 04:06
  • 1
    @Creepy Gnome: I'm running Win7 64-bit and had no problems accessing these registry keys. – Scott Dorman Feb 28 '10 at 19:06
  • 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 Oct 15 '10 at 11:03
  • 2012/2013 link - http://visualstudiogallery.msdn.microsoft.com/da227a0b-0e31-4a11-8f6b-3a149cf2e459 – Chris S Oct 05 '13 at 20:37
  • maybe i am dumb, but what value do i need to add to this Text Editor key? – jheriko Dec 16 '14 at 13:25
  • 1
    @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...) – SamB Aug 28 '15 at 23:47
  • 3
    Any idea for Visual Studio 2015? The registry hack doesn't seem to work anymore. – Joanis Mar 22 '16 at 15:35
  • 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 https://visualstudiogallery.msdn.microsoft.com/34ebc6a2-2777-421d-8914-e29c1dfa7f5d These are really basic features. It's baffling that you need an extension for that (but hey... Microsoft!). – Joanis Mar 22 '16 at 16:09
  • 1
    @Joanis https://visualstudiogallery.msdn.microsoft.com/da227a0b-0e31-4a11-8f6b-3a149cf2e459 – lost_in_the_source May 01 '16 at 01:22
  • 2
    How do you do this with vs2017? – Demodave Mar 17 '17 at 15:01
  • 1
    @Demodave Use the Editor Guidelines extension - https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.EditorGuidelines – Scott Dorman Jun 08 '17 at 15:37
  • 3
    @Demodave the Microsoft DevLabs Editor Guidelines extension has been deprecated for VS2017; the [related Marketplace page](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.EditorGuidelines) currently recommends using [Paul Harrington's Editor Guidelines extension](https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelines). – plr108 May 02 '19 at 12:51
  • @plr108 I think I ended up using the one you suggested. Waiting to install vs2019 to see if it is the same. – Demodave May 06 '19 at 21:27
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

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
rony l
  • 5,798
  • 5
  • 35
  • 56
  • 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. – Fermin Silva Apr 09 '12 at 21:44
  • 2
    Here's the link for the VS 2012 version.. http://visualstudiogallery.msdn.microsoft.com/3a96a4dc-ba9c-4589-92c5-640e07332afd – Peter Bernier Feb 18 '13 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 – Riegardt Steyn Mar 06 '14 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: https://marketplace.visualstudio.com/items?itemName=PaulHarrington.EditorGuidelines – Aage Sep 05 '19 at 08:20
63

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

jaredbaszler
  • 3,941
  • 2
  • 32
  • 40
  • 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. – FrozenTarzan Aug 06 '19 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 05 '19 at 08: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. – Tyler Shellberg Jul 06 '20 at 17:14
  • @TylerShellberg cursor position when you make right click is the answer !!! – Dani Mar 23 '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

Jeremy Cook
  • 20,840
  • 9
  • 71
  • 77
brianpeiris
  • 10,735
  • 1
  • 31
  • 44
  • 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 '15 at 16:53
  • Is there a way to make this line a solid? – Demodave Jul 14 '15 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: http://www.jeff.wilcox.name/2010/02/visualstudio2010guides/ – brianpeiris Jul 15 '15 at 01: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! :)

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
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

xsl
  • 17,116
  • 18
  • 71
  • 112
Noah Richards
  • 6,777
  • 2
  • 31
  • 28
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

Dio Phung
  • 5,944
  • 5
  • 37
  • 55
Dio
  • 1
  • 1
  • 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 '17 at 19:39
6

This works for SQL Server Management Studio also.

Community
  • 1
  • 1
Keith Walton
  • 5,211
  • 6
  • 39
  • 53
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.

eddyq
  • 879
  • 1
  • 13
  • 25
4

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

enter image description here

Pavel P
  • 15,789
  • 11
  • 79
  • 128
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
Rory MacLeod
  • 11,012
  • 7
  • 41
  • 43
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``"
}
Daniel Fisher lennybacon
  • 3,865
  • 1
  • 30
  • 38
0

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

carloswm85
  • 1,396
  • 13
  • 23
  • 1
    I'm on 17.6.2, and there is no such command. – Bent Tranberg Jun 04 '23 at 02: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 05 '23 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. – Bent Tranberg Jun 05 '23 at 12:14
  • `Command "Edit.AddGuideline" is not valid.` – Gabriel Anderson Aug 11 '23 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 '23 at 00:46
  • 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. – carloswm85 Aug 12 '23 at 00:49
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.

Bent Tranberg
  • 3,445
  • 26
  • 35
-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.

Sven Voigt
  • 91
  • 7