是否有方法从 VisualStudio 代码中的终端打开在运行终端的 same vscode 实例中打开的文件?类似于 Cloud9中的 C9工具。
我知道 密码工具,但是当您从集成终端运行 code something.php时,它会打开一个 新的 vscode 实例,这不是我想要的..。
code something.php
我不知道您使用的是什么操作系统,但在 MacOS 上,您只需在集成终端中输入 open filename.ext,它就会在同一个 VSCode 实例中打开一个新的选项卡,以便您进行编辑。
open filename.ext
您可以使用-r 或—— use-window 命令行选项。
code -r something.php
我用 code -r .打开主窗口的工作目录。
code -r .
在我安装的1.31.0版本中,在 Windows 7上,我发现唯一的方法是修改系统中的文件关联,以便。Cproj 和。Cs 文件默认情况下由 Visual Studio Code 打开,在 Terminal 中键入“ filename.cs”在同一个窗口中以该名称打开文件...-r 选项对于第一次调用不起作用(打开一个新窗口) ,但是随后的每次调用都能正确地重用同一个窗口。OK 不能用这种方式打开整个目录-反正有点劣质。也许使用外部 shell 并使用“-r”选项会更方便
只是
code file_name
我在 Win10和 Linux (Ubuntu)上都试过
如果您在 macOS 中使用 command not found: code,请使用它的完整路径。
command not found: code
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]
在 open --help中可以找到很多东西
open --help
我在 MacOS 上的一个解决办法是: open -a 'Visual Studio Code.app' something.php
open -a 'Visual Studio Code.app' something.php
您可以使用 CLI 中的 code命令打开一个文件,但是如果您希望在现有窗口中打开它,可以使用其他答案中提到的 code -r <file>(我在 Ubuntu Linux 上使用的是 does) ,或者,如果 -r不能工作(在 WSL 下?),确保 window.openFilesInNewWindow是 settings.json或 VS 代码设置 UI 中的 off或 default,然后使用 code <file>。
code
code -r <file>
-r
window.openFilesInNewWindow
settings.json
off
default
code <file>
VSCode 1.64(2022年1月)附带了一个新命令:
键盘导航链接 以前,终端中的链接导航需要使用鼠标。 Now, links can be opened using only the keyboard via the following commands: Terminal: Open Detected Link... to view all links (web, file, word) Https://github.com/microsoft/vscode Terminal: Open Last File Link... ex: /Users/user/repo/file.txt
以前,终端中的链接导航需要使用鼠标。
Now, links can be opened using only the keyboard via the following commands:
Terminal: Open Detected Link...
Terminal: Open Last File Link...
/Users/user/repo/file.txt
Check if the last command Terminal: Open Last File Link... would help in your case.
See also "壳积分法"
打开 VisualStudio 代码
Press CMD + SHIFT + P (this opens "Command Palette")
类型 shell command
shell command
选择“在路径中安装代码命令”
从终端导航到任何项目,然后键入 code .
code .
如果它不工作,首先选择“卸载代码命令从路径”,然后重新安装它。