Typing comment delimiters manually wastes time. Every single day.
Learning how to comment in VSCode with keyboard shortcuts cuts that task down to a single keystroke. Whether you’re debugging JavaScript, documenting Python functions, or disabling HTML blocks, the right shortcut makes all the difference.
This guide covers the exact key combinations for Windows, Mac, and Linux. You’ll learn single-line comments, block comments, multi-line selection techniques, and how to customize keybindings to match your workflow.
By the end, commenting and uncommenting code becomes muscle memory rather than a manual chore.
How to Comment in VSCode

Commenting in VSCode is the process of adding non-executable text annotations to source code files using keyboard shortcuts or menu commands within Visual Studio Code.
Developers need this when documenting code logic, disabling code sections during debugging, or leaving notes for team members working on the same codebase.
This guide covers 4 methods requiring 30 seconds to 2 minutes and basic familiarity with Visual Studio Code.
Prerequisites
- Visual Studio Code version 1.80 or later installed on Windows, macOS, or Linux
- An open file containing any programming language (JavaScript, Python, HTML, CSS, etc.)
- Basic keyboard navigation skills
- Estimated time: 2 minutes
What Is a Comment in VSCode?
A comment is text within source code that the compiler or interpreter ignores during execution.
VSCode automatically detects your file’s programming language and applies the correct comment syntax.
Comments serve as software documentation directly inside your code files.
What Are the Comment Types in VSCode?
VSCode supports two primary comment formats: single-line and block comments.
The code editor handles syntax differences automatically based on the active file extension.
What Is a Single-Line Comment?
A single-line comment adds annotation text to one line only.
Common syntax includes // for JavaScript and C++, # for Python, and <!-- --> for HTML.
What Is a Block Comment?
A block comment spans multiple lines within a single comment delimiter pair.
JavaScript uses / /, Python uses triple quotes """, and CSS uses / / syntax.
How Do You Add a Single-Line Comment in VSCode?
Place your cursor on the target line and press the toggle comment shortcut for your operating system.
VSCode inserts the correct comment syntax at the line’s beginning based on the detected language.
The same shortcut works to uncomment code, making it a toggle command.
What Is the Windows Keyboard Shortcut for Single-Line Comments?
Press Ctrl + / to toggle a single-line comment on Windows or Linux.
This keybinding triggers the editor.action.commentLine command in the text editor.
Works with or without text selection.
What Is the Mac Keyboard Shortcut for Single-Line Comments?
Press Cmd + / to toggle single-line comments on macOS.
The Command key replaces Ctrl for most VSCode keyboard shortcuts on Mac systems.
Muscle memory builds quickly after a few uses.
How Do You Add a Block Comment in VSCode?
Select the code you want to comment, then use the block comment shortcut for your platform.
VSCode wraps the selection in multi-line comment delimiters specific to your programming language.
What Is the Windows Shortcut for Block Comments?
Press Shift + Alt + A to add a block comment on Windows or Linux.
Without selection, this inserts an empty comment block at cursor position.
What Is the Mac Shortcut for Block Comments?
Press Shift + Option + A on macOS.
Same behavior as Windows: wraps selected text or inserts empty delimiters.
How Do You Comment Out Multiple Lines in VSCode?
Select multiple lines using click-and-drag or Shift + Arrow keys.
Press Ctrl + / (Windows/Linux) or Cmd + / (Mac) to comment all selected lines at once.
Each line receives its own single-line comment prefix. This approach works well during debugging or when performing code refactoring.
How Do You Uncomment Code in VSCode?
Place cursor on a commented line or select multiple commented lines.
Press the same toggle comment shortcut (Ctrl + / or Cmd + /) to remove comment syntax.
Works for both single-line and block comments.
How Do You Toggle Comments in VSCode?
The Ctrl + / and Cmd + / shortcuts function as toggles by default.
Commented code becomes uncommented; uncommented code becomes commented. No separate keybindings needed.
How Do You Customize Comment Shortcuts in VSCode?
VSCode allows full keybindings configuration through the settings interface or JSON files.
Reassign shortcuts when defaults conflict with other extensions or personal preferences.
Where Do You Find the Keyboard Shortcuts Menu?
Open Command Palette with Ctrl + Shift + P (Windows/Linux) or Cmd + Shift + P (Mac).
Type “Keyboard Shortcuts” and select Preferences: Open Keyboard Shortcuts. You can also access this through settings.json in VSCode for direct JSON editing.
How Do You Change the Default Comment Keybinding?
Search for “comment” in the Keyboard Shortcuts editor to find all comment-related commands.
Click the pencil icon next to any command, press your desired key combination, then hit Enter to save.
What Are the Comment Syntax Differences by Programming Language?
VSCode detects file extensions and applies language-specific comment syntax automatically.
The same keyboard shortcut produces different output depending on active file type.
How Does VSCode Handle JavaScript Comments?
Single-line: // comment text
Block: / comment text /
JSDoc comments use / / for generating technical documentation.
How Does VSCode Handle Python Comments?
Single-line: # comment text
Multi-line uses consecutive # symbols or triple quotes """ for docstrings.
Learn more about commenting multiple lines in Python for detailed workflows.
How Does VSCode Handle HTML Comments?
HTML uses <!-- comment text --> syntax for both single and multi-line comments.
Same delimiters regardless of comment length.
How Does VSCode Handle CSS Comments?
CSS uses / comment text / exclusively.
No single-line syntax exists in standard CSS. SCSS and LESS support // for single lines.
Verification
Type a line of code, press Ctrl + / (or Cmd + /), and confirm comment syntax appears at line start.
Press the shortcut again to verify the comment removes correctly. Test in multiple file types to confirm language detection works.
Troubleshooting
Issue: Comment shortcut not responding
Solution: Check for keybinding conflicts in Preferences > Keyboard Shortcuts. Search “Ctrl+/” to see all commands bound to that combination. Disable conflicting extensions or reassign the shortcut.
Issue: Wrong comment syntax inserted
Solution: Verify the language mode in the bottom-right status bar. Click the language indicator and select the correct language manually. VSCode may misdetect files without extensions.
Related Processes
- How to format code in VSCode
- How to indent multiple lines in VSCode
- How to find and replace in VSCode
- Code review process for team collaboration
- Source control fundamentals for version management
FAQ on How To Comment In VSCode
What Is the Shortcut to Comment in VSCode?
Press Ctrl + / on Windows and Linux or Cmd + / on Mac. This toggle command adds or removes single-line comment syntax based on your file’s programming language. Works instantly without any selection required.
How Do I Comment Multiple Lines at Once?
Select the lines you want to comment using click-and-drag or Shift + Arrow keys. Press Ctrl + / (Windows/Linux) or Cmd + / (Mac). Each selected line receives its own comment prefix automatically.
How Do I Uncomment Code in VSCode?
Use the same shortcut that creates comments. Place your cursor on commented code and press Ctrl + / or Cmd + /. The toggle behavior removes existing comment syntax without needing a separate keybinding.
What Is the Block Comment Shortcut?
Press Shift + Alt + A on Windows/Linux or Shift + Option + A on Mac. This wraps selected text in multi-line comment delimiters like / / for JavaScript or CSS files.
Why Is My Comment Shortcut Not Working?
Check for keybinding conflicts with installed extensions. Open Keyboard Shortcuts from the Command Palette and search for your shortcut. Conflicting commands appear listed together. Disable or reassign the conflicting binding to restore functionality.
How Do I Change the Default Comment Keybinding?
Open Command Palette with Ctrl + Shift + P, type “Keyboard Shortcuts,” and select the preferences option. Search “comment,” click the pencil icon next to the command, then press your preferred key combination.
Does VSCode Support Different Comment Syntax for Each Language?
Yes. VSCode detects your file extension and applies correct syntax automatically. JavaScript uses //, Python uses #, HTML uses <!-- -->. The same keyboard shortcut produces language-appropriate output every time.
How Do I Add a Comment Without Selecting Text First?
Place your cursor anywhere on the target line. Press the comment shortcut without selecting anything. VSCode comments the entire line automatically. For block comments, an empty delimiter pair gets inserted at cursor position.
Can Extensions Improve Commenting in VSCode?
Yes. Better Comments adds color-coded categories like alerts, TODOs, and queries. Comment Anchors creates navigable bookmarks within code. These extensions integrate with the web development IDE features VSCode already provides.
What Is the Difference Between Line and Block Comments?
Line comments apply to single lines using syntax like // or #. Block comments span multiple lines within delimiter pairs like / /. Choose line comments for quick notes, block comments for disabling larger code sections.
Conclusion
Knowing how to comment in VSCode transforms the way you document and debug code. A few keystrokes replace tedious manual typing.
The toggle comment feature works across JavaScript, Python, HTML, CSS, and dozens of other languages. VSCode handles syntax differences automatically.
Ctrl + / for line comments. Shift + Alt + A for block comments. These two shortcuts cover most scenarios you’ll encounter during software development.
Customize keybindings through the Command Palette when defaults conflict with your setup. Extensions like Better Comments add even more functionality.
Practice these shortcuts daily. Within a week, code annotation* becomes automatic. Your editor productivity increases, and your codebase stays cleaner with proper documentation habits in place.
- Full-Lifecycle Product Strategy: From MVP Validation to Scalable Production Architecture - July 29, 2026
- How to Rename a Repository in GitHub: Quick Guide - July 28, 2026
- What Modern Teams Should Know Before Replacing Legacy PAM Tools - July 27, 2026



