Today I learned that Visual Studio Code has a powerful command-line interface (CLI) that lets you control how you launch the editor through command-line options (switches).
- Open a file:
code <file_path>. You can list multiple files separated by spaces. If a file doesn’t exist, it will be created. When opening multiple files, VS Code opens them all as tabs in a single window instance. - Open a folder:
code <folder_path>. You can specify multiple folders separated by spaces to create a Multi-root Workspace that includes each folder and allows you to manage multiple project “roots” simultaneously.
Open a file at a specific line and optional column.
code -g, --goto path/to/file:line[:column]Open a fresh session of VS Code instead of restoring the previous session.
code -n, --new-window [path/to/folder-or-file]You can also use -r or --reuse-window to force opening a file or folder in the last active window.
Wait for the opened file to be closed before returning to the command line. This is useful for things like editing a Git commit message.
code -w, --wait path/to/fileSpecify the directory for user data, which is useful for managing separate profiles or running as a different user.
code --user-data-dir "/path/to/custom/profile"Open VS Code with all installed extensions temporarily disabled.
code --disable-extensionsEnables verbose logging, which is helpful for diagnosing issues.
code --verboseDisplays all available CLI options.
code --helpAlternatively, you can view the manual page:
man codeFor a complete list of options, see the official documentation:
You can also use vscode:// URL schemes to open folders and files.
vscode://file/{full path to folder}/vscode://file/{full path to file}vscode://file/{full path to file}:line:column-
The column number for character position is optional. ↩
