【发布时间】:2022-07-15 14:33:45
【问题描述】:
我刚从 PhpStorm 转到 VS Code,还有一些我不习惯的东西。
当我用 Ctrl + / 注释一行时,光标停留在该行中。我希望我的光标移动到下一行(就像在 PhpStorm 中一样)。
关于如何在评论一行后添加此“转到下一行”操作有什么想法吗?
【问题讨论】:
-
我认为你必须使用宏扩展来运行两个命令。
我刚从 PhpStorm 转到 VS Code,还有一些我不习惯的东西。
当我用 Ctrl + / 注释一行时,光标停留在该行中。我希望我的光标移动到下一行(就像在 PhpStorm 中一样)。
关于如何在评论一行后添加此“转到下一行”操作有什么想法吗?
【问题讨论】:
使用此键绑定(在您的 keybindings.json 中)和宏扩展 multi-command:
{
"key": "ctrl+/", // whatever you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.commentLine", // for line comments
"editor.action.insertLineAfter"
// "cursorDown"
]
},
"when": "editorTextFocus"
},
{
"key": "shift+alt+A", // whatever keybinding you want
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.blockComment", // for block comments too
"editor.action.insertLineAfter"
// "cursorDown"
]
},
"when": "editorTextFocus"
}
唯一的缺点是当你取消注释时它也会插入一行。如果您只想插入一行,而不是插入一行(可能有预先存在的文本,请改用命令"cursorDown"。
【讨论】:
ctrl+/,计算机会发出错误声音,如果我将其更改为cmd+/,那么什么都不会发生,包括不再注释掉该行
虽然@Mark 的solution 很有帮助,但我发现它对于新手来说是不完整的——我必须进行额外的研究才能实现该功能。所以这里有详细的步骤。
View - Extensions
Multi-command 扩展。转到File > Preferences > Keyboard Shortcuts。 (Code > Preferences > Keyboard Shortcuts 在 macOS 上)
Open Keyboard Shortcuts (JSON) 如下图所示。
keybindings.json 将被打开。[
{
"key": "ctrl+/",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.commentLine",
"cursorDown"
]
},
"when": "editorTextFocus"
}
]
不要否认自己对两种解决方案都进行评价。
【讨论】: