shortcutsguide

Comment Out Shortcut (⌘/ / Ctrl+/)

Toggle a line comment instantly: press Ctrl+/ on Windows or ⌘/ on Mac in VS Code. Here it is with block comments and other editors.

ActionMacWindows
Toggle line comment (VS Code) ⌘/ Ctrl+/
Toggle block comment (VS Code) ⇧⌥A Shift+Alt+A
Toggle comment (Sublime Text) ⌘/ Ctrl+/
Toggle comment (JetBrains) ⌘/ Ctrl+/
Block comment (JetBrains) ⌘⌥/ Ctrl+Shift+/

Comment out a line or selection

In VS Code, press Ctrl+/ (Windows/Linux) or ⌘/ (Mac) to comment out the current line, or the whole selection if several lines are highlighted. Press it again to uncomment — it is a toggle. The editor automatically uses the right comment syntax for the language (//, #, <!-- -->, and so on).

Block comments

For a wrapping block comment use Shift+Alt+A (Win) / ⇧⌥A (Mac) in VS Code. Most editors share Ctrl+/ / ⌘/ for line comments, so the habit carries between Sublime, JetBrains and VS Code.

Troubleshooting: Ctrl+/ does nothing

On some non-US keyboard layouts the / key sits behind Shift, so Ctrl+/ never registers. Try Ctrl+Shift+7 (a common alternative on German/Nordic layouts) or rebind Toggle Line Comment to a key you can reach. If the comment appears but code still runs, make sure the file language mode (bottom-right in VS Code) matches the actual language.

FAQ

How do I comment out code in VS Code?

Ctrl+/ on Windows/Linux or ⌘/ on Mac toggles a line comment on the current line or selection. Press again to uncomment.

How do I add a block comment?

In VS Code use Shift+Alt+A (Windows) or ⇧⌥A (Mac); JetBrains uses Ctrl+Shift+/ or ⌘⌥/.

Why does Ctrl+/ not comment anything?

On some keyboard layouts the / key requires Shift, so Ctrl+/ isn't detected. Try Ctrl+Shift+7 or rebind 'Toggle Line Comment' in the keyboard shortcuts.

Does the comment shortcut know my language?

Yes — the editor picks the correct comment syntax from the file's language mode, so the same shortcut works in JavaScript, Python, HTML and more.