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...] [paths...]

PARAMETERS

-n, --new-window
    Open in a new window

-d, --diff
    Compare two folders or files

-a, --add
    Add folder(s) to the last active window

-g, --goto
    Open file at path on line:col

-w, --wait
    Wait for file to be closed before returning

-r, --reuse-window
    Open in existing window

--help
    Print usage

--version
    Print version

--install-extension
    Install extension

--list-extensions
    List installed extensions

--uninstall-extension
    Uninstall extension

-f, --folder-uri
    Open folder from URI

-u, --user-data-dir


    Specify user data directory

DESCRIPTION

The code command launches Visual Studio Code (VS Code), a popular open-source code editor developed by Microsoft. It allows users to open files, folders, or workspaces directly from the terminal, making it efficient for developers. When invoked without arguments, it opens VS Code in the current directory.

Key features include support for extensions, integrated terminal, Git integration, and debugging. The command integrates seamlessly with shell environments, enabling quick edits via commands like code file.txt. It supports multiple instances, new windows, and specific line navigation.

Installation typically adds code to PATH via VS Code's "Install 'code' command in PATH" option in the Command Palette (Ctrl+Shift+P). On Linux, it may require manual symlink setup from $VSCODE_PATH/bin/code. Ideal for scripting and automation, it enhances productivity in CLI-heavy workflows.

CAVEATS

Requires VS Code installed with 'code' in PATH; may not work in restricted environments without proper setup. Large workspaces can consume significant memory.

REMOTE USAGE

Supports code --remote ssh-remote+host for remote development after VS Code Server setup.

WORKSPACE SUPPORT

Use code --workspace workspace.code-workspace to open multi-root workspaces.

HISTORY

Introduced with Visual Studio Code 1.0 in 2015 by Microsoft. Evolved with VS Code releases, adding extension management and remote support in later versions (e.g., 1.30+ for CLI improvements). Widely adopted in Linux distros via snaps/flathub.

SEE ALSO

vim(1), nano(1), emacs(1), gedit(1)

Copied to clipboard