VSCode code Command
In Visual Studio Code, the code command is a command-line tool used to quickly open VS Code and perform some code-related operations.
The code command helps developers launch VS Code directly from a terminal or command prompt, or handle specific tasks.
The most common way is to use the code command to open a file directory directly from the command line, which requires installing the code command first.
After installing VS Code on Windows, the code command is automatically registered in the system environment variables; if not registered, you can manually add the VS Code installation path to the PATH environment variable.
Enabling VSCode's code command is very simple; first open the Command Palette:
- macOS shortcut: Shift+Cmd+P (command + shift + p)
- Windows/Linux shortcut: Ctrl + Shift + P
Search for and install >shell command:

Then select Shell Command: Install 'code' command in PATH to add a reference to the code command to the system PATH.
We can open files, install extensions, change the display language, and even view diagnostic information via the command line.

The following are some commonly used command-line options, which you can view with the code --help command:

We can use the code . command in the command line to open a folder in VS Code:

| Command | Description |
|---|---|
code <路径> |
Open a file or folder |
code . |
Open the current directory as a workspace |
code --new-window |
Open in a new window |
code --diff |
Compare the contents of two files |
code --wait |
Wait for the window to close before returning to the terminal |
code --disable-extensions |
Run VS Code with all extensions disabled |
code --install-extension <扩展名> |
Install a specified extension |
code --list-extensions |
List all installed extensions |
code --uninstall-extension <扩展名> |
Uninstall a specified extension |
Common functions of the code command
1. Open a file or folder
code <文件路径>
For example, open the app.js file:
code app.js
Open a folder (as a workspace):
code <文件夹路径>
For example, open the my-project folder:
code my-project
2. Create a new file
If the specified file does not exist, code will create the file and open it:
code newfile.js
** 3. Open VS Code with the current directory as workspace**
Running the code command directly starts VS Code with the current terminal directory as the workspace:
code .
4. Compare files
The code command supports file content comparison:
code --diff <文件1> <文件2>
Example:
code --diff index.html index-backup.html
5. View help
View all available options of the code command:
code --help
Using the code command to open a vue project
Create a vue project
Open a terminal or command prompt and enter the following command to create a vue project:
npm create vue@latest
The system will prompt you to enter a project name; here we enter runoob-vue3-app:
Vue.js - The Progressive JavaScript Framework
? 请输入项目名称: › runoob-vue3-app
After that, there will be some options; you can choose according to your needs, or simply press Enter all the way through:
Vue.js - The Progressive JavaScript Framework
> 请输入项目名称: … runoob-vue3-app
> 是否使用 TypeScript 语法? … 否 / 是
> 是否启用 JSX 支持? … 否 / 是
> 是否引入 Vue Router 进行单页面应用开发? … 否 / 是
> 是否引入 Pinia 用于状态管理? … 否 / 是
> 是否引入 Vitest 用于单元测试? … 否 / 是
> 是否要引入一款端到端(End to End)测试工具? › 不需要
> 是否引入 ESLint 用于代码质量检测? › 否
正在初始化项目 /Users/Runoob/runoob-vue3-app...
Project initialization is complete, you can execute the following commands:
cd runoob-vue3-app
npm install
npm run dev
After the project is created, enter the project folder and install dependencies:
cd runoob-vue3-app
npm install
Installing dependencies may also take a few minutes.
Enter the following command to quickly start your Vue application:
npm run dev

Open http://localhost:5173 in your browser; it will display as follows:

Press Ctrl+C to stop the vue-cli-service server.
Using the code command to open a vue project
From the terminal or command prompt, navigate to the Vue project folder runoob-vue3-app that we created, then use the code command to open the project in VS Code:
cd runoob-vue3-app
code .
VS Code will start and display your Vue project in the file explorer, as shown below:
