简体   繁体   中英

How to open a file from the integrated terminal in Visual Studio Code?

Is there a way of opening a file from the terminal in Visual Studio Code that opens in the same<\/em> vscode instance that runs the terminal? Similar to c9<\/a> tool in Cloud9.

您可以使用 -r 或 --reuse-window 命令行选项。

code -r something.php

我不知道您使用的是什么操作系统,但在 MacOS 上,您只需在集成终端中说open filename.ext ,它就会在同一个 VSCode 实例中打开一个新选项卡,供您编辑。

I use code -r . to open the current directory in the main window.

just

code file_name

I tried it on Win10 and on Linux (Ubuntu)

如果在 MacOS 中command not found: code ,请使用它的完整路径。

/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]

in the version 1.31.0 that I have installed, on Windows 7, the only way I found to do this is to eg change the file associations in system so that .cproj and .cs files are opened by Visual Studio Code by default, and type "filename.cs" in Terminal to open file by that name in the same window... -r option is not working for the first call (opens a new window), but with each subsequent call that same window is correctly reused. ok can't get to open whole directories this way - it's a bit shoddy anyway. probably it would be more convenient to use an outside shell and work with "-r" option

Many things can be found in open --help

A work around that worked for me on MacOS is: open -a 'Visual Studio Code.app' compose-2.yml

您可以使用 CLI 中的code命令打开文件,但如果您希望它在现有窗口中打开,请使用其他答案中提到的code -r <file> (这在 Ubuntu Linux对我有用),或者,如果-r不起作用(在 WSL 下?),请确保在settings.json或 VS Code 设置 UI 中window.openFilesInNewWindow处于offdefault状态,然后使用code <file>

code -r .txt

This works the best for me if I need to open a file from the terminal into the current VS Code Window.

VSCode 1.64 (Jan. 2022) comes with a new command:

<\/h2>

Previously, link navigation in the terminal required the use of a mouse.

  • <\/li>
  • <\/li>
  • <\/li><\/ul><\/blockquote>

    Check if the last command Terminal: Open Last File Link...<\/code> would help in your case.

    "

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