VS Code 可以使用键盘快捷键输入文本吗?

Vla*_*rSD 13 visual-studio-code

我知道您可以输入带有代码片段的文本块,但是您可以配置键盘快捷键来输入一些文本吗?使用“editor.action”,您可以移动光标,但我无法确定是否可以让它输入一些文本。

Ctrl+Enter这样的东西是 "); 然后换行

也许创建一个代码片段,然后使用键盘快捷键调用它?

有没有办法找到“editor.action”的所有选项?

Ale*_*lex 21

您可以在按键上插入用户代码段

打开 keybindings.json (Preferences: Open Keyboard Shortcuts (JSON)),它定义了你所有的键绑定,并添加一个键绑定传递“snippet”作为额外的参数

{
    "key": "ctrl+enter",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus",
    "args": {
        "snippet": "\");\n$0"
    }
}
Run Code Online (Sandbox Code Playgroud)

此外,您可以指定它应该使用的语言

"when": "editorTextFocus && editorLangId == 'javascript'"
Run Code Online (Sandbox Code Playgroud)

请参阅此处了解更多信息。

  • 我成功使用了“Cmd+Shift+P > 首选项:打开键盘快捷键 (JSON)”并且 (5认同)

Mar*_*ark 6

您还可以type在键绑定中使用简单命令,例如:

 {
    "key": "ctrl+enter",
    "command": "type",
    "args": { 
      "text": "myText" 
    },
    "when": "editorTextFocus"
 },
Run Code Online (Sandbox Code Playgroud)


Ben*_*ero 1

可用键盘操作的列表可从此处获得。如果您有特定的想法,您可以考虑为 VS Code 编写一个扩展,这样您就可以使用修改编辑器内容的键绑定创建操作。