Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Better Block CommentsNew to Visual Studio Code? Get it now.
Better Block Comments

Better Block Comments

Scott Rhamy

|
9 installs
| (0) | Free
Supports nested delimiter support, universal comment via single hotkey
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Better Block Comments (BBC)

Language support

Unlike other extensions, Better Block Comments works with ANY language that has block-comment syntax. No language-specific configuration needed. For purposes of this README, I will assume JS/TS for explanation sake.

REFERENCE: Javascript / Typescript Comment Types

// I am a single line comment

/* I am a block comment and can span multiple lines */

Maintains built in VSCode block comment functionality

  • Multi-cursor support
  • Appropriate selection adjustment after toggling/untoggling
  • Undo stack similarly supported

Additions to VS Code's built-in block comment

Behaviour VS Code built-in Better Block Comments
Selection contains an existing /* */ Breaks — inner */ terminates the outer comment early Safe — inner delimiters are augmented with § before wrapping, restored on unwrap
Language has no block comment syntax Does nothing Fallback toggles line comments (//, etc.) per line (configurable)
One hotkey, context-aware behavior Two separate commands for line vs. block comments Single hotkey where existing selection triggers block comment, no selection triggers line comment (configurable)
Supports languages like Razor No Yes — detects C# code blocks within @{ } Razor sections

The problem with native nested comments

VS Code's Toggle Block Comment (shift+alt+a) breaks when your selection already contains a comment. The internal closing block comment token prematuely closes the desired comment block.

Nested Comment Video

Selection includes an whole line including /* cached */

const x = /* cached */ getValue();
// VS Code result — broken, inner */ ends the outer comment
/* const x = /* cached */ getValue(); */

// Better Block Comments result — inner delimiters safely augmented
// preventing early comment closure

/* const x = /§ cached §/ getValue(); */

// Toggle off comment — original fully restored:
const x = /* cached */ getValue();

The benefits of enabling Universal Comment option

One commenting hotkey always gives you what is logical based on context of selection/position in line.

Universal Comment Video

Cursor anywhere in line (no selection) → Line comment added at start of line

// Before
let data = [1,2,3,4];
// After
// let data = [1,2,3,4];

Cursor at end of line (no selection, universalComment.inlineEnd enabled) → inline line comment at end of line (note cursor represented by |)

// Before
let data = [1,2,3,4]; |
// After
let data = [1,2,3,4]; // |

Selection of number[] → Inline block comment

//Before
let data number[] = [1,2,3,4];
// Becomes
let data /* number[] */ = [1,2,3,4];

Usage

Action Shortcut
Toggle block comment cmd+alt+/ (Mac) / ctrl+alt+/ (Win/Linux)

It would be rude to overwrite the default VS Code keybinding for line comments (cmd+/ / ctrl+/), but if this extension and Universal Comment option aligns with your workflow, feel free.

keybindings.json

{
  "key": "cmd+/",
  "command": "editor.action.blockComment",
  "when": "editorTextFocus"
}

Settings

Setting Default Description
betterBlockComments.universalComment.enabled true Enabled: no selection → line comment at beginning of line (indent aware). Disabled: no selection → inline block comment /* */.
betterBlockComments.universalComment.inlineEnd true Cursor at line end → // appended inline instead of beginning of line. Toggle removes it. No effect when Universal Comment is disabled.
betterBlockComments.lineCommentFallback true Enabled - Languages not supporting Block Comments fallback as Line Comments. Disabled - performs no action (VSCode Default).

Requirements

  • VS Code 1.85.0 or later

Notes

  • The § character is used internally as an augmentation marker for block comments (i.e. preventing early termination of nested comments). It was chosen for its rarity across all language comment syntaxes and is not configurable.
  • Broadly tested

Changelog

See CHANGELOG.md.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft