Table of Contents
code practical function
Open the latest session
Open a specific project
Jump to the line of the file
code installation
Summary
Home Development Tools VSCode A brief analysis of the VSCode CLI tool, it turns out to be so useful!

A brief analysis of the VSCode CLI tool, it turns out to be so useful!

Sep 08, 2022 pm 08:34 PM
vscode

A brief analysis of the VSCode CLI tool, it turns out to be so useful!

Speaking of the vscode CLI tool, you may be unfamiliar with it because it is not necessary in daily work. But since some of its functions are quite practical, and some of my recent technical ideas can just be realized with the help of it, this article will talk about the practical functions of VSCode CLI. [Recommended study: "vscode introductory tutorial"]

The shell command of VSCode CLI is called code, and code will be used later to refer to VSCode CLI tools.

code practical function

Open the latest session

codeWithout any options or Parameter execution will open the latest session of VSCode. For example, if you recently opened projectA, no matter whether projectA is covered by other windows or you have exited VSCode, the following command can quickly open projectA:

$ code
Copy after login

If you are using the shell, this command should help you quickly open VSCode or locate the file you just edited.

Open a specific project

Here I would like to ask you how you usually use VSCode to open a project. Do you follow the following steps?

  • Click on the VSCode icon

  • Click on the menu bar File

  • Click on Open

  • Find and open it in Mac’s Finder

I’m not, I’m used to using the shell, and I think command line operations are faster than searching in Finder.

code . command is what I usually use the most. It can quickly open the project in the current directory in VSCode.

All my projects are placed in a fixed directory, so I only need to cd to the project directory first, and then execute code ..

Of course, you can also use code <folder> to open the project, the effect is the same.

Jump to the line of the file

##code -g ::The command can be fast Jump to a certain character in a certain line of the file. For example, the following command will open the index.ts file, and position the cursor at line 18, before the character index is 8.

$ code -g /project-path/src/index.ts:18:8
Copy after login
Some current dev tools such as

react-dev-inspector and vue-devtools allow developers to click on DOM elements to open and locate them in VSCode to the corresponding source code location. The principle is to obtain the location information of the source code when the dev server is running and insert it into the DOM element. Then when the developer clicks on the DOM, the location information is sent to the dev server. The dev server then calls the code ability to jump to the source code. .

File comparison

If you want to quickly compare two files, you can use the following command:

$ code -d file-path-a file-path-b
Copy after login
This pair is used to using VSCode to compare file differences and It may be more useful for students who resolve conflicts.

Plug-in operation

This is my favorite feature that I have discovered recently, including the following points:

  • code --list -extensions --show-versions: List all installed plug-ins in the form of .@;
  • code --install-extension : To install the plug-in, you can add the --force option to prevent pop-up prompts;
  • code --uninstall-extension : Uninstall the plug-in.
Imagine if you were asked to develop a front-end engineering scaffolding, what would you do?

Imitate most scaffolding on the market, and of course provide users with configurations related to code formats such as editorConfig, eslint, prettier, etc. But after completing these, the scaffolding only scores 90 points. In fact, in order for eslint to take effect, users must install the corresponding VSCode plug-in and configure

settings.json.

settings.json Fortunately, you can create settings.json in the .vscode directory to share configurations among team members and overwrite local Configuration, saving team members the trouble of manual configuration and avoiding the problem of inconsistent development configurations.

As for the VSCode plug-in, generally speaking, we let users install it themselves or it is already installed by default. But for front-end novices or new colleagues, this is undoubtedly painful, and it is also intolerable to excellent scaffolding developers. At this time, the above commands come into play.

--list-extensions Check whether the user has installed a plug-in. If not, use --install-extension to install it.

It is conceivable that with the help of the above commands for operating plug-ins and .vscode, the scaffolding can help users configure the development environment completely without any sense, and can ensure that everyone in the team has the same configuration. Yes, don't worry that one day a new colleague will come over and say that his eslint does not take effect.

Note: The commands related to plug-in operations are a bit powerful, so use them with caution.

code installation

Some students may say that to make code effective, you must not manually install codeIs the command installed on the global environment variable PATH?

This is like this on Mac, but we can also call code directly through the path /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code .

For Windows and Linux systems, code will be automatically added to PATH when VSCode is installed, and code can be called directly.

Therefore, scaffolding can be encapsulated to prevent users from manually adding environment variables.

Summary

This article only introduces some functions of VSCode CLI that I think are more practical. Other functions such as switching languages ​​and performance monitoring are not introduced. You can jump to the official website through the link in the information at the end of the article to view it.

Recently, I have been simply encapsulating code related commands, hoping to provide a set of basic capabilities for direct calls to other node projects. The project address is: github.com/avennn/vsc -…, everyone is welcome to use and PR. If you think it is good, you are welcome to give it a star.

For more knowledge about VSCode, please visit: vscode tutorial!

The above is the detailed content of A brief analysis of the VSCode CLI tool, it turns out to be so useful!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

How to define header files for vscode How to define header files for vscode Apr 15, 2025 pm 09:09 PM

How to define header files using Visual Studio Code? Create a header file and declare symbols in the header file using the .h or .hpp suffix name (such as classes, functions, variables) Compile the program using the #include directive to include the header file in the source file. The header file will be included and the declared symbols are available.

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

Common commands for vscode terminal Common commands for vscode terminal Apr 15, 2025 pm 10:06 PM

Common commands for VS Code terminals include: Clear the terminal screen (clear), list the current directory file (ls), change the current working directory (cd), print the current working directory path (pwd), create a new directory (mkdir), delete empty directory (rmdir), create a new file (touch) delete a file or directory (rm), copy a file or directory (cp), move or rename a file or directory (mv) display file content (cat) view file content and scroll (less) view file content only scroll down (more) display the first few lines of the file (head)

How to solve the problem of vscode Chinese annotations becoming question marks How to solve the problem of vscode Chinese annotations becoming question marks Apr 15, 2025 pm 11:36 PM

How to solve the problem that Chinese comments in Visual Studio Code become question marks: Check the file encoding and make sure it is "UTF-8 without BOM". Change the font to a font that supports Chinese characters, such as "Song Style" or "Microsoft Yahei". Reinstall the font. Enable Unicode support. Upgrade VSCode, restart the computer, and recreate the source file.

How to set vscode in Chinese How to set vscode in Chinese Apr 15, 2025 pm 09:27 PM

There are two ways to set up a Chinese language in Visual Studio Code: 1. Install the Chinese language package; 2. Modify the "locale" settings in the configuration file. Make sure Visual Studio Code version is 1.17 or higher.

vscode Previous Next Shortcut Key vscode Previous Next Shortcut Key Apr 15, 2025 pm 10:51 PM

VS Code One-step/Next step shortcut key usage: One-step (backward): Windows/Linux: Ctrl ←; macOS: Cmd ←Next step (forward): Windows/Linux: Ctrl →; macOS: Cmd →

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

See all articles