Command line

code

code: open files or directories in Visual Studio Code (VS Code) from the command line.

The code command allows you to quickly open a file or a directory in VS Code without manually launching the application. Using the code command can help streamline your workflow by enabling you to navigate your project's files and directories in the terminal and open them directly in VS Code when needed. This eliminates the need to switch between the terminal and the file explorer to locate and open files.

To use the code command, you first need to have VS Code installed on your system. Once installed, you can open VS Code from the terminal by simply typing code followed by the file or directory you want to open.

VS Code as the default editor for Git

To set VS Code as the default editor for Git, you can use the following command:

Run in Terminal:
git config --global core.editor "code --wait"

This command sets the default editor for Git to VS Code. The --wait flag tells Git to wait for VS Code to close before continuing execution in the terminal.

After setting VS Code as the default editor, when you run a Git command that requires you to enter a message (such as git commit without the -m flag), Git will open VS Code for you to enter the message. Once you save and close the file in VS Code, Git will continue with the operation.

Examples

Open the current directory in VS Code:

code .

Open a specific file in VS Code:

code README.md

Open a specific directory in VS Code:

code path/to/your/project
© 2024-2025 GitByBit.All rights reserved.