Reputation: 441
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.
Something like Ctrl+Enter would be "); then a new line
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" ?
Upvotes: 28
Views: 11213
Reputation: 1517
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": "```"
}
}
Upvotes: 1
Reputation: 181218
You can also use the simple command type
in a keybinding like:
{
"key": "ctrl+enter",
"command": "type",
"args": {
"text": "myText"
},
"when": "editorTextFocus"
},
Upvotes: 15
Reputation: 67581
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
{
"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.
Upvotes: 46
Reputation: 123864
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.
Upvotes: 1