[英]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.