[英]How to highlight current line number in Visual Studio Code / VS Code
[英]How to run a shell script with the current line or block of code as argument in Visual Studio Code?
有沒有辦法實現類似於“Python:在 Python 終端中運行選擇/行”但當前代碼行或代碼塊作為參數傳遞給可配置的 shell 腳本的方法?
您可以使用擴展命令變量將所選文本傳遞給任務命令
{
"version": "2.0.0",
"tasks": [
{
"label": "echo selected text",
"type": "shell",
"command": "echo",
"args": [ "${input:selectedText}" ],
"problemMatcher": []
}
],
"inputs": [
{
"id": "selectedText",
"type": "command",
"command": "extension.commandvariable.transform",
"args": {
"text": "${selectedText}"
}
}
]
}
如果需要,您可以將一些 arguments 添加到${selectedText}
變量。
您可以在向終端發送命令的鍵綁定中直接使用變量${selectedText}
:
{
"key": "alt+t", // whatever you want for a keybinding
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "echo '${selectedText}'\u000D"
}
}
是一個
return
,所以命令立即運行。
或者首先嘗試將此鍵綁定到當前行的 select 並將其發送到終端:
{
"key": "alt+t",
"command": "runCommands",
"args": {
"commands": [
"cursorHome",
"cursorEndSelect",
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "echo '${selectedText}'\u000D"
}
}
]
}
}
或者在任務中:
"tasks": [
{
"label": "echoMe",
"type": "shell",
"command": "echo ${selectedText}",
"args": [
]
}
]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.