How to trick Visual Studio to not show line numbers for blank lines?

Going through my folder of my blog “contact me” emails, I came across this question. I like tricking Visual Studio into doing things, so I thought I’d share.

Is there a way to display only line number of coded lines, i.e. don’t number blank lines? Numbered blank lines makes showing code in powerpoint decks hard to follow.

Here’s the screenshot of what could go into your powerpoint deck.

line numbers only on real lines of code

To do this,

  1. Enable Word Wrap (Tools Options – Text Editor – All Languages – General)
  2. At the end of the first real line (like #28 above), start inserting white space until it goes off the screen. Note the Word Wrap glyph.
  3. Turn off the Word Wrap glyph (same place as in step 1) and Turn off “View White Space” (Edit – Advance – View White Space)

Here’s what the hack really looks like

what hack looks like using visible white space

Sorry, this isn’t the start of a new VS tip series. Just wanted to share some q&a that have come in through my blog.

Technorati Tags: VS2005Tips,VS2008Tips

Comments (3)

  1. Wouldn’t it be less hassle to just take screen shots of every page of code, open the resulting images in a hex editor and locate the bits that correspond to the line numbers you want to hide and turn them white? Plus if you trigger auto format all that hard work is gone.

  2. Mike says:

    Um, perhaps knowing something about these "powerpoint decks" would help, but this seems like a really lame way to get what is being asked for.

  3. Sara,

    In Visual Studio, I would run a "Find and Replace", passing "{n} *n" in the "Find what:" field and "(120,1)" in the "Replace with:" field, assuring to "Find Options" > "Use" > "Regular Expression" be selected. If one has a wider monitor screen, it is just a matter of replacing 120 to a bigger number.

    Just don’t forget to WARN your readers, this is for presentation purposes ONLY and code changes SHALL never be committed/saved to disk 🙂

Skip to main content