![如何使用键绑定在 VS Code 中按段落选择文本?](https://linux22.com/image/1689330/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E9%94%AE%E7%BB%91%E5%AE%9A%E5%9C%A8%20VS%20Code%20%E4%B8%AD%E6%8C%89%E6%AE%B5%E8%90%BD%E9%80%89%E6%8B%A9%E6%96%87%E6%9C%AC%EF%BC%9F.png)
我找到了如何自定义键绑定以跳转到最近的空行这里。
但我想知道我是否可以以同样的方式设置一个键绑定来选择段落或下一个空行。我希望它从光标所在的位置选择到下一个(使用++ Ctrl)或上一个空行(使用++ )ShiftDownArrowCtrlShiftUpArrow
更一般地说,我不知道如何在文件中搜索现有的、有效的“命令”来配置我自己的键绑定keybindings.json
。
答案1
您需要cursorMove
使用适当的参数绑定命令。要绑定:
- 使用Ctrl++从光标选择到下一个空白行ShiftDown
- Ctrl使用++从光标选择到上Shift一个空白行Up
您可以使用:
{
"key": "ctrl+shift+down",
"command": "cursorMove",
"when": "editorTextFocus",
"args": {
"to": "nextBlankLine",
"select": true
}
},
{
"key": "ctrl+shift+up",
"command": "cursorMove",
"when": "editorTextFocus",
"args": {
"to": "prevBlankLine",
"select": true
}
}
keybindings.json
通过执行命令面板 ( ++ Shift) ->将其添加至CtrlP偏好设置:打开键盘快捷键 (JSON)命令。
作为奖励,要绑定一个快捷方式来选择整个段落,正如问题标题所暗示的那样,runCommands
可以使用宏:
{
"key": "ctrl+shift+a",
"command": "runCommands",
"when": "editorTextFocus",
"args": {
"commands": [
{
"command": "cursorMove",
"args": {
"to": "prevBlankLine"
}
},
{
"command": "cursorMove",
"args": {
"to": "nextBlankLine",
"select": true
}
}
]
}
}
查看光标移动文档以获取更多信息。