Removes single-line and multi-line comments from your code — for basically
any language — without touching strings, URLs, or actual code that happens
to contain //, #, <!--, etc.
What it handles
- Line comments:
//,#,--,;,'(VB), depending on language - Block comments:
/* ... */,<!-- ... -->,<# ... #>,=begin/=end,--[[ ]] - 30+ languages out of the box: JS/TS/JSX/TSX, Python, Java, C/C++/C#, Go, Rust, PHP, Ruby, HTML/XML, CSS/SCSS/LESS, Markdown, YAML, Shell, PowerShell, SQL, Lua, Dockerfile, Makefile, Vue, and more.
- Unrecognized file types fall back to
//+/* */(the most common style).
What it will NOT touch
- Anything inside string literals (
"...",'...',`...`), even if it contains//,#, or other comment-like text. - A leading shebang line (
#!/usr/bin/env node) is always preserved. - Actual code — only the comment text and comment-only lines are removed.
Installation (no publishing required)
-
Unzip the extension folder somewhere permanent, e.g.
~/comment-sweep. -
Open a terminal in that folder and run:
npm install -g @vscode/vsce vsce packageThis produces
comment-sweep-1.0.0.vsix. -
In VS Code: open the Extensions panel → click the
...menu (top right) → Install from VSIX... → select the.vsixfile you just built.(Alternatively, skip packaging entirely: copy the whole
comment-sweepfolder into your VS Code extensions directory —~/.vscode/extensions/on macOS/Linux,%USERPROFILE%\.vscode\extensions\on Windows — then restart VS Code.)
Usage
- Open any file in VS Code.
- Run Comment Sweep: Remove Comments from File from the Command
Palette (
Ctrl+Shift+P/Cmd+Shift+P), or right-click in the editor and pick it from the context menu. - To clean only part of a file: select the text first, then run Comment Sweep: Remove Comments from Selection the same way.
Undo (Ctrl+Z / Cmd+Z) works as normal if you want the comments back.
Keyboard shortcuts
| Command | Windows/Linux | macOS |
|---|---|---|
| Remove Comments from File | Ctrl+Alt+C |
Cmd+Alt+C |
| Remove Comments from Selection | Ctrl+Alt+Shift+C |
Cmd+Alt+Shift+C |
To change these: Command Palette → Preferences: Open Keyboard Shortcuts → search "Comment Sweep" → click the pencil icon next to a command.
Known limitations
- Regex literals in JS/TS that contain
//inside them (e.g./a\/\/b/) aren't specially detected — this is a rare edge case; check code with inline regex after running. - JSON files are left untouched (standard JSON has no comment syntax);
.jsoncfiles are supported. - Python/Ruby "block comments" via triple-quoted strings are treated as
strings (correctly) — only
#/=begin/=endstyle comments are removed.
License
MIT