What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
在 VS Code 编辑器中,将光标放在代码行内,按 Ctrl + /(macOS 为 ⌘ + /)即可切换行注释。选中多行后使用相同快捷键,可以一次注释或取消注释多行代码;需要包裹整段代码时,则使用块注释快捷键。
| 操作 | Windows | Linux | macOS |
|---|---|---|---|
| 切换行注释 | Ctrl + / |
Ctrl + / |
⌘ + / |
| 切换块注释 | Shift + Alt + A |
Ctrl + Shift + A |
Shift + Option + A |
| 强制添加行注释 | Ctrl + K,再按 Ctrl + C |
Ctrl + K,再按 Ctrl + C |
⌘ + K,再按 ⌘ + C |
| 强制取消行注释 | Ctrl + K,再按 Ctrl + U |
Ctrl + K,再按 Ctrl + U |
⌘ + K,再按 ⌘ + U |
以上是 VS Code 的默认键绑定,用户可以修改或删除它们。官方默认快捷键参考见 VS Code Default Keyboard Shortcuts。
一行或多行添加注释
将光标放在目标行的任意位置,不需要先选中整行:
- Windows/Linux:按
Ctrl + /。 - macOS:按
⌘ + /。
VS Code 会按照当前语言模式的配置,在该行前添加相应的注释符号。再次执行同一个“切换行注释”命令,通常会取消普通、统一状态选区中的行注释。
#1 Best Overall
- Brilliant Color Illumination- With 11 unique backlights, choose the perfect ambiance for any mood. Adjust light speed and brightness among 5 levels for a comfortable environment, day or night. The double injection ABS keycaps ensure clear backlight and precise typing. From late-night tasks to immersive gaming, our mechanical keyboard enhances every experience
- Support Macro Editing: The K671 Mechanical Gaming Keyboard can be macro editing, you can remap the keys function, set shortcuts, or combine multiple key functions in one key to get more efficient work and gaming. The LED Backlit Effects also can be adjusted by the software(note: the color can not be changed)
- Hot-swappable Linear Red Switch- Our K671 gaming keyboard features red switch, which requires less force to press down and the keys feel smoother and easier to use. It's best for rpgs and mmo, imo games. You will get 4 spare switches and two red keycaps to exchange the key switch when it does not work.
- Full keys Anti-ghosting- All keys can work simultaneously, easily complete any combining functions without conflicting keys. 12 multimedia key shortcuts allow you to quickly access to calculator/media/volume control/email
- Professional After-Sales Service- We provide every Redragon customer with 24-Month Warranty , Please feel free to contact us when you meet any problem. We will spare no effort to provide the best service to every customer
例如,JavaScript 代码:
console.log("Hello");
注释后通常变为:
// console.log("Hello");
一次注释多行时,先拖动选中这些代码,再按 Ctrl + / 或 ⌘ + /。这会为选区中的每一行分别添加注释标记,而不是只在整个选区两端插入一对块注释符号。
例如 Python:
name = "Alice"
age = 20
print(name, age)
批量注释后通常为:
# name = "Alice"
# age = 20
# print(name, age)
再次按行注释快捷键通常会恢复原状。若选区同时包含已注释和未注释的行,切换结果取决于 VS Code 对当前选区状态的判断;需要明确执行“只添加”或“只删除”时,请使用后文的强制命令。
行注释和块注释有什么区别
行注释
行注释会在一行或多行的每一行分别添加注释符号,是临时禁用代码、保留清晰版本控制差异时最常用的方法。其官方命令名称是 Toggle Line Comment,命令 ID 为 editor.action.commentLine。
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstall块注释
块注释会用开始和结束标记包住选中的内容。先选中代码,再使用:
Rank #2
- Tri-mode Connection Keyboard: AULA F75 Pro wireless mechanical keyboards work with Bluetooth 5.0, 2.4GHz wireless and USB wired connection, can connect up to five devices at the same time, and easily switch by shortcut keys or side button. F75 Pro computer keyboard is suitable for PC, laptops, tablets, mobile phones, PS, XBOX etc, to meet all the needs of users. In addition, the rechargeable keyboard is equipped with a 4000mAh large-capacity battery, which has long-lasting battery life
- Hot-swap Custom Keyboard: This custom mechanical keyboard with hot-swappable base supports 3-pin or 5-pin switches replacement. Even keyboard beginners can easily DIY there own keyboards without soldering issue. F75 Pro gaming keyboards equipped with pre-lubricated stabilizers and LEOBOG reaper switches, bring smooth typing feeling and pleasant creamy mechanical sound, provide fast response for exciting game
- Advanced Structure and PCB Single Key Slotting: This thocky heavy mechanical keyboard features a advanced structure, extended integrated silicone pad, and PCB single key slotting, better optimizes resilience and stability, making the hand feel softer and more elastic. Five layers of filling silencer fills the gap between the PCB, the positioning plate and the shaft,effectively counteracting the cavity noise sound of the shaft hitting the positioning plate, and providing a solid feel
- 16.8 Million RGB Backlit: F75 Pro light up led keyboard features 16.8 million RGB lighting color. With 16 pre-set lighting effects to add a great atmosphere to the game. And supports 10 cool music rhythm lighting effects with driver. Lighting brightness and speed can be adjusted by the knob or the FN + key combination. You can select the single color effect as wish. And you can turn off the backlight if you do not need it
- Professional Gaming Keyboard: No matter the outlook, the construction, or the function, F75 Pro mechanical keyboard is definitely a professional gaming keyboard. This 81-key 75% layout compact keyboard can save more desktop space while retaining the necessary arrow keys for gaming. Additionally, with the multi-function knob, you can easily control the backlight and Media. Keys macro programmable, you can customize the function of single key or key combination function through F75 driver to increase the probability of winning the game and improve the work efficiency. N key rollover, and supports WIN key lock to prevent accidental touches in intense games
- Windows:
Shift + Alt + A - Linux:
Ctrl + Shift + A - macOS:
Shift + Option + A
该命令名为 Toggle Block Comment,命令 ID 为 editor.action.blockComment。例如 JavaScript、Java、C、C++ 和 C# 通常会生成:
/*
console.log("Hello");
console.log("World");
*/
块注释并非所有语言都支持。Python 和 Shell 通常使用连续的 # 行;HTML 使用 <!-- ... -->;CSS 通常使用 /* ... */。已有块注释内部再嵌套同类块注释,也可能造成语法错误,因此处理嵌套代码时应优先使用行注释。
VS Code 通过当前语言配置中的 comments.lineComment 和 comments.blockComment 判断注释方式,详情见 Language Configuration Guide。
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →强制添加或取消行注释
普通快捷键是“切换”操作:代码的当前状态会影响结果。如果希望明确执行添加或删除,可以使用以下默认快捷键:
Rank #3
- The Keychron C2 (non-backlight version) is a 104 keys full size wired retro color keycaps mechanical keyboard made for Mac and Windows. Engineered to maximize your productivity with most popular full size layout with number pad.
- With a layout optimized for Mac, the C2 has all necessary multimedia and function keys (Num Lock works with Windows only), while compatible with Windows, and comes with a dedicated Siri or Cortana key. Extra keycaps for both Mac and Windows operating systems are included.
- Designed with reliability in mind, the C2 comes with USB Type-C wired connection with a braid cable, which ensures a constant power supply, and best to fit home and light gaming. Inclined bottom frame and 2 level adjustable feet (6˚ & 9˚) makes the C2 more comfortable to type.
- The pre-installed tactile Keychron switch providing unrivaled tactile responsiveness with up to 50 million keystroke durable lifespan.
- Outfitted the C2 Non-Backlight version with retro-inspired color scheme looks as good in the office as it does in the game room.
- Add Line Comment:Windows/Linux 按
Ctrl + K后按Ctrl + C;macOS 按⌘ + K后按⌘ + C。 - Remove Line Comment:Windows/Linux 按
Ctrl + K后按Ctrl + U;macOS 按⌘ + K后按⌘ + U。
对应的命令 ID 分别是 editor.action.addCommentLine 和 editor.action.removeCommentLine。这对混合选区尤其有用:需要“全部加注释”时使用 Add,需要“全部取消”时使用 Remove。
不同编程语言生成的注释符号
注释符号由语言模式和语言扩展决定,不是 VS Code 对所有文件统一插入同一种字符。
| 语言或文件类型 | 常见行注释 | 常见块注释 |
|---|---|---|
| JavaScript、TypeScript | // |
/* ... */ |
| Java、C、C++、C# | // |
/* ... */ |
| Python | # |
通常使用连续的 # 行 |
| HTML | <!-- ... --> |
<!-- ... --> |
| CSS | 通常使用块形式 | /* ... */ |
| SQL | -- |
部分数据库支持 /* ... */ |
| Shell | # |
通常没有统一的块注释语法 |
| JSON | 标准 JSON 不允许注释 | 取决于是否使用 JSONC 等格式 |
因此,如果 JavaScript 文件被识别为纯文本,VS Code 可能无法插入 //。文件扩展名、自定义扩展名和已安装的语言扩展都会影响识别结果。
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute不用快捷键:使用命令面板
快捷键失效或键盘布局不熟悉时,可以使用命令面板:
Rank #4
- 【Dreamy Rainbow Gaming Keyboard】K521 Gaming Keyboard Adopts a Different LED Backlight Design, Upgraded on the Traditional LED Backlight Effect, Making the Light More Penetrating, Giving You a More Dazzling Visual Effect, Making Your Gaming Process More Enjoyable
- 【One Touch Opens & Visual Feast】The K521 Red Dragon Keyboard has a One-Touch on/off Lighting Button for Added Convenience. It also has a Three-Position Adjustable Breathing Mode and a Four-Position Adjustable Brightness Lighting Mode
- 【Mechanical Feeling & Fast Tapping】The PC Keyboard Keys are Designed for Mechanical Feeling, Giving You a Better Feel During Use and the Ability to Trigger Keys Quickly, Allowing You to Win All Your Games
- 【19 Keys Anti-Ghosting Keyboard】Anti-Ghosting Ensures Every Button Can Be Triggered. This Allows You to Trigger Key Combinations In The Game Accurately, And Each Skill Can Be Accurately Released to Increase Your Winning Rate. Redragon K521 Will Be Your Perfect Partner
- 【12 Multimedia Combination Keys】The K521 Wired Gaming Keyboard is Equipped with 12 Multimedia Keys That Can Greatly Enhance Your Gaming/Office Efficiency and Make It More Convenient to Use
- 按
F1,或按Ctrl + Shift + P(macOS 为⌘ + Shift + P)。 - 输入
Toggle Line Comment,选择同名命令。 - 需要块注释时,搜索并选择
Toggle Block Comment。
也可以在编辑器中右键选中内容,查找注释相关命令。不过右键菜单的名称和位置可能因 VS Code 版本、界面语言及扩展而不同,所以命令面板是更稳定的替代入口。不要把 Fold All Block Comments 与注释命令混淆:前者只是折叠、隐藏已有的块注释,不会添加或删除注释。
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.快捷键没有反应怎么办
- 确认焦点在编辑器:先点击代码区域。终端、搜索框、侧边栏获得焦点时,注释快捷键可能由其他控件处理。
- 检查文件是否只读:只读文件、不可编辑区域或受保护的编辑器不会接受修改。
- 检查语言模式:查看右下角的语言名称。如果文件实际是 JavaScript 却显示为 Plain Text,点击该名称选择正确模式,也可以执行
Change Language Mode。默认快捷键是 Windows/Linux 的Ctrl + K后按M,macOS 的⌘ + K后按M。 - 用命令面板测试:如果命令面板中的 Toggle Line Comment 能正常执行,问题通常在快捷键映射、键盘布局或焦点,而不是注释功能本身。
- 检查快捷键冲突:打开 Keyboard Shortcuts,搜索
Toggle Line Comment,查看是否被其他绑定覆盖。 - 检查键盘布局:官方快捷键参考主要按标准美式键盘显示。德语、法语、中文输入法或其他布局中,
/、?、[等按键位置可能不同。 - 检查终端冲突:macOS 集成终端中的
⌘ + K可能用于清屏等终端操作。先点击编辑器,或改用命令面板。
VS Code 的键绑定包含编辑器焦点、非只读等 when 条件;条件不满足时,即使快捷键显示正确,也可能不会执行。可参考官方的 Keyboard shortcuts 文档。
查看和修改注释快捷键
打开 Keyboard Shortcuts 编辑器:
- Windows/Linux:按
Ctrl + K,再按Ctrl + S。 - macOS:按
⌘ + K,再按⌘ + S。 - 也可以打开菜单 File > Preferences > Keyboard Shortcuts。
在搜索框输入以下命令名称:
Toggle Line CommentToggle Block CommentAdd Line CommentRemove Line Comment
点击对应命令旁的铅笔图标,按下新的组合键并确认即可。也可以右键绑定选择删除,或恢复默认绑定。
在 keybindings.json 中按语言设置
需要精确控制绑定时,可以编辑 keybindings.json。例如只为 C# 文件设置块注释快捷键:
Best Value
- Tactile Quiet mechanical key switches with a satisfying tactile bump you feel - for precise feedback, reactive key reset, and less noise so your typing doesn't disturb those around you
- Low-profile keys, more comfort: A keyboard layout designed for effortless precision, with a full-size form factor and low-profile mechanical switches for better ergonomics
- Smart illumination: Backlit keys light up the moment your hands approach the cordless keyboard and automatically adjust to suit changing lighting conditions
- Faster workflow, more customization: Customize Fn keys, assign backlighting effects, enable Flow cross-computer, multi-device control, and more in the improved Logi Options+ (1)
- Multi-device, multi-OS: Pair MX Mechanical Bluetooth wireless keyboard with up to 3 devices on nearly any operating system via Bluetooth Low Energy or included Logi Bolt receiver(2)
{
"key": "shift+alt+a",
"command": "editor.action.blockComment",
"when": "editorTextFocus && editorLangId == csharp"
}
editorLangId == csharp 会限制该绑定只在 C# 语言模式中生效。自定义绑定时要检查 JSON 语法,以及 when 条件是否与实际编辑器状态匹配;任一处错误都可能让快捷键看起来没有反应。命令和扩展可调用的命令说明见 VS Code Commands。
行注释还是块注释:怎么选
- 优先行注释:临时禁用几行代码、语言没有统一块注释语法、希望每行保持独立,或希望版本控制差异更清楚时。
- 优先块注释:C 风格语言中需要包住连续代码或一整段文本,并且确认该语言支持块注释时。
注释不会删除源代码,只是让语言解析器按注释处理;注释文本仍可能被搜索工具、文档生成器或静态分析器读取。提交代码前还应确认注释中的敏感信息不会被保留在版本库中。
The Bottom Line
最常用的做法是:选中一行或多行代码,按 Windows/Linux 的 Ctrl + /,或 macOS 的 ⌘ + / 切换行注释;需要整段包裹时使用对应平台的块注释快捷键。快捷键失效时,优先检查编辑器焦点、语言模式和 Keyboard Shortcuts 设置。
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

