views:

187

answers:

4

When I write a comment, it's often a paragraph or a few lines that explains clearly what a bit of code is doing and why it's doing that.

What I'd like is if I could start a comment, and have the editor automatically insert a line break and continue the comment to the nest line when I reach, say, 80 characters long.

So I'd type:

// Lorem ipsum dolor sit amet, consectetur adipiscing elit. < here the editor breaks automatically and continues onto the next line: >

// Etiam congue quam eget leo dignissim tincidunt.

A: 

Wouldn't it simply be easier for you to use the /...../ comment notation and simple hit enter whenever you want to create a new line.

/* Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam congue quam eget leo dignissim tincidunt. */

Mentee
No, that's not easier, it's what I do right now. I want the breaks to be automatic.
Pete Michaud
+1  A: 

I'm pretty late to this, but I believe if you use /// rather than // when you hit enter it automatically types another set of ///

not sure why or what specifically the /// is for vs. the // but it works as a comment none the less.

Hope this helps~

Aaj
/// is for generating xml from comments I believe.
Philip Wallace
+1  A: 

I'm not aware of anything automatic, but you could try the excellent Comment Reflower plugin. It will wrap the comment containing the cursor at the press of a key or toolbar button. Supports sensible markup for non-wrapped regions, configurable bullet points and comment styles and wrap columns. Transformed my commenting; these days, I'm lost without it.

I use the original one myself on VS2005:

http://commentreflower.sourceforge.net/

And hre's what's alleged to be a port to VS2008, though I don't use VS2008 myself:

http://www.kynosarges.de/CommentReflower.html

(Regarding automatic wrapping, I had this switched on in emacs for a while and found it somewhat cumbersome, with an annoying habit of reformatting commented-out code if you did the wrong thing. So the lack of anything automatic may not be such a bad thing.)

brone
A: 

I haven't found a way to do it automatically as you type, but VS 2008 comes with a macro to insert line breaks on command.

  1. Go to Tools > Options > Environment > Keyboard
  2. Find the Macros.Samples.VSEditor.FillCommentParagraph command
  3. Bind it to a shortcut key. I used Alt+Q because I'm used to the Emacs command.

When the cursor is in a long comment line, use the shortcut key. The first time it will ask you how long you want each line to be.

Unfortunately, it seems like it only goes from a long line to a paragraph. I don't know how to make it refill the paragraph after you edit it like Emacs auto-fill.

Alex