I\'m trying to make a vscode snippet for python. Suppose I have a line of code like this:
my_var = call_some_function()
I\'d like to double
As @Alex's link suggests, I think you will need to use a macro extension to get this to work. I prefer multi-command because it has an interval delay available (which is absolutely necessary for some macros but not yours).
In your settings:
"multiCommand.commands": [
{
"command": "multiCommand.debug",
"sequence": [
"editor.action.clipboardCopyAction",
"editor.action.insertLineAfter",
{
"command": "editor.action.insertSnippet",
"args": {
"snippet": "LOGGER.debug(\"$CLIPBOARD: %s\", $CLIPBOARD)\n$0"
}
},
]
}
]
This will copy your selection first to the clipboard so it can be used later by the snippet. Then insert an empty line below and insert the snippet there (in case the line below already has some code on it).
Trigger this with a keybinding:
{
"key": "ctrl+alt+d",
"command": "extension.multiCommand.execute",
"args": { "command": "multiCommand.debug" }
},
It works for both your examples.
This isn't exactly what was asked for, but is close, using the $CLIPBOARD variable:
"log-clipboard": {
"prefix": "log-clipboard",
"body": [
"LOGGER.debug('$CLIPBOARD: %s', $CLIPBOARD)",
"$0"
],
"description": "Log an expression from the clipboard"
}
To use:
Pretty close.