简体   繁体   English

如何使用 vscode 终端打开文件?

[英]How to open file using vscode terminal?

I want to open a new tab and open a file using vscode terminal.我想打开一个新选项卡并使用vscode终端打开一个文件。

like open somefile.js command, so I can use ls and open file quickly.比如open somefile.js命令,所以我可以使用ls快速打开文件。

使用code -r <file>在最后一个活动代码窗口中打开文件

use使用

code -r <filename>

just remeber to install the code command to PATH .请记住将代码命令安装到PATH in VScode, open the command palette and type "code", you should see a Shell Command: Install code to PATH option.在 VScode 中,打开命令面板并键入“code”,您应该会看到一个 Shell 命令:将代码安装到 PATH 选项。

I really haven't actually seen any difference between using the command without the -r flag.我真的没有看到使用没有-r标志的命令之间的任何区别。

If you are already in VSCode terminal (not an external OS terminal), check out the latest VSCode 1.64 (Jan. 2022) Terminal shell integration<\/strong><\/a> :如果您已经在 VSCode 终端(不是外部 OS 终端)中,请查看最新的 VSCode 1.64(2022 年 1 月) 终端外壳集成<\/strong><\/a>:

The terminal now features experimental opt-in shell integration which allows VS Code to gain insights on what is going on within the terminal as it was previously a black box.该终端现在具有实验性的选择加入 shell 集成,它允许 VS Code 深入了解终端内发生的事情,因为它以前是一个黑盒子。

When enabled using " terminal.integrated.enableShellIntegration": true<\/code> , arguments to run a shell integration script will be injected into your terminal profile if possible.当使用 " terminal.integrated.enableShellIntegration": true<\/code>启用时,如果可能,运行 shell 集成脚本的参数将被注入到您的终端配置文件中。

The script itself mostly just injects invisible sequences into your prompt, providing us with information like where the prompt, command and command output is, what the current working directory (cwd) is for each command and the exit code of each command.脚本本身主要只是将不可见的序列注入到您的提示符中,为我们提供提示符、命令和命令输出的位置、每个命令的当前工作目录 (cwd) 以及每个命令的退出代码等信息。

<\/blockquote>

That means:这意味着:

Link support relative to the cwd相对于 cwd 的链接支持<\/h2>

Since we know the cwd<\/code><\/strong> for each line in the terminal buffer, we can support opening links in the terminal relative to the cwd at the location where it was activated<\/strong> .由于我们知道终端缓冲区中每一行的cwd<\/code><\/strong> ,我们可以支持在终端中打开相对于 cwd 被激活位置的链接<\/strong>。

Before, when a link was clicked, a quick pick would open with results from any folders containing a match for that name.以前,当单击链接时,将打开一个快速选择,其中包含与该名称匹配的任何文件夹中的结果。

Now, the exact file match will be opened.现在,将打开完全匹配的文件。

In a terminal with a cwd<\/code> of VSCode, package.json<\/code> is echoed.在具有 VSCode 的cwd<\/code>的终端中,会回显package.json<\/code> 。
Clicking on the file name will result in vscode\/package.json<\/code> opening.单击文件名将打开vscode\/package.json<\/code> 。

The directory is changed to be the template-string-converter<\/code> and then package.json<\/code> is echoed.将目录更改为template-string-converter<\/code> ,然后回显package.json<\/code> 。
Clicking on the file name will open template-string-converter\/package.json<\/code> .单击文件名将打开template-string-converter\/package.json<\/code> 。

<\/blockquote>"

https:\/\/github.com\/microsoft\/vscode-docs\/raw\/vnext\/release-notes\/images\/1_64\/relative-cwd-link.png --<\/a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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