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 directly helps developers launch VS Code directly from the 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, in which case you need to install the code command first.
After installing VS Code on Windows, the code command is automatically registered to the system environment variables. If not registered, you can manually add the VS Code installation path to the PATH environment variable.
Enabling the VSCode code command is very simple, first open the command palette:
* macOS system shortcut: β§βP (command + shift + p)
* Windows/Linux shortcut: Ctrl + Shift + P
Search for Install>shell command:
!(#)
Then select Install 'code' command in PATH - Shell Command: Install 'code' command in PATH to add the code command reference to the system PATH.
We can use the command line to open files, install extensions, modify the display language, and even view diagnostic information.
!(#)
Here are some commonly used command line options, you can view them via the code --help command:
!(#)
We can use the code . command in the command line to open a folder in VS Code:
!(#)
| Command | Function Description |
| --- | --- |
| `code ` | Open file or folder |
| `code .` | Open current directory as workspace |
| `code --new-window` | Open in new window |
| `code --diff` | Compare contents of two files |
| `code --wait` | Return to terminal after window closes |
| `code --disable-extensions` | Disable all extensions to run VS Code |
| `code --install-extension ` | Install specified extension |
| `code --list-extensions` | List all installed extensions |
| `code --uninstall-extension ` | Uninstall specified extension |
### Common Functions of the code Command
**1. Open File or Folder**
code
For example, to open the app.js file:
code app.js
Open folder (as workspace):
code
For example, to open the my-project folder:
code my-project
**2. Create 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 Current Directory as Workspace**
Running the code command directly will start VS Code with the current terminal directory as the workspace:
code .
**4. Compare Files**
The code command supports file content comparison:
code --diff
Example:
code --diff index.html index-backup.html
**5. View Help**
View all available options for the code command:
code --help
* * *
## Use code Command to Open Vue Project
### Create Vue Project
Open terminal or command prompt, enter the following command to create a Vue project:
npm create vue@latest
The system will prompt you to enter the project name, I entered tutorial-vue3-app:
Vue.js - The Progressive JavaScript Framework? Please enter project name: βΊ tutorial-vue3-app
Then there will be some options, you can choose according to your needs, or press Enter all the way:
Vue.js - The Progressive JavaScript Framework> Please enter project name: β¦ tutorial-vue3-app > Use TypeScript syntax? β¦ No / Yes> Enable JSX support? β¦ No / Yes> Introduce Vue Router for single-page application development? β¦ No / Yes> Introduce Pinia for state management? β¦ No / Yes> Introduce Vitest for unit testing? β¦ No / Yes> Do you want to introduce an end-to-end (End to End) testing tool? βΊ No need> Introduce ESLint for code quality detection? βΊ NoInitializing project /Users/Tutorial/tutorial-vue3-app...Project initialization complete, you can execute the following commands: cd tutorial-vue3-app npm install npm run dev
After the project is created, enter the project folder and install dependencies:
cd tutorial-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 the browser, it displays as follows:
!(#)
Press Ctrl+C to stop the vue-cli-service server.
### Use code Command to Open Vue Project
From the terminal or command prompt, enter the Vue project folder we created, tutorial-vue3-app, then use the code command to open the project in VS Code:
cd tutorial-vue3-app code .
VS Code will start and display your Vue project in the file explorer, as shown below:
!(https://
YouTip