简体   繁体   中英

How to refer to current file from Integrated Terminal in Visual Studio Code

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

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" }
}

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

\ is a return.

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"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM