Maintaining Consistent Line Lengths

Today’s tip comes from the “Anally Retentive” department. In the .NET CLR team likes to keep their lines of code under 110 characters long. I’m assuming that they’re trying to maintain consistency and readability. I often try to maintain an imaginary line length limit, but I doubt I’m very consistent.

Vertical line in Visual Studio

Fortunately, Visual Studio provides a hidden feature that lets you draw a vertical line in the text editor to show you where a certain line length would end. Fire up your registry editor and find this key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor

If you’re using a version of Visual Studio before 2008, you’ll need to decrement the 9.0 version number in the path above.

Then, add the following value (as a string or REG_SZ) with the name of “Guides”:

RGB(192,192,192) 110

The first part is the color, and the second part is the line length. Personally, I use a line length of 110 to stay consistent with how Microsoft has chosen to do it. I like the color listed above because it’s faint, but visible. Since the line is almost impossible to see in the screenshot above, here is an un-scaled screenshot of the line itself:

Vertical Line

To further enforce the 110 character limit, you could also resize the code portion of your Visual Studio window so that it’s near the line. This will make the line itself a little less annoying, while allowing you to use the rest of the window for other information. For example, take a look at how much room I have on a 1920×1200 screen when I horizontally resize my code window:

Utilizing a large monitor in Visual Studio 

Obviously this tip isn’t for everyone. You may be working with legacy code with long lines, or you might work on a team that doesn’t mind long lines. The great news is that Visual Studio is pretty accommodating to however you like to work.

Kick It!

4 Comments so far »

  1. Nick Koszykowski said,

    Wrote on April 6, 2009 @ 3:07 pm

    Reg key is correct, but the string Name should be Guides with RGB(192,192,192) 110 for Data.

  2. superjason said,

    Wrote on April 6, 2009 @ 3:14 pm

    Thank you, good catch! I added the name of the string value.

  3. Arjan`s World » LINKBLOG for April 7, 2009 said,

    Wrote on April 7, 2009 @ 3:28 pm

    [...] Maintaining Consistent Line Lengths – Jason Young Nice tip to fiddle a vertical line in Visual Studio helping you to see when your own max_line_length has been reached [...]

  4. Vishal Bhatt said,

    Wrote on June 24, 2010 @ 4:34 am

    Very nice tip.

Comment RSS · TrackBack URI

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Comment: