1. Go to VS Code snippet Settings

  • Graphical entry:

  • Enter: UseCtrl+Shift+POpen the command panel and entersniSelect config user snippet:

2. VS Code built-in snippets





3. Create a user-defined code snippet

Choice.Create a new global snippet file

Sets the snippet name

Edit snippet content

The default content is empty, and the basic snippet format is given in the comments, as you can seeWrite in JSON format:

Each of these means the following:

  • Print to console: snippet name;
  • scope:
  • prefix: Keyword detected by VS Code when entering;
  • body: snippet content;
  • description: snippet description;

Where the body needs to be written in line, and in which you can use placeholders to control the cursor position and the content to be displayed, such as:

  • The $1Represents the first cursor position after insertion,$2Represents the second cursor position, and so on,$0Represents the last cursor position;
  • ${1: Please enter the file name}Represents the first cursor position, and the default display “Please enter a file name”;

Finally, use an example to illustrate how to write:

4. Insert user code snippets

When entering the code, enter the keyword of the set code, that is, the value of the prefix field set before to trigger the automatic prompt: