23

I've looked, but it doesn't look like you can apply specific formatting to just comments.

Deane
  • 8,269
  • 12
  • 58
  • 108

7 Answers7

4

No. The shortcut is Ctrl+E, Ctrl+W.

There would be one trick how to format the comments. Write your own code snippet for the comment.

nubm
  • 1,153
  • 2
  • 14
  • 32
4

Well, there is an Add-In which will automatically format your comments to a given width (as a side feature).

It is HyperAddIn - the main feature of which is allowing you to create 'hyperlinks' to other places in your code within comments, like this:

// The other half of this logic is in code:ComponentManager.Initialise()

With HyperAddIn installed, the code:ComponentManager.Initialise() becomes a clickable link.

I have it installed, it works OK, but I must admit that most of the time I don't have the comment formatting switched on.

Benjol
  • 63,995
  • 54
  • 186
  • 268
3

CodeMaid's page lists re-flowing comments among its many code-beautification features.

Eponymous
  • 6,143
  • 4
  • 43
  • 43
3

As I have not found anything suitable so far, I use Vim. I set Open in &Vim as an external tool command, so I can just press Alt+T,V to open the current file in it. In Vim, I find the comment (press / for incremental search), select it (Shift+V selects whole line) and gq command formats the selected text. Finally, :wq and I am back in Visual Studio.

Hopefully, some simple extension appears in future or VsVim will get this feature.

Lukas Cenovsky
  • 5,476
  • 2
  • 31
  • 39
  • I love this solution! I use VsVim, most of the time, but I often want to drop into Vim for the full experience. This gives me the ability to do just that with ease. I wish I could up-vote this answer another time. – Ben Jacobs May 28 '14 at 17:09
1

The free AtomeerUtils addin mentions such a feature:

  • Word-wrap the text in a block comment.

I have not tried it.

JRL
  • 76,767
  • 18
  • 98
  • 146
-3

You can extend VS 2010 to do this http://code.msdn.microsoft.com/ToDoGlyphFactory

Raj Kaimal
  • 8,304
  • 27
  • 18
-4

It may not answer the question directly, but, instead of:

//Writing a really really long comment on one line that should probably be broken up into multiple lines anyhow

Why don't you:

//Break your comments up into multiple lines so that
//you don't need to worry about them wrapping?

Also, I don't like long lines of code - break them up across multiple lines so it's easier to read. All a matter of preference I know, but if you have to scroll horizontally to see all the code, it's a good sign it needs formatting better IMO.

Mike
  • 6,149
  • 5
  • 34
  • 45
  • 17
    This is an epic pain to manage. If you add to or elaborate on your comment, you have to go back and fix all the hard line breaks you added. – Deane Apr 10 '10 at 14:35
  • 1
    @Deane: I don't know, I've used this method for over 10 years and it's been fine. Of course, it's anecdotal, but I do think you can trivially follow this approach (and it's "scalable" to any editor :P) – Noon Silk Apr 12 '10 at 07:36
  • 10yrs on and this approach still works perfectly for me. – Mike Apr 21 '21 at 22:52
  • This is great, except when it's your coworkers' code -_- – Fried Brice Jan 24 '22 at 23:25
  • I don’t agree sorry. With code formatters there’s really no issue in this approach. In JavaScript/Go (primary languages for me) the code is formatted on every save and multi line comments like this have no negative impact. – Mike Jan 25 '22 at 12:23