在终端用 code . 打开 VS Code

利用 VS Code 自带的命令行工具,从 cmd 或 PowerShell 直接把当前文件夹打开成工作区。

WindowsVS Code开发低风险
在任意终端里 cd 到项目目录,运行 code . 即可把该文件夹作为工作区在 VS Code 中打开。

01命令

命令
$ code .

02作用说明

code 命令随 VS Code 一起安装:code . 打开当前文件夹,code file.txt 打开单个文件,code -r . 则复用上一个窗口而不是新开一个。如果提示找不到命令,Windows 用户需要重开终端让 PATH 生效,或在安装时勾选"添加到 PATH"。在 VS Code 内置终端里同样可用,方便快速打开相邻的项目文件夹。

03风险

风险低风险
使用条件Visual Studio Code installed with the 'code' command on PATH — enable "Add to PATH" during setup, or run "Shell Command: Install 'code' command in PATH"
!注意: 如果终端是在安装 VS Code 之前打开的,命令会不可用——重启终端加载新的 PATH 即可。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Command Line Interface (VS Code)
    Microsoft · vendor-doc · 2026-09-17
    依据: Documents the code CLI: code . opens the current folder, code file.txt opens files, and flags like -r/-n/-d control window reuse.

最后验证: 2026-09-18 · 分类: 开发者

06相关方案