I need to execute multiple commands in keybindings.json in vscode to be able to log variable name, filename and the variable value.
ex in dart
double x = 2.2; print("main.dart -> x $x"); the default behavior is to insertSnippet in the same line but i need to go to add new line below my variable then insert my custom snippet.
In addition i tried macros and multi-command. Unforgettably i couldn't reach the VSCode environment variables like TM_FILENAME_BASE and CLIPBOARD. They just print as a plane text something like
double x = 2.2; print("$TM_FILENAME_BASE x $x") Not able to resolve the env var to it's value.
this is from mutli-command extension settings.json
"multiCommand.commands": [ { "command": "myCommand", "sequence": [ "cursorDown", "insertSnippet", { "command": "type", "args": { "text": "print(\" log-> ${TM_FILENAME_BASE} -> ${TM_SELECTED_TEXT} -> ${${TM_SELECTED_TEXT}} \" );" } } ] }, ], and this one from keybindings.json
{ "key": "alt+p", "command": "editor.action.insertSnippet", "when": "editorTextFocus && resourceExtname == .dart", "args": { "snippet": "print(\" log-> ${TM_FILENAME_BASE} -> ${TM_SELECTED_TEXT} -> ${${TM_SELECTED_TEXT}} \" );" } } SOLUTION This is a tweaked solution for my issue inspired by Mark
from settings.json
"multiCommand.commands": [ { "command": "multiCommand.printVariable", "sequence": [ "editor.action.clipboardCopyAction", // Copy the selected to the clipboard "editor.action.insertLineAfter", { "command": "editor.action.insertSnippet", "args": { "snippet": "print(\"${TM_FILENAME_BASE} -> ${CLIPBOARD} -> ${${CLIPBOARD}}\");" // then add it here } }, ] }, ], from keybindings.json
{ "key": "alt+p", "command": "extension.multiCommand.execute", "args": { "command": "multiCommand.printVariable" }, "when": "editorTextFocus && resourceExtname == .dart" } 