22

I am trying to find solution how to hide and unhide comments in VS2010. What i found is:

# region 
comments for code
#endregion

and:

http://holyhoehle.wordpress.com/2010/01/17/hide-comments-in-visual-studio/

but this one is not working in VS2010 or i don't know how to...

So maybe any one can help and offer some solution how to hide comments like:

string x = "...." //comment
rfmodulator
  • 3,638
  • 3
  • 18
  • 22
zee
  • 415
  • 1
  • 7
  • 13
  • 22
    Go to the editor options and set the color of comments to white? :) – Ilya Kogan Jan 02 '12 at 00:45
  • 6
    lol, yeah...generally comments are meant to be seen, as they add something meaningful to the information...except this one. – rfmodulator Jan 02 '12 at 00:49
  • 2
    make white good one :) , "comments are meant to be seen" yes i know that but when you have a lot of them and you already know all code you don't need them. You need them after year or for other people to understand. – zee Jan 02 '12 at 00:52
  • 7
    @zee: strive for self-describing code. Comments should be used to explain non-obvious intent. – Mitch Wheat Jan 02 '12 at 01:07
  • 1
    "Comments are meant to be seen" ... by the people actually using my classes in their own code. Self-describing code is excellent practice for writing code but is useless to people consuming those objects. Comments are useful to them but are a major annoyance when writing self-describing code. – SixOThree Aug 19 '13 at 15:25

6 Answers6

35

this extension is no longer maintained

I made a Visual Studio extension that allows you to hide/show comments.
You can get it here:

for Visual Studio 2010-2013
for Visual Studio 2015-2017

3dGrabber
  • 4,710
  • 1
  • 34
  • 42
  • 2
    Looks good though I can't try it yet as I'm mainly developing in VS 2015--any chance of an update for VS 2015 support? (Coding in C# so I'd hope it wouldn't be a huge update) – matthewsheets Jun 03 '15 at 17:24
  • 3
    I'm thinking about a rewrite. In VS2015 I could rely on the built-in Roslyn parser and ditch the dependency on NRefactory. Just doesn't make sense to continually parse the source with 3 different parsers (VS + NRefactory + ReSharper). Should help with performance, although that wasn't really an issue so far. – 3dGrabber Jun 05 '15 at 09:20
  • 1
    @3dGrabber I've always liked your plugin. Any chance it's open source? I'd really like a VS2015 version. – craftworkgames Sep 08 '15 at 11:36
  • There's a nasty null reference error in the VS 2013 version in "HideShow.Implementation". It seems to occur when Intellisense is triggered within an object initializer block. – Triynko Jan 18 '16 at 00:22
  • 3
    @3dGrabber Do you plan on VS 2015 support? If no, can you open source it? – Hooch Apr 19 '16 at 12:18
  • 1
    @Hooch et al: I realeased a 2015+ Version based on Roslyn. See edit above. – 3dGrabber Jan 19 '17 at 13:52
  • 2
    This extension does not use async load, so it no longer works in VS2019. – Aaroninus Jul 03 '19 at 14:25
  • Doesn't work for VS2019, in fact my VS is crashing because of the extension. I removed it now. – Suleman Aug 01 '19 at 14:03
  • How about VS2022? – Kux Jun 08 '22 at 13:45
12

You can highlight them one by one, Right-click, and choose Outlining > Hide Selection.

The keyboard shortcut for that maneuver is Ctrl+M, Ctrl+H.

rfmodulator
  • 3,638
  • 3
  • 18
  • 22
  • This is a useful option, but it isn't remembered - if you close the tab that you did that in, the hidden selection is forgotten. – slugster Jan 02 '12 at 01:02
  • @slugster You're Wrong again, sorry. It's even saved between VS sessions. :) Better luck next time. – rfmodulator Jan 02 '12 at 01:06
  • Nope, not wrong - I thought I would give you the benefit of the doubt (maybe it was only VS2008 that forgot it) so I just tried it, closed that tab, reopened that particulr class and... voila!! the comment was no longer hidden. Reversal of your downvote would be appreciated. Either that or update your answer to be more complete. Didn't think I was wrong - I used to use this method quite extensively when working on large javascript files. – slugster Jan 02 '12 at 01:11
  • 1
    It's confirmed working on VS2010 Ultimate SP1, between file sessions, and VS sessions. All hidden content is remembered as such. – rfmodulator Jan 02 '12 at 01:14
  • Ok, I just checked this a bit more. I have two machines both running VS2010 Premium SP1, one with ReSharper and one without. The one with ReSharper remembers, the other doesn't. So the next question would be: are you running a plugin that is remembering this on behalf of VS? – slugster Jan 02 '12 at 01:30
  • @slugster Do you also have StyleCop for RS? I used to have StyleCop, it's uninstalled now, but I still have the Close All option on the tab context menu... So I can't say that it's not because of that. – rfmodulator Jan 02 '12 at 01:39
  • Visual Studio 2013 with no Resharper remembers the Hide Selection. At least after closing and opening the tab. – Mehrad Sep 29 '14 at 23:10
  • Perfect! I presenting the code as instruction and I use the comments as a "reveal". – Tony D May 09 '16 at 17:50
10

Aside from setting the font color of the comments to the same as the background color (which is what that VS plugin that you mentioned does), there is no way to hide comments.

Multi line comments (prefixed with either // or /* */ are already collapsible, but single line comments are not natively. Your only option for those is to use the Ctrl-MH key chord for a temporary (while the file is open) collapse (as mentioned in @rfmodulator's answer), or remove them altogether.

*The default C# key chord for collapsing all collapsible blocks is Ctrl-MO

slugster
  • 49,403
  • 14
  • 95
  • 145
  • See my answer for the single-line collapse procedure. – rfmodulator Jan 02 '12 at 01:01
  • @rfmodulator And see my answer about it. Your option means you have to go through every comment manually and apply it - I doubt the OP really wants to do something as impractical as that. – slugster Jan 02 '12 at 01:06
  • For me multi line comments are not collapseable... How can I get them to be again? (Visual Studio 2017 ) – harlekintiger Sep 21 '19 at 14:31
  • Fruits of my experiments: Having `/*` without a closing will be collapsible. Adding the closing `*/` results in VS removing the collapse button. – harlekintiger Sep 21 '19 at 14:43
2

You could use this macro to collapse all of the XML comments. I suspect that's about as good as you're going to get.

There is no way other than changing the comment color to hide inline comments and I could see that leading to all sorts of problems.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
1

To hide the selected code or area (first select the area), just use Ctrl + M, Ctrl + H. This works for any selection.

Kibria
  • 141
  • 1
  • 1
  • 13
1

Using shortcut keys: Simply select your comment or working code and the just press:

Ctrl+M, Ctrl+H -> To hide (this simply collapse your selected section and make small box preview)

Ctrl+M, Ctrl+U -> To uhide

anil shrestha
  • 2,136
  • 2
  • 12
  • 26