如何在Visual Studio代码中引用集成终端的当前文件

问题描述 投票:3回答:1

我想知道是否可以(使用内置变量)直接使用从集成终端在Visual Studio中打开的当前文件,例如:

>some_command $current_file   (Where $current_file would be a built-in variable that calls the current active file)

如果终端是CMD(DOS),而不是我现在要做的事情:

> more C:\The\Path\to\File\MyFile.txt

或者如果使用的终端是bash:

$ cat /The/Path/to/File/MyFile.txt
terminal reference visual-studio-code built-in
1个回答
3
投票

作为一种解决方法,您可以使用新功能将${file}等变量发送到具有此类键绑定的终端:

{
  "key": "ctrl+shift+t",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "'${file}'\u000D" }
}

然后,在终端类型some_command中按Ctrl-Shift-T,将附加当前文件名并运行命令。

\u000D是一个回归。

© www.soinside.com 2019 - 2024. All rights reserved.