Skip to main content

Command Palette

Search for a command to run...

Make your Own VsCode Snippets

Published
โ€ข2 min read
Make your Own VsCode Snippets
A

Self taught programmer

Make your Own VsCode Snippets

Snippets are very useful for quickly creating code, but do you know it's more AWESOME to make one?

Make your own snippets in VsCode

1. Open VsCode and type

Press Ctrl + Shift + P to Open Command Palette in VsCode.

Image description

1. type Configure User Snippets

๐Ÿ’ฅ Enter

1. type Select the language you want to create snippets for
  • java
  • javascript
  • python
  • css .... Let's Enter Javascript. Image description
    {
      // โ†“ this is name of snippet
      "Print to console": {
          // โ†“ this is prefix the command will be typed to use it.
           "prefix": "log",
          //  โ†“ this is the snippet itself, body of the snippet
           "body": [
              //  $1 is the placeholder for the first argument, $number defines tabindex for the snippet.
               "console.log('$1');",
               "$2"
           ],
          //  โ†“ this is the description of the snippet.
           "description": "Log output to console"
       }
    }
    
1. type Save the snippet/ Close the file.
2. Make a file index.js
3. use the prefix to type the snippet.
4. type log and hit enter.

you can also add more functionality like filename, foldername, cursor position, to your snippets, as a adding variables to your snippets

Read more variables in snippets from VsCode snippets docs.

Share which snippets you are gonna create with this

Thanks for reading. Share your snippets with everyone. comment about topics you like.

๐Ÿค๐ŸพConnect me on: Twitter: ๐Ÿ•Š๏ธ@Abhayprajapati_ Github: ๐Ÿง@theabhayprajapati Linkedin: ๐Ÿ“Œ@abhayprajaapati Youtube: ๐Ÿ“บ@Abhayprajapati