What is the simpliest way to create custom shortcuts for methods I'm using everydays?
Like dd()
Log::info()
or console.log()
.
Let me explain exactly what behavior I want for my shortcut:
I came up with this solution, thanks to @Mark in comments, related to this thread : How can I insert a snippet on a new line with vscode?
Install Multi-command VSCode extension
Open the settings of the extension and click on Edit in settings.json
Implement your shortcut code (e.g console.log()
)
"multiCommand.commands": [
{
"command": "multiCommand.console.log",
"sequence": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "console.log(\"$CLIPBOARD: \", $$CLIPBOARD)\n$0"
}
},
]
},
Then in VSCode go to Preferences -> Keyboard Shortcuts, open keybindings.json
Add the path binding command
// (new version)
{
"key": "ctrl+1",
"command": "multiCommand.console.log"
}
// (old version)
{
"key": "ctrl+1",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.console.log" }
}