Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode: Assign key command to a snippet?

In previous editors I've users, notably SublimeText and Atom, I was able to create a simple command to add a character like   when I type option-space.

In Atom, for example, I created the command in init.coffee:

atom.commands.add 'atom-text-editor',
 'editor:insert-nbsp': (event) ->
   editor = @getModel()
   editor.insertText(' ')

and then the easy part, a keybinding to call the custom command:

  'alt-enter': 'editor:insert-br'

In vscode, I know how to do the latter (create a keybinding) but how to create the command.

I realize I can create a snippet, which I have made several of, but I want to essentially trigger the   snippet with a keybinding.

How can I do this?

like image 584
Steve Avatar asked Dec 14 '22 03:12

Steve


1 Answers

It's actually much easier in VSCode since 1.9:

{
 "key": "alt+space",
 "command": "type",
 "args": {
   "text": " "
 },
 "when": "editorTextFocus"
},
like image 151
Steve Avatar answered Mar 16 '23 06:03

Steve