Reputation: 17426
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
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\Text Editor
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\Text Editor
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.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.
Upvotes: 382
Views: 184841
Reputation: 2416
NOTE. This answer is surely not working for versions <17.7, but it should work for the mentioned versions.
Download the following extension: Editor Guidelines, by Paul Harrington
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:
(NOTE: You may or may not need double space between Edit.AddGuideline
and <NumberPosition>
for the command to work.)
Edit.AddGuideline <NumberPosition>
From the Menu: View
> Other Windows
> Command Window
Here's the result:
For changing the color, go to Tools
> Options
> Environment
> Fonts and Colors
> In "Disaplay items:" select: > Guideline
> Change the color using "Item background:"
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
):
Upvotes: 4
Reputation:
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:
Visual Studio 2022
Same author as above but seems he had to split the extension to work with 2022: Editor Guidelines plugin.
Upvotes: 68
Reputation: 3470
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.
Upvotes: 1
Reputation: 42526
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.
Upvotes: 108
Reputation: 147
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.
Upvotes: -1
Reputation: 4194
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``"
}
Upvotes: 0
Reputation: 16892
For those who use Visual Assist, vertical guidelines can be enabled from Display
section in Visual Assist's options:
Upvotes: 5
Reputation: 6022
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.
To turn off go to options and find Productivity Power Tools
and in that section turn off Column Guides
. A reboot will be necessary.
Upvotes: 86
Reputation: 1
I found this Visual Studio 2010 extension: Indent Guides
http://visualstudiogallery.msdn.microsoft.com/e792686d-542b-474a-8c55-630980e72c30
Upvotes: 6
Reputation: 909
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.
Upvotes: 3
Reputation: 10795
There is now an extension for Visual Studio 2012 and 2013:
http://visualstudiogallery.msdn.microsoft.com/da227a0b-0e31-4a11-8f6b-3a149cf2e459
Upvotes: 19
Reputation:
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! :)
Upvotes: 10
Reputation: 6867
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
Upvotes: 7
Reputation: 11170
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
Upvotes: 2