How to Comment and Uncomment Multiple Lines in VS Code - Quick Guide

Aug 27, 2023

Quick Reference

Use your cursor to select multiple lines, then:

  • Windows/Linux: ctrl + /
  • Mac: command ⌘ + /

Detailed Guide

Single Line Comments

  1. Place cursor on the line
  2. Hit ctrl + / (Windows/Linux) or command ⌘ + / (Mac)
  3. Repeat to uncomment
// This line is commented
This line isn't

Block Comments

Useful for documenting functions or temporarily disabling code blocks:

  1. Select multiple lines
  2. Hit ctrl + shift + a (Windows/Linux) or option ⌥ + shift ⇧ + a (Mac)
/* This entire block
   is commented out
   using block comments */

Alternative Methods

Line Comments (Windows Only)

  • Comment: ctrl + k, ctrl + c
  • Uncomment: ctrl + k, ctrl + u

Custom Shortcuts

  1. Open Command Palette (command ⌘/ctrl + shift ⇧/shift + p)
  2. Type "Keyboard Shortcuts"
  3. Search for "comment"
  4. Click the shortcut you want to modify

Pro Tips

  • Line comments vary by language:
  • JavaScript/TypeScript: //
  • Python: #
  • HTML: <!--
  • CSS: /*

Code Formatting

Bonus shortcut for clean code:

  • Windows: shift + alt + f
  • Mac: shift ⇧ + option ⌥ + f
  • Linux: ctrl + shift + i

Need a blog platform? Check out Hexo+Vercel .