Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2019 C++ multiline comments

When a line is partially selected, this results in /**/ C-style comment:

#include /*<assert.h>*/
#include <stdlib.h>
#include <node.h>

When one or several lines is partially selected, this results in // C++-style comment:

//#include <assert.h>
//#include <stdlib.h>
#include <node.h>

All VS2019 comment options have this behaviour: Toggle Line Comment (Ctrl+K, Ctrl+/), Toggle Block Comment (Ctrl+Shift+/), Comment Selection (Ctrl+K, Ctrl+C).

Do these options behave differently in other languages?

I'm aware of C++-style comment drawbacks but would like to be able to use them for multiline comments where needed:

/*
#include <assert.h>
#include <stdlib.h>
*/
#include <node.h>

Is it possible to configure Visual Studio 2019 this way?

There are other similar questions but they refer to older VS versions and answers seem to be outdated.

like image 445
Estus Flask Avatar asked Apr 27 '26 18:04

Estus Flask


1 Answers

As far as I'm concerned, you should select the whole line (i.e. from the very first character of the line) in order to use c++ comments for multiple lines.

If there are comments among the selected lines, Ctrl+K,Ctrl+C will generate C++ style comments even if the selection does not start from the beginning of the lines.

For example:Select the content as shown:

enter image description here

And then Ctrl+K, Ctrl+C

enter image description here

If you select the whole line including spaces:

enter image description here

And then Ctrl+K, Ctrl+C,you will get C++-style comment for multiline comments

enter image description here

like image 153
Jeaninez - MSFT Avatar answered Apr 30 '26 08:04

Jeaninez - MSFT