How to Comment Multiple Lines in VS Code

Here are a couple of tips on commenting out multiple lines of code in VS Code.
Warp Terminal

Comments are generally used to make code easy to understand and maintain. Commenting out sections of code is also part of the debugging process.

Now, different programming languages have different ways of adding comments. To add comments in bash, you use # and in C/C++, you use //.

Things become easier when you use a code editor like VS Code. The editor has hotkeys to add comments irrespective of the programming language.

πŸ‘‰
Select the desired lines of code and then use Ctrl + / to comment them out in VS Code.

Not clear yet? Let me go in detail.

Comment out a block of code in VS Code

The first step in commenting out a block of code is to select lines with the mouse. You can also use Ctrl + shift with down and up arrow keys:

select code
Select the code block first

But selecting the entire block of code might not be the most convenient way, especially while dealing with large projects. In that case, you can collapse the entire block of code by clicking on the little arrow located beside the number of lines:

select the entire block of code in vs code
For huge code block, collapse the block and then select it

Once you select the code in any of the shown ways, you just have to use Ctrl + / (Forward slash), and the selected block will be commented out:

comment block of code in vs code
Use Ctrl+/ after selecting your code block to comment it out

But this was specific to only comment out the block of codes, but what if I tell you can comment on multiple lines placed randomly?

Bonus Tip: Comment out multiple lines placed randomly in VS Code

Need to comment out multiple lines that are not together? You can of course keep on pressing Ctrl+/ when you are on the desired lines.

But there is a neat trick pro VS Code users love to use here.

Hold the Alt key and click anywhere inside the line you want to comment out. And you’d see multiple cursors, something like this:

enable multiple cursors in vs code
Hole Alt key and click on the desired lines

Once you are done placing cursors at desired lines, you can comment them out by using Ctrl + /:

comment out multiple lines in vs code
Commenting multiple lines in VS Code

A pretty neat way to comment out lines. Isn’t it?

Wrapping Up

Coing background image
Image Credit: Depositphotos

This was a quick tutorial on how you can comment out multiple lines in VS Code. While VS Code is open source, the installation files contain tracking to help them improve user experience.

And if you want to have complete control, you can use VSCodium which is a clone of VS Code but does not track your data.

I hope this quick little tip on adding comments in VS Code helps you with this awesome code editor.

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.