没有内置的方法可以做到这一点。您将需要延期。看https://stackoverflow.com/a/59448448/836330 https://stackoverflow.com/a/59448448/836330对于之前使用不同扩展名的答案。这是使用我同时制作的扩展的更好答案,。但存在如下限制。
使这个键绑定(在你的keybindings.json
):
{
"key": "alt+/", // unfortunately, this cannot be ctrl+/
"command": "findInCurrentFile",
"args": {
{
"key": "alt+r",
"command": "findInCurrentFile",
"args": {
"preCommands": [
"cursorEnd",
"cursorHomeSelect",
"cursorHomeSelect"
],
"replace": "${LINE_COMMENT}${TM_CURRENT_LINE}",
"restrictFind": "line" // works on multiple lines, see the demo
},
"when": "editorLangId == python" // if you want to limit it to a language
},
}
You can use whatever keybinding you want, but not Ctrl+/ because then toggle off will not work.
Ctrl+/ will work to toggle off comments if you do not use it in the keybinding above to add comments.
注意:为了使其正常工作,您需要禁用以下设置(我已显示对特定语言 python 禁用了该设置):
"[python]": {
"editor.comments.insertSpace": false
}
这会进入你的settings.json
.