Visual Studio 2005. Working with C++, is there a way to have it automatically continue commenting when I press Enter? Ex, I type '//' and begin entering my long-winded comment. When I press Enter, I want it to automatically place a '//' sequence at the current indent level (or a '*' if commenting with C-style comments). I have not yet googled me up a solution (though it seems many folks want the C-style comment continuation removed).
- try placing \ before hitting enter. Yes this is a cheat, but it gets the work doneCreris– Creris2015-04-23 20:31:26 +00:00Commented Apr 23, 2015 at 20:31
- Use /* and */ to delimit your comments, or an #if 0 ... #endif block.Dan Korn– Dan Korn2015-04-23 20:41:42 +00:00Commented Apr 23, 2015 at 20:41
- 1I know I can use the C style comments, I like the auto-comment feature. The \ "cheat" did not work. I gather then, that what I am looking for does not exist?Jon– Jon2015-04-23 21:01:24 +00:00Commented Apr 23, 2015 at 21:01
2 Answers
I've exhaustively searched the editor preferences in VS 2013, there is currently no option to auto continue a // comment.
However, with triple slash (///) comments, you have a couple of options:
A triple slash comment line will automatically continue after pressing Enter if:
The comment line at the cursor contains any non-whitespace character. I like this condition, because I can keep typing as normal, then double-tap
Enterto terminate the comment. It ends up looking like this:/// This is my multiline comment.Press
Enterand type more comment:/// This is my multiline comment. /// I just pressed enter. Now I'll press enter twice and start coding.Press
Entertwice and type code:/// This is my multiline comment. /// I just pressed enter. Now I'll press enter twice and start coding. /// public class ...The comment line below the cursor contains another triple slash comment. This allows you to have big comments with multiple paragraphs and usage examples separated by empty lines. Here it is:
/// There is already a comment line below. CURSOR IS HERE -> | ///Press
Enterthree times and start a usage example:/// There is already a comment line below. CURSOR IS HERE -> | /// /// /// For Example: /// /// Foo foo = bar; ///The empty comment line remains, and you can continue commenting arbitrarily.
1 Comment
One hack is to press Space Left Enter when at the end of a comment. It seems to discard the extra space as well.
VS splits comments across multiple lines nicely if you press Enter midway through a comment, so this is tapping into that functionality.
You might be able to make a hotkey that makes Enter always do this in VS, as it discards the space even when not in comments.