Wednesday, June 06, 2007

Visual Studio Tips.. 80 Character Guideline

Enabling Guidelines in Visual Studio

Lots of people wants to limit the number of character in one line of their code to be maximum of 80/100. This is done basically for readability. Believe me, code looks really readable if you follow the character limit for one line. Here is the way to have character guidelines in microsoft visual studio editor.

First, shut down Visual Studio if already started.Open Registry editor (start>run>regedit.exe). Browse to

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\7.1\Text Editor]

[here 7.1 is used for visual studio 2003, look for 8.0 if you use vs 2005, or 9.0 for vs 2008]. Create a string value called

Guides

Set Guides to the following

RGB(x,y,z) n1,...,n13

Where x,y,z are the RGB values and n is the column number. You can have at most 13 guidelines. For example set the Guides value data to,

RGB(128,0,0) 80,100

This will place a Red guideline at column numbers 80 and 100.
And now launch VS and open any text file.

Disabling Guidelines
Just delete the Guides keys you created above. Restart VS, and no more guidelines.

Easier Way:
You can download following registry file and run which will do the same thing.
vs2003_guideline.reg
vs2005_guideline.reg
vs2008_guideline.reg
vcs2008ExpressEdition_guideline.reg

If you find this post useful, you might also like [this] and [this] post by me as well.

Thanks

15 comments:

Anonymous said...

Thanks! Just what I was looking for!

Unknown said...

Wonderful!
Exactly what I was looking for...

Unknown said...

Seems to be an off-by-one error. The registry must be counting on a 0-start array rather than 1-start because my lines came up at col 81 and 101.

Thanks for the info though!

kzarog said...

Thank you for the excellent tip!

Arif Siddiquee said...

Thanks for the insight Daniel. But I think the one i posted is right. VS starts column number counting from 1.

SnowyIVu said...

Awesome, I definitely needed this!

Arif Siddiquee said...

Glad to hear that.

Unknown said...

I tried this but it doesn't work. I have Visual C# 2008 Express Edition - is that the problem?

Arif Siddiquee said...

I am not sure about the Visual C# 2008 Express Edition, never tried on that. Can you try with this? HKEY_CURRENT_USER\Software\Microsoft\VCExpress\9.0\Text Editor

Unknown said...

Yes, that worked perfectly. Thanks so much for the quick response! I should have been able to figure that out myself, but it didn't occur to me that VCS stood for Visual C# Studio.

Thanks again!

Arif Siddiquee said...

Glad it worked for you. :D

Thomas Sedlaczek said...

Wonderful!!!

You made my day!
I was annoyed for years with the fact the VS doesn't provide a setting to highlight print margin. Thank you sooo much for solving this issue! ;-)

Anonymous said...

Thank you so much, this is exactly what I needed.

Anonymous said...

I would appreciate more visual materials, to make your blog more attractive, but your writing style really compensates it. But there is always place for improvement

Joseph McCullough said...

Wow, this is exactly what I needed! I was tired of guessing all the time!