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.
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.
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.
Press CMD + / (Mac) or CTRL + / (Windows). The highlighted lines are commented out. 3. Press CMD + / (Mac) or CTRL + / (Windows) again.
Press Ctrl + / To comment more than one line: Select all the lines that you would like to be commented.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With