LinuxCommandLibrary

code

Open Visual Studio Code editor

TLDR

Start Visual Studio Code

$ code
copy

Open specific files/directories
$ code [path/to/file_or_directory1 path/to/file_or_directory2 ...]
copy

Compare two specific files
$ code [[-d|--diff]] [path/to/file1] [path/to/file2]
copy

Open specific files/directories in a new window
$ code [[-n|--new-window]] [path/to/file_or_directory1 path/to/file_or_directory2 ...]
copy

Install/uninstall a specific extension
$ code --[install|uninstall]-extension [publisher.extension]
copy

Display diagnostic and process information about the running code window
$ code [[-s|--status]]
copy

Print installed extensions with their versions
$ code --list-extensions --show-versions
copy

Start the editor as a superuser (root) while storing user data in a specific directory
$ sudo code --user-data-dir [path/to/directory]
copy

SYNOPSIS

code [options] [path ...]

PARAMETERS

--help
    Show help message and exit.

--version
    Show version information and exit.

--list-extensions
    List installed extensions.

--install-extension
    Installs an extension.

--uninstall-extension
    Uninstalls an extension.

--enable-proposed-api
    Enables proposed APIs for extensions. Can receive one or more extension IDs to enable proposed APIs.

--disable-extensions
    Disable all installed extensions.

--disable-extension
    Disable an extension.

--status
    Prints process usage and diagnostics information. Can be used to investigate performance issues.

--verbose
    Enable verbose logging (console output).

--log
    Specify the log level (`trace`, `debug`, `info`, `warn`, `error`, `critical`, `off`).

--user-data-dir


    Specifies the directory to store user data.

--profile
    Opens with the given profile.

[path ...]
    Path to file or folder to open.

-r, --reuse-window
    Force to open a file or folder in an already opened window.

-n, --new-window
    Force a new instance of Code.

-g, --goto
    Open the file at path with the cursor at line and optional character position.

-d, --diff
    Open a diff editor comparing two files.

-m, --merge
    Open a merge editor with the three files.

-w, --wait
    Wait for the files to be closed before returning.

--locate-shell-integration
    Prints the path to the script for shell integration.

DESCRIPTION

The `code` command is a convenient way to launch Visual Studio Code from the command line. It allows you to quickly open files, directories, or even entire projects within VS Code. It's particularly useful for developers who prefer working in the terminal and want to seamlessly transition to a visual editor without disrupting their workflow. The `code` command accepts various options, enabling you to open multiple files or directories, specify a specific line number to start on, compare files, or even open a diff editor. This integration allows for a more efficient development experience by combining the power of the command line with the features of VS Code's editor.

CAVEATS

The `code` command relies on VS Code being installed and the `code` executable being properly configured in your system's PATH environment variable. If you encounter errors, ensure that VS Code is installed and that the `code` command is accessible from your terminal.

SHELL INTEGRATION

VS Code provides shell integration scripts that can be used to enhance the command-line experience. These scripts offer features like displaying the current branch in the terminal and showing decorations for modified files. Use `--locate-shell-integration` to find the script relevant to your shell (e.g., Bash, Zsh).

EXTENSION MANAGEMENT

The `code` command offers built-in extension management features. You can install, uninstall, enable, and disable extensions directly from the command line, which can be useful for scripting and automation.

HISTORY

The `code` command was introduced as part of the initial release of Visual Studio Code. It's designed to provide a seamless integration between the command line and the VS Code editor, catering to developers who prefer to work in both environments. Over time, the command has been enhanced with new options and features to further improve its usability and flexibility.

SEE ALSO

less(1), cat(1), vim(1), nano(1)

Copied to clipboard