Jon
Jon

Reputation: 1705

visual studio continue multiline comment

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

Upvotes: 3

Views: 1076

Answers (2)

Emerson
Emerson

Reputation: 101

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.

Upvotes: 0

kdbanman
kdbanman

Reputation: 10557

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.

Upvotes: 1

Related Questions