Excluding Text Lines In Visual Studio

Environment: Visual Studio

Description:

Computers used to work primarily in text mode on screens of 25 rows of 80 columns. In those days it was common for text editors to allow you to exclude groups of lines so that you instead only saw a single special line representing the fact that lines were being hidden from view. Although displays now allow far more than 25 lines, it is still of use to exclude lines that are otherwise in the way. For example, if you are doing a file conversion it might be convenient to hide from view those portions you have already modified.

The simple VBScript macro below provides this feature that lacks native support within Visual Studio. I won't argue that this is an ideal implementation but it ought to work in general. To implement it, unzip exclude.dsm from the attached zip file to some place on your computer. Next, do the following:

  1. Unzip exclude.dsm from the zip file below
  2. Within Visual Studio click on Tools/Customize.../Add-ins and Macro Files
  3. Browse and select the exclude.dsm file
  4. Check the box to the left of exclude.dsm in order to enable it

If you'd like to assign keys to these functions:

  1. Click on Tools/Customize.../Keyboard/Category/Macros
  2. Select exclude then assign something to it such as Alt+X
  3. Select unexclude then assign something to it such as Alt+U

How it works:

When you select some lines then perform an exclude it cuts those lines and pastes them into a file named excludes.txt that is placed next to msdev.exe (if you don't like this location then simply modify the GetExcludeFileName function so that it instead returns where that file ought to be located). Unexclude works in reverse. When you perform an exclude it creates a special line that it puts in place of the removed lines that looks like this:

<===== Excluded Lines=5 Date=9/6/01 Time=1:31:51 PM =====>

This signature is used during an unexclude operation. You must place the cursor on that line when you want to perform an unexclude to bring the lines back.

Limitations and improvements:

You mustn't exclude two groups of lines within the same second, not that I believe that is possible.

If you have an improvement please let me know!

Downloads

Download source - 1.25 Kb


Comments

  • project manager

    Posted by Thelma Block on 12/15/2013 08:14am

    I would like to leave the code in place (others require this) but identify it as excluded code in some way, so that it could be blocked, i.e. collapsed/expanded, and have fonts/colors or at least colors used in the VB IDE. My company likes to leave previous code in place for historical reasons, but I find it confusing and often misleading. If it could be collapsed or at least a light gray so that the real comments stand out in green, I believe it would be a real productivity enhancement for my programmers

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

  • Protecting business operations means shifting the priorities around availability from disaster recovery to business continuity. Enterprises are shifting their focus from recovery from a disaster to preventing the disaster in the first place. With this change in mindset, disaster recovery is no longer the first line of defense; the organizations with a smarter business continuity practice are less impacted when disasters strike. This SmartSelect will provide insight to help guide your enterprise toward better …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds