Search code examples
key-bindingsvisual-studio-code

Inserting code with a keybinding in Visual Studio Code


How can I insert code in Visual Studio Code for MacOS with key bindings? For example in Sublime I can insert a console.log like this:

{ 
  "keys": ["super+shift+l"],
  "command": "insert_snippet",
  "args": {
    "contents": "console.log('test:' + varname);${0}"
  }
},

If I press Cmd+Shift+L I get console.log('test:' + varname);


Solution

  • You can specify what the insertSnippet command should insert like this:

    {
        "key": "cmd+shift+l",
        "command": "editor.action.insertSnippet",
        "args": {
           "snippet": "console.log('test:' + varname);${0}"
        }
    }