Linux command
code 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Open VS Code
code .
Open a specific file
code [path/to/file]
Open a file at a specific line
code -g [file.txt]:[line]:[column]
Open a new window
code -n
Open a file in an existing window
code -r [path/to/file]
Compare two files
code -d [file1] [file2]
Install an extension
code --install-extension [publisher.extension]
List installed extensions
code --list-extensions
说明
code is the command-line interface for Visual Studio Code, Microsoft's popular source code editor. It allows launching the editor, opening files and folders, managing extensions, and integrating VS Code into command-line workflows. The CLI supports opening files at specific positions, which is useful for jumping to error locations from build tools or linters. The diff mode provides visual comparison between files. The --wait flag enables using VS Code as a Git editor or for other tools that need to wait for file editing completion. Extension management through the CLI enables scripting VS Code setup and synchronizing development environments. Combined with the Settings Sync feature, this allows reproducible editor configurations across machines.
参数
- -n, --new-window
- Open a new VS Code window.
- -r, --reuse-window
- Open files in the last active window.
- -g, --goto
- Open file at specific line and column (file:line:column).
- -d, --diff
- Compare two files in diff mode.
- -w, --wait
- Wait for files to be closed before returning.
- --locale _LOCALE_
- Set the display language (e.g., en-US, zh-CN).
- --install-extension _EXT_
- Install a VS Code extension by ID.
- --uninstall-extension _EXT_
- Uninstall a VS Code extension.
- --list-extensions
- List all installed extensions.
- --disable-extensions
- Disable all installed extensions for this session.
- --user-data-dir _DIR_
- Specify the directory for user data.
- -v, --version
- Display version information.
- -h, --help
- Display help information.
FAQ
What is the code command used for?
code is the command-line interface for Visual Studio Code, Microsoft's popular source code editor. It allows launching the editor, opening files and folders, managing extensions, and integrating VS Code into command-line workflows. The CLI supports opening files at specific positions, which is useful for jumping to error locations from build tools or linters. The diff mode provides visual comparison between files. The --wait flag enables using VS Code as a Git editor or for other tools that need to wait for file editing completion. Extension management through the CLI enables scripting VS Code setup and synchronizing development environments. Combined with the Settings Sync feature, this allows reproducible editor configurations across machines.
How do I run a basic code example?
Run `code .` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -n, --new-window do in code?
Open a new VS Code window.