REW

What Is The Shortcut For Multiline Comment In CPP?

Published Aug 29, 2025 3 min read
On this page

In C++, the syntax for a multiline comment is to wrap the text between /* and */. There is no universal keyboard shortcut for this syntax, as the shortcut depends entirely on the specific code editor or Integrated Development Environment (IDE) you are using.

For most modern IDEs, you can create a multiline comment by first selecting the block of code with your cursor, and then using a designated shortcut to automatically apply comments to every line.

Multiline comment shortcuts by editor

Visual Studio Code (VS Code)

  • Toggle Block Comment:
    • Windows/Linux:Shift + Alt + A
    • macOS:Shift + Option + A
  • Toggle Line Comment on Multiple Lines:
    • Windows/Linux:Ctrl + /
    • macOS:Cmd + /
    • How it works: This command places // at the beginning of every selected line, which achieves the same result as a block comment.

Microsoft Visual Studio

  • Toggle Block/Line Comment:
    • Windows: First, select the lines you want to comment out. Then press Ctrl + K, followed by Ctrl + C.
    • Uncomment: To remove comments, use Ctrl + K, followed by Ctrl + U.
  • How it works: This shortcut uses the C++ single-line comment // and applies it to every selected line.

Eclipse

  • Add Block Comment:
    • Shortcut: Select the block of code, then press Ctrl + Shift + /.
  • Remove Block Comment:
    • Shortcut: Select the block of code, then press Ctrl + Shift + \.
  • How it works: Eclipse will use the /* ... */ syntax to wrap the selected text.

CLion (JetBrains IDEs)

  • Toggle Block Comment:
    • Windows/Linux:Ctrl + Shift + /
    • macOS:Cmd + Shift + /
  • How it works: CLion automatically wraps the selected text with the /* ... */ block comment syntax.

The C++ standard for multiline comments

Even without an IDE, C++ defines a standardized way to create multiline comments, also known as block comments. You can type this syntax by hand in any text editor.

Syntax

A multiline comment begins with /* and ends with */. Everything placed between these two delimiters is ignored by the compiler.

/*
This is a multiline comment.
It can span across many lines
and is ignored by the C++ compiler.
*/
int x = 10; // The code resumes here

Use code with caution.

Important considerations

  • No nesting: A crucial rule for C-style /* ... */ comments is that they cannot be nested. An attempt to place one block comment inside another will result in a syntax error.cpp

    /* Outer comment /* Inner comment */ Still part of outer comment */ // ERROR: The compiler sees the first "*/" and doesn't know what to do with the second.
    

    Use code with caution.

  • Use for debugging: Block comments are very useful for quickly disabling large chunks of code for debugging purposes, without having to delete the code itself.

  • Readability: For shorter, line-by-line comments, using a series of // comments is often more readable. A block comment is generally reserved for more extensive descriptions or explanations.

Enjoyed this article? Share it with a friend.