Blog · · 3 min read

VS Code shortcut to comment out code (line and block)

Ctrl+/ toggles a line comment in Visual Studio Code on Windows and Shift+Alt+A a block comment. The add and remove variants, why Ctrl+/ fails on many non-US keyboards, and how to fix it.

In Visual Studio Code on Windows, press Ctrl+/ to comment out the current line or every selected line. Press it again to remove the comments.

For a block comment around the selection, such as /* ... */ in JavaScript or CSS, press Shift+Alt+A.

All four comment commands

From the VS Code default keyboard shortcuts reference, on Windows:

  • Toggle Line Comment: Ctrl+/ (command editor.action.commentLine)
  • Toggle Block Comment: Shift+Alt+A (command editor.action.blockComment)
  • Add Line Comment: Ctrl+K then Ctrl+C (command editor.action.addCommentLine)
  • Remove Line Comment: Ctrl+K then Ctrl+U (command editor.action.removeCommentLine)

The toggle is what most people use. The add and remove pair is useful when a selection mixes commented and uncommented lines and you want them all to end up the same way.

VS Code uses the comment style of the file's language: // in JavaScript and C#, # in Python and PowerShell, <!-- --> in HTML. A language without a line comment, such as plain HTML, gets a block comment instead.

On macOS the toggle is Cmd+/ and the block comment Shift+Option+A.

Why Ctrl+/ does nothing

Your keyboard layout

This is the most common reason. VS Code's reference notes that its keys are shown "assuming a standard US keyboard layout", and its keybindings page explains that shortcuts follow your current layout. On many layouts, / is not a key of its own: on a German layout it is Shift+7, and on others it sits elsewhere. So "Ctrl+/" may really be a different combination on your keyboard, or no combination at all.

To find out what VS Code expects on your keyboard:

  1. Open the Keyboard Shortcuts editor with Ctrl+K then Ctrl+S.
  2. Search for editor.action.commentLine.
  3. The Keybinding column shows the keys for your layout. Double-click the row to assign a combination you can type, for example Ctrl+Shift+7 or anything free.

Another binding wins

An extension or your own settings can bind Ctrl+/ to something else. In the Keyboard Shortcuts editor, search for the key itself to see every command that uses it. VS Code also has a built-in tool for this: run Developer: Toggle Keyboard Shortcuts Troubleshooting from the Command Palette, press the shortcut, and the Output panel logs which command, if any, received it.

The focus is somewhere else

The comment commands work in the editor. If the cursor is in the terminal, the search box or a panel, Ctrl+/ goes there. Click in the code first.

The file has no language

A file that VS Code treats as plain text has no comment syntax, so there is nothing to toggle. Pick the language in the status bar at the bottom right.

Comment from a ring

RadialDeck is the radial menu for Windows that we make. When VS Code is in front, the same hotkey that opens your usual ring opens a VS Code ring, and the gallery has Comment as a ready-made slice. It sends the toggle-comment key for you, together with slices such as Palette, Quick open, Format, Find in files, Terminal, Source control, Debug and Zen.

If the Comment slice does nothing on your keyboard layout, change its keys to the combination you assigned in step 3 above, so the ring always matches what VS Code expects.

Every VS Code action in the gallery is on the VS Code page.

Quick reference

  • Toggle line comment: Ctrl+/ (macOS Cmd+/)
  • Toggle block comment: Shift+Alt+A
  • Add / remove line comment: Ctrl+K Ctrl+C / Ctrl+K Ctrl+U
  • Find the key on your layout: Ctrl+K Ctrl+S, search editor.action.commentLine
  • See what a key does: Developer: Toggle Keyboard Shortcuts Troubleshooting

RadialDeck is free for two rings, and Pro adds a ring per program such as the VS Code ring, with a 14-day trial. It is in the Microsoft Store.

Try it in RadialDeck

Free for two rings, with a 14-day trial of everything in Pro. Windows 10 and 11, from the Microsoft Store.

Get it from Microsoft or download the installer (.exe)