20

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)

instead of what I have to do now if terminal is CMD (DOS):

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

Or if the terminal used is bash:

$ cat /The/Path/to/File/MyFile.txt
Ger Cas
  • 2,188
  • 2
  • 18
  • 45

2 Answers2

25

You could, as a workaround, use the new abilty to send variables like ${file} to the terminal with such a keybinding (see vscode docs). In your keybindings.json file add:

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

Then, in the terminal type some_command and hit Ctrl-Shift-T and the current filename will be appended and the command run.

\u000D is a return.

Hinrich
  • 13,485
  • 7
  • 43
  • 66
Mark
  • 143,421
  • 24
  • 428
  • 436
8

Based on the above answer with activation only when the terminal is in focus:

{
  "key": "ctrl+shift+t",
  "command": "workbench.action.terminal.sendSequence",
  "args": { "text": "'${file}'\u000D" },
  "when": "terminalFocus"
}
nvd
  • 2,995
  • 28
  • 16