Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Qt creator can I comment each line, instead of commenting just the selection?

Tags:

c++

qt

I think this question must have been asked before, but I couldn't find any.

So in Qt creator, let's say that I have some code like this:

int var1;
int var2;
for (int i = 0; i < 10; i++) {
    // do sth
}

When I select a bunch of lines from the beginning of the first line till the end of the last line and toggle comment, I get this:

// int var1;
// int var2;
// for (int i = 0; i < 10; i++) {
//     // do sth
// }

But when I select from the middle of the first line, I get something like this:

int v/*ar1;
     ^ note the /*

int var2;
for (int i = 0; i < 10; i++) {
    // do sth
}*/
 ^ and */

What I would like is, have Qt creator comment using // from the beginning of each line selected, just like the first example.

Is there a way to do this? For all IDEs and editors I have used in the past (Atom, Sublime etc) this has worked, so I assume that there must be a way, but I can't seem to find it.

Thanks in advance.

like image 382
Semin Park Avatar asked Dec 29 '17 08:12

Semin Park


People also ask

How do you comment multiple lines in Qt?

You can select multiple lines in the editor and then right click.. There is an (Un)Comment selection and the shortcut is Ctrl+/ either for commenting or for uncommenting a line.

Are multi-line comments allowed in C?

Represented as /* any_text */ start with forward slash and asterisk (/*) and end with asterisk and forward slash (*/). It is used to denote multi-line comment.

How do you comment every line in once?

Press CMD + / (Mac) or CTRL + / (Windows). The highlighted lines are commented out. 3. Press CMD + / (Mac) or CTRL + / (Windows) again.

How do you select and comment multiple lines?

Press Ctrl + / To comment more than one line: Select all the lines that you would like to be commented.


1 Answers

Ctrl + / will comment in/out the line the cursor happens to be on.

If you have a selection that spans over the entirety of one or more lines, the // comment will be generated as well.

But if your selection doesn't span over entire lines, the /* */ format will be used.

That is very logical behavior that allows you to have both comment styles, depending on whether you want to comment out an entire line or just a small fragment. There is no benefit in losing the second commenting style, which can be quite useful at times, simply select lines end to beginning if you don't want the comment block style.

like image 108
dtech Avatar answered Oct 26 '22 00:10

dtech