简体   繁体   English

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

[英]Can VS Code type text with keyboard shortcuts?

I know you can enter a block of text with code snippets but can you configure keyboard shortcuts to enter some text?我知道您可以使用代码片段输入一段文本,但是您可以配置键盘快捷键来输入一些文本吗? With "editor.action" you can move the cursor but I can't find if it's possible if you can get it to type some text.使用“editor.action”,您可以移动光标,但我找不到是否可以让它输入一些文本。

Something like Ctrl + Enter would be "); then a new lineCtrl + Enter这样的东西是 "); 然后换行

Maybe create a code snippet and then invoke it with a keyboard shortcut?也许创建一个代码片段,然后使用键盘快捷键调用它?

Is there a way to find what all the options are for "editor.action"?有没有办法找到“editor.action”的所有选项?

You can insert a User Snippet on keypress:您可以在按键上插入 用户代码段

Open keybindings.json (Preferences: Open Keyboard Shortcuts (JSON)), which defines all your keybindings, and add a keybinding passing "snippet" as an extra argument打开 keybindings.json (Preferences: Open Keyboard Shortcuts (JSON)),它定义了你所有的键绑定,并添加一个键绑定传递“snippet”作为额外的参数

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

Furthermore, you can specify languages in which it should work:此外,您可以指定它应该使用的语言

"when": "editorTextFocus && editorLangId == 'javascript'"

See here for more information.请参阅此处了解更多信息。

You can also use the simple command type in a keybinding like:您还可以在键绑定中使用简单的命令type ,例如:

 {
    "key": "ctrl+enter",
    "command": "type",
    "args": { 
      "text": "myText" 
    },
    "when": "editorTextFocus"
 },

The list of available keyboard actions is available from here .可用键盘操作的列表可从此处获得 You can consider to write an extension for VS Code if you have something specific in mind, with that you can create actions with keybindings that modify the editor contents.如果您有特定的想法,可以考虑为 VS Code 编写扩展,这样您就可以创建带有修改编辑器内容的键绑定的操作。

I just leave it here.我只是把它留在这里。 An alias for triple backticks for people with non-English keyboards:使用非英语键盘的人的三重反引号的别名:

    {
        "key": "ctrl+shift+1",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && !editorReadonly && editorLangId == 'markdown'",
        "args":{
            "snippet": "```"
        }
    }

Ctrl+Shift+P > Preferences: Open Keyboard Shortcuts (JSON)

Add the following JSON object to the array that opens: 将以下JSON对象添加到打开的数组中:

[
    {
        "key": "ctrl+enter",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus",
        "args": {
            "snippet": "\");\n$0"
        }
    }
]

More examples: https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-rules 更多示例: https : //code.visualstudio.com/docs/getstarted/keybindings#_keyboard-rules

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM