abulka / vscode-snippet-creator

An extension to simplify the snippet creation
11 stars 2 forks source link

Snippet Creator

This extension helps to automate snippet creation. Select the code you want to create snippet from and use command Create Snippet from the command palette or your custom keybind.

😥 This extension was accidentally deleted from the marketplace in mid 2020, but is now back! The number of downloads count, unfortunately, has been reset to zero

Features

Example

Usage

Use the command Create Snippet from the command palette or your custom keybind:

When answering the prompts:

Tip: It's OK to simply hit ENTER when prompted for the prefix and description. The prefix becomes the same as the name, and the description becomes 'description for name'.

Your snippet will now have been added to the relevant snippets file, and is now ready to use.


Mini Tutorial on Snippets

Inserting your new snippet

Use Insert Snippet (a built-in vscode command) to select and insert your snippet. Alternatively, whilst typing in the vscode editor, snippets prefixes are automatically listed in the vscode code completion dropdown.

This plugin does not change the standard way you insert snippets.

Tip: Optionally, use the extension Snippets Explorer (see below) to list all snippets in a treeview and insert snippets.

Editing snippets

You can edit snippets created by this extension using Preferences: Configure User Snippets (a built-in vscode command) to select a language and edit your snippets JSON file.

This plugin does not change the standard way you edit snippets. Just use the built in vscode command.

Why edit snippets?

What a snippet looks like:

e.g. in python.json in your ~/vscode/snippets directory:

    "my snippet": {
        "prefix": "mysnip",
        "body": "# this is a fragment of code which is a comment",
        "description": "a nice description of my snippet"
    },
    "my other snippet": {
        "prefix": "mysnip2",
        "body": [
            "a",
            "b",
            "\tc",
            "d",
        ],
        "description": "a nice description of my other snippet"
    },

Note snippets that cover more than one line are converted to arrays of strings, making editing them easier.


Background

Before this extension existed, you had to generate snippets by crafting the JSON manually or by visiting https://snippet-generator.app/ and pasting into the relevant JSON snippet file.

See Also

You may also be interested in Snippets Explorer in the marketplace, which offers a treeview of all available snippets - hover to preview, click to insert. Search for 'wware' in the marketplace to find it.