如何在 Visual Studio Code 中从集成终端引用当前文件 [英] How to refer to current file from Integrated Terminal in Visual Studio Code
问题描述
我想知道是否可以(使用内置变量)直接处理从集成终端在 Visual Studio 中打开的当前文件,例如:
I want to know if it is possible (with a built in variable) to work directly with current file opened in Visual Studio from intergrated terminal, for example:
>some_command $current_file (Where $current_file would be a built-in variable that calls the current active file)
如果终端是 CMD (DOS),而不是我现在必须做的:
instead of what I have to do now if terminal is CMD (DOS):
> more C:\The\Path\to\File\MyFile.txt
或者如果使用的终端是 bash:
Or if the terminal used is bash:
$ cat /The/Path/to/File/MyFile.txt
推荐答案
作为一种变通方法,您可以使用新的 abilty 将诸如 ${file}
之类的变量发送到具有此类键绑定的终端.在您的 keybindings.json 文件中添加:
You could, as a workaround, use the new abilty to send variables like ${file}
to the terminal with such a keybinding. In your keybindings.json file add:
{
"key": "ctrl+shift+t",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "'${file}'\u000D" }
}
然后,在终端中输入 some_command
并点击 Ctrl-Shift-T 和当前文件名将附加并运行命令.
Then, in the terminal type some_command
and hit Ctrl-Shift-T and the current filename will be appended and the command run.
\u000D
是一个回报.
这篇关于如何在 Visual Studio Code 中从集成终端引用当前文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!