ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Enhanced​Snippets

by OdatNurd ST4

A Sublime Text 4 extension package for adding custom variables to Sublime snippets

Details

Installs

  • Total 100
  • Win 50
  • Mac 25
  • Linux 25
Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8 Nov 7 Nov 6 Nov 5 Nov 4 Nov 3 Nov 2 Nov 1 Oct 31 Oct 30 Oct 29 Oct 28 Oct 27 Oct 26 Oct 25 Oct 24 Oct 23 Oct 22 Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8
Windows 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 3 1 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0
Linux 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

Introduction

EnhancedSnippets is a package for Sublime Text 4 that extends and enhances the Snippet System in Sublime Text to include:

  • A new .enhanced-sublime-snippet file type that is a text file with YAML front matter instead of an XML file
  • Snippets can be made available not only by scope but also by glob (i.e. only if the file name matches a specific format), or optionally both at once
  • The ability to add your own variables to snippets, such as $DATE, $BUZZWORD and $CLIPBOARD (all included by default)
  • Snippet fields can be given a list of options, for which you will be prompted to select a value when the snippet expands.

Demo Video

---
tabTrigger: 'wind'
scope: 'text.html - (meta.tag | meta.character.less-than) - source.php'
description: 'Windstorm HTML Template'
options:
  - field: 2
    placeholder: 'Windstorm Version Number'
    values:
      - '0.3.8'
      - 'latest'
---
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>$1</title>
</head>
<body>

  <script src="https://cdn.jsdelivr.net/npm/@axel669/windstorm@${2:latest}/dist/browser.js"></script>

  $0
</body>
</html>

Installation

Package Control

The best way to install the package is via PackageControl, as this will take care of ensuring that the package is kept up to date without your having to do anything at all.

You can install via Package Control by opening the Command Palette and selecting the command Package Control: Install Package and searching for EnhancedSnippets in the list of packages.

Manual Installation

In order to manually install the package, clone the repository into your Sublime Text Packages directory. You can locate this directory by choosing Preferences > Browse Packages... from the menu.

Manual installation is not recommended for most users, as in this case you are responsible for manually keeping everything up to date. You should only use manual installation if you have a very compelling reason to do so and are familiar enough with the process to know how to do it properly.

In a Nutshell

EnhancedSnippets adds support for a new snippet file extension, enhanced-sublime-snippet; this is a text file with YAML front matter to help create snippets in an easier to read way. EnhancedSnippets will only load and recognize files of the enhanced-sublime-snippet extension!

Once created, enhanced-sublime-snippet files are automatically loaded when Sublime starts, reloaded when they are changed, and will be loaded and unloaded from third party packages as well (if that package has any defined).

Enhanced snippets will be available via autocomplete, added to the command palette (although they will not show their tab triggers the way that a native snippet can, currently), and can be used in key bindings and menu entries via the insert_enhanced_snippet command, which is a drop in placement for the built in insert_snippet command.

In addition to the properties that a normal snippet has, an enhanced snippet has the following extra capabilities; examples of all of these are outlined in the following section.

  • You can include a glob key to constrain the snippet only to files that match the glob; this can be used instead of, or in addition to, the normal scope key.
  • Numeric snippet fields can optionally include a list of multiple choice options; while tabbing through the snippet fields, landing on a field with options will display a list of the available options for you to choose from
  • There is an API that allows for the creation of new snippet variables; such variables are available any time the snippet expands, including when triggered via AutoComplete. Out of the box, the $DATE, $CLIPBOARD and $BUZZWORD variables are available.

For more detailed documentation on the package, please consult the official documentation site.