The Visual Studio Code command line interface (2023)

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.

The Visual Studio Code command line interface (1)

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.

The Visual Studio Code command line interface (2)

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:

The Visual Studio Code command line interface (3)

(Video) Using Command Line in VSCode

Monitoring:macOS users must first run a command (Shell Command: Install "code" command in PATH) to add the executable VS Code to theCAMINOenvironment 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 manuallyCaminoenvironment variable ($RUTAunder 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 buildcode savvy.

CLI Core Options

These are the optional arguments you can use when launching VS Code from the command lineCode:

StreitDescription
-HÖ--Helpuse print
-vÖ--ExecutionPrint the VS Code version (e.g. 1.22.2), GitHub commit ID and architecture (e.g. x64).
-norteÖ--new windowOpen a new VS Code session instead of restoring the previous session (default).
-RÖ- Reuse windowsForce open a file or folder in the last active window.
- GrammÖ--Becomeswhen 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 luckWait 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)

The Visual Studio Code command line interface (4)

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.

(Video) VSCode Command Line CLI Tips & Tricks

StreitDescription
archiveName 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- GrammDispute. Name of a file to open at the specified line and optional character position.
PastaName of a folder to open. You can specify multiple folders and a new oneMultiroot workspaceit is created

The Visual Studio Code command line interface (5)

Choose a profile

You can launch VS Code with a specific oneProfilethrough--ProfileCommand line interface option. You pass the name of the profile after the--Profileargument and open a folder or workspace with that profile. The following command line opens theweb exampleWeb 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.

StreitDescription
--install-extension <ext>Install an extension. Provide the full name of the extensionEditor.Extensionas an argument. Use--fortalezaArgument to avoid prompts.
--uninstall-extension <ext>Uninstall an extension. Provide the full name of the extensionEditor.Extensionals Argument.
--Disable extensionsDisable any installed extensions. The extensions are still visible in theDisabled personfrom the plugins view, but they are never activated.
--list extensionsList of installed extensions.
--show versionsView 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.Extensionals Argument.

The Visual Studio Code command line interface (6)

Advanced CLI options

There are several CLI options that help with error reproduction and advanced configuration.

StreitDescription
--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, -statusPrint process usage and diagnostic information.
-p, --performancestart with theDeveloper: Starting powercommand enabled.
--disable-gpuDisable GPU hardware acceleration.
- detailedPrint verbose output (implies- with a little bit of luck).
--prof-startRun the CPU Profiler at startup.
- Load recordsUpload 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.

(Video) Visual Studio Code - 3 - Command Line

We build functionalityCodeCLI 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:

The Visual Studio Code command line interface (7)

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

(Video) Python Environment Setup - Windows 10 - VSCode, Command Line Interface

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}.

The Visual Studio Code command line interface (8)

monitoring: if you use VS Codeinitiatedbuilds is the URL prefixvscode-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 binaryCodein your way VS Code Windows and Linux installations must have VS Code installed in their path. Try uninstalling and reinstalling VS Code. YesCodenot 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.

(Video) CS50P - Visual Studio Code for CS50

01.03.2023

Videos

1. VSCode Tutorial For Beginners - Getting Started With VSCode
(Tech With Tim)
2. Visual Studio Code Tips - Switch between Command Prompt vs Powershell in Visual Studio Code Terminal
(SFDC Learn & Share)
3. How to Open VS Code from your Terminal/Command Line (Fast)
(TechStacker)
4. Intro To The .NET CLI - How To Use It, Why We Need It, And More
(IAmTimCorey)
5. 25 VS Code Productivity Tips and Speed Hacks
(Fireship)
6. How to open Visual Studio Code Editor from command line
(T3SO Tutorials)
Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated: 11/04/2023

Views: 6319

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.