Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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" ?

like image 252
VladimirSD Avatar asked Sep 05 '25 16:09

VladimirSD


1 Answers

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.

like image 166
Alex Avatar answered Sep 08 '25 20:09

Alex