3

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).

3
  • try placing \ before hitting enter. Yes this is a cheat, but it gets the work done Commented Apr 23, 2015 at 20:31
  • Use /* and */ to delimit your comments, or an #if 0 ... #endif block. Commented Apr 23, 2015 at 20:41
  • 1
    I 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? Commented Apr 23, 2015 at 21:01

2 Answers 2

1

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:

  1. 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 Enter to terminate the comment. It ends up looking like this:

    /// This is my multiline comment. 

    Press Enter and type more comment:

    /// This is my multiline comment. /// I just pressed enter. Now I'll press enter twice and start coding. 

    Press Enter twice and type code:

    /// This is my multiline comment. /// I just pressed enter. Now I'll press enter twice and start coding. /// public class ... 
  2. 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 Enter three 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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm, not working for me in Visual Studio 2017 in a C++ project, is there an option I'm missing?
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.