Visual Studio Code has a powerful built-in command-line interface that you can use to control how the editor is launched. You can open files, install extensions, change the display language, and generate diagnostics using command-line switches.
If you're looking for command line tools in VS Code, check out theIntegrated end device.
command line help
For an overview of the VS Code CLI, open a terminal or command prompt and typecode - help
. You'll see the version, usage example, and list of command line options.
Starting from the command line
You can launch VS Code from the command line to quickly open a file, folder, or project. VS Code normally opens in the context of a folder. To do this, in an open terminal or command prompt, navigate to your project folder and typeCode
:
Monitoring:macOS users must first run a command (Shell Command: Install "code" command in PATH) to add the executable VS Code to theCAMINO
environment variable. read thismacOS setup guidefor help
Windows and Linux installations must add the location of the VS Code binaries to the system path. If not, you can add the location manuallyCamino
environment variable ($RUTA
under Linux). For example, Windows has VS Code installedAppData\Local\Programas\Microsoft VS Code\bin
. For platform-specific setup instructions, seeconfigure.
Insider:If you use VS CodeinitiatedPreview with which to start your Insiders build
code savvy
.
CLI Core Options
These are the optional arguments you can use when launching VS Code from the command lineCode
:
Streit | Description |
---|---|
-H Ö--Help | use print |
-v Ö--Execution | Print the VS Code version (e.g. 1.22.2), GitHub commit ID and architecture (e.g. x64). |
-norte Ö--new window | Open a new VS Code session instead of restoring the previous session (default). |
-R Ö- Reuse windows | Force open a file or folder in the last active window. |
- Gramm Ö--Becomes | when used withfile:line{:characters}, opens a file at a specific line and optional character position. This argument is provided because some operating systems allow it: in a filename. |
-D Ö--diff <archivo1> <archivo2> | Open a file diff editor. It requires two file paths as arguments. |
-Metro Ö--merge <path1> <path2> <base> <result> | Perform a three-way merge by specifying paths to two changed versions of a file, the common source of both changed versions, and the output file to store the merge results. |
-C Ö- with a little bit of luck | Wait for the files to close before returning. |
--locale <local> | put thatLanguage(regional settings) for the VS Code session. (For example,In U.S Özh-TW ) |
Open files and folders
Sometimes you want to open or create a file. If the specified file doesn't exist, VS Code creates it along with the new intermediate folders:
code index.html style.css-Dokumentation\Reame.md
You can use absolute or relative paths for files and folders. Relative paths are relative to the current command prompt directory it is running inCode
.
If you specify more than one file on the command line, VS Code will only open a single instance.
If you specify more than one folder on the command line, VS Code creates oneMultiroot workspaceincluding each folder.
Streit | Description |
---|---|
archive | Name of a file to open. If the file does not exist, it will be created and marked as edited. You can specify multiple files by separating each file name with a space. |
file:line[:char] | used with the- Gramm Dispute. Name of a file to open at the specified line and optional character position. |
Pasta | Name of a folder to open. You can specify multiple folders and a new oneMultiroot workspaceit is created |
Choose a profile
You can launch VS Code with a specific oneProfilethrough--Profile
Command line interface option. You pass the name of the profile after the--Profile
argument and open a folder or workspace with that profile. The following command line opens theweb example
Web Development profile folder:
code ~/projects/web-sample --profile "Web Development"
If the specified profile does not exist, a new empty profile will be created with the specified name.
work with extensions
Can install and manage VS Codeextensionsfrom the command line.
Streit | Description |
---|---|
--install-extension <ext> | Install an extension. Provide the full name of the extensionEditor.Extension as an argument. Use--fortaleza Argument to avoid prompts. |
--uninstall-extension <ext> | Uninstall an extension. Provide the full name of the extensionEditor.Extension als Argument. |
--Disable extensions | Disable any installed extensions. The extensions are still visible in theDisabled personfrom the plugins view, but they are never activated. |
--list extensions | List of installed extensions. |
--show versions | View installed extension versions when used--list extensions |
--enable-proposed-api <ext> | Enables the proposed API functions for an extension. Provide the full name of the extensionEditor.Extension als Argument. |
Advanced CLI options
There are several CLI options that help with error reproduction and advanced configuration.
Streit | Description |
---|---|
--extensions-dir <dir> | Set the root path for the extensions. Has no influence onPortable mode. |
--user-data-dir <directory> | Specifies the directory where user data is stored. This is useful when running as root. Has no influence onPortable mode. |
-s, -status | Print process usage and diagnostic information. |
-p, --performance | start with theDeveloper: Starting powercommand enabled. |
--disable-gpu | Disable GPU hardware acceleration. |
- detailed | Print verbose output (implies- with a little bit of luck ). |
--prof-start | Run the CPU Profiler at startup. |
- Load records | Upload the latest session logs to a secure endpoint. |
Multirraíz | |
--add <directory> | Add folder to last active window for a multiroot workspace. |
Create a remote tunnel
VS Code integrates with othersremote environmentsto be even more powerful and flexible. Our goal is to provide a cohesive experience that allows you to manage local and remote computers through a unified CLI.
Visual Studio-CodeRemote - TunnelThe extension allows you to connect to a remote machine like a desktop or VM through a secure tunnel. Tunneling transfers data securely from one network to another. You can securely connect to this computer from anywhere without requiring SSH.
We build functionalityCode
CLI that starts tunnels to remote computers. You can run:
Code-Tunnel
to create a tunnel on your remote machine. You can connect to this computer using a VS Code desktop or web client.
You can check the other wrapper commands by running themCode Tunnel - Help
:
Since you may need to run the CLI on a remote computer where VS Code Desktop cannot be installed, the CLI is also available for unattended installationVS Code Download Page.
For more information on remote tunneling, see theRemote-Tunneldokumentation.
Open VS Code with URL
You can also open projects and files using the platform's URL handling mechanism. Use the following URL formats for:
Open a project
vscode://file/{full path to project}/vscode://file/c:/myproject/
open a folder
vscode://file/{full path to file}vscode://file/c:/myProject/package.json
Open a row and column file
vscode://file/{full path to file}:line:columnvscode://file/c:/myProject/package.json:5:10
You can use the URL in applications like browsers or file explorers that can parse and redirect the URL. For example, on Windows, you can pass avscode://
URL directly to Windows Explorer or command line asstart vscode://{full path to file}
.
monitoring: if you use VS Codeinitiatedbuilds is the URL prefix
vscode-insider://
.
Next Steps
Read on to learn more about:
- Integrated end device- Run command line tools from VS Code.
- base edition- Learn the basics of the VS Code editor.
- Navigationscode- With VS Code you can quickly understand and go through your source code.
frequently asked questions
'code' is not recognized as an internal or external command
Your operating system cannot find the VS Code binaryCode
in your way VS Code Windows and Linux installations must have VS Code installed in their path. Try uninstalling and reinstalling VS Code. YesCode
not found yet, see the platform-specific configuration topics forWindowmiLinux.
On macOS, you need theShell Command: Install "code" command in PATHcommand (available fromcommand palette ⇧⌘S(Windows, LinuxCtrl+Shift+P)). Watch themMacOSspecific configuration topic for more details.
How do I get access to a command line (terminal) from VS Code?
The VS Code has aIntegrated end devicewhere you can run command line tools in VS Code.
Can I specify the location of the VS Code configuration to have a portable version?
Not directly from the command line, but VS Code has onePortable mode, which allows you to keep settings and data in the same place as the installation, for example on a USB drive.
01.03.2023