How to Comment Out Code in VS Code
Commenting out blocks of code is an essential practice for debugging and keeping your codebase clean. This article provides a quick guide on how to instantly comment and uncomment multiple lines of code in Visual Studio Code (VS Code) using keyboard shortcuts for Windows, macOS, and Linux.
The Quickest Method: Toggle Line Comments
The fastest way to comment out a highlighted block of code is to use
the Toggle Line Comment shortcut. This method adds the
language-specific single-line comment character (like // or
#) to the beginning of every selected line.
- Highlight the block of code you want to comment out.
- Press the following keyboard shortcut:
- Windows / Linux:
Ctrl+/ - macOS:
Cmd+/
- Windows / Linux:
To uncomment the code, simply highlight the block again and press the same keyboard shortcut.
The Alternative Method: Toggle Block Comments
If you prefer to wrap your selected code inside a single block
comment (such as /* ... */ in JavaScript or CSS), you can
use the Toggle Block Comment shortcut.
- Highlight the block of code you want to wrap.
- Press the following keyboard shortcut:
- Windows / Linux:
Shift+Alt+A - macOS:
Shift+Option+A
- Windows / Linux:
Like the line comment shortcut, pressing this combination again on the selected block will remove the comment.