【发布时间】:2020-06-10 17:20:58
【问题描述】:
我需要在 vscode 中的 keybindings.json 中执行多个命令才能记录变量名、文件名和变量值。
飞镖中的前任
double x = 2.2;
print("main.dart -> x $x");
默认行为是在同一行中插入片段,但我需要在我的变量下方添加新行,然后插入我的自定义 sn-p。
此外,我尝试了宏和多命令。令人难忘的是,我无法访问 TM_FILENAME_BASE 和 CLIPBOARD 等 VSCode 环境变量。它们只是打印为平面文本,例如
double x = 2.2;
print("$TM_FILENAME_BASE x $x")
无法将环境变量解析为它的值。
这是来自 mutli-command 扩展 settings.json
"multiCommand.commands": [
{
"command": "myCommand",
"sequence": [
"cursorDown",
"insertSnippet",
{
"command": "type",
"args": {
"text": "print(\" log-> ${TM_FILENAME_BASE} ->
${TM_SELECTED_TEXT} -> ${${TM_SELECTED_TEXT}} \" );"
}
}
]
},
],
这个来自 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}} \" );"
}
}
解决方案 这是受 Mark 启发的针对我的问题的调整解决方案
来自 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
}
},
]
},
],
来自 keybindings.json
{
"key": "alt+p",
"command": "extension.multiCommand.execute",
"args": {
"command": "multiCommand.printVariable"
},
"when": "editorTextFocus && resourceExtname == .dart"
}
【问题讨论】:
-
请出示您的 sn-p 和/或宏。因此,我们可以帮助修复您编写的内容,而不是自己编写。