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
VS Code provides two powerful commands to navigate in and across files with easy-to-use key bindings. Hold Ctrl and press Tab to view a list of all files open in an editor group. To open one of these files, use Tab again to pick the file you want to navigate to, then release Ctrl to open it.
Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.
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.
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"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With