04 September 2007

Visualize Right Margin in Visual Studio

ReSharper has formatting option to keep your source code lines below certain limit.
In Options, go to Languages / C# / Formatting Style / Line Breaks and Wrapping, find "Wrap long lines" below "Line Wrapping" group and enable it, then set "Right margin (columns)" to the desired value. That's pretty cool, but how can one see which lines will be wrapped?

Meet Visual Studio secret feature: Guides!

As described in this blog post, you can play a bit with registry and make Visual Studio display nice dotted vertical lines at specific column:

  • Open "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor" key

  • Create new string value "Guides"

  • Set its value to something like "RGB(192,192,192) 119" (columns in registry are zero-based)

  • Restart Visual Studio


Now you will be able to see when your lines are too long, and probably make manual formatting before ReSharper will split lines at next reformat.

10 comments:

Richard said...

Do you know if this works in VS2005 as well as Orcas?

Ilya Ryzhenkov said...

For VS 2005 you should change registry path from "9.0" to "8.0". I didn't try it, but from the blogs I can say it should work.

Tomas Vykruta said...

I just tried VS2005, it works.

Pradeep said...

I donot have Test Editor under VisualStudio\9.0\ in registry ???
what should be done??

Ilya Ryzhenkov said...

Pradeep, I don't know, sorry, do you look in Current User hive, not Local Machine?

Pradeep said...

hey thanks for the reply. I did look under Current User hive.
Let me google it, If I found a soln I shall post it here.

Dinesh said...

Pradeep, you should look for 'Text Editor' not 'Test Editor'.

daspecster said...

I cannot believe that VS doesn't have some option setting for this silly regedit...

Brett Veenstra said...

For VS2010, check out http://stackoverflow.com/questions/2660491/right-margin-marks-in-vs2010-text-editors

Anonymous said...

This no longer seems to work in 2012.