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

Wrap​It

by pykong ST3

Wrap Contents With Specific Code

Details

Installs

  • Total 255
  • Win 154
  • OS X 69
  • Linux 32
Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 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
Windows 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 2 0 0 0 0 0 0 1 0 1 0 0
OS X 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 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1
Linux 0 0 0 2 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 0

Readme

Source
raw.​githubusercontent.​com

WrapIt

Sublime Text 3 plugin to easily wrap a text selection in predefined code blocks.

WhatFor?

  • Want to surround a selection with brackets? Easy. Just WrapIt!
  • Need to have these few lines inside an if-else block. It's fun. Just WrapIt!
  • Like to join several functions into a class declaration? No problem. Just WrapIt!
  • Want to … I think you get it! Just WrapIt! ;-)

Installation

Just use PackageControl. I am not going to explain here how to use it.

Usage

Wrapping

  1. Put your cursor anywhere, or select some text then hit alt+w.
  2. The quick panel will open giving you a range of code structure for wrapping your text with.
  3. Once you chose one, your text will rapidly get embedded into the selcted code structure.
  4. Like in any snippets you can use tab to move between different regions of that code to successively fill it.

Defining custom wrappers

By default WrapIt comes with templates for PHP, Python, JavaScript and JSON. You can extend the user settings file with custom templates for any syntax. Like so:

"definitions":[
                    { 
                      "name":"Python",
                      "syntaxes": [
                        "Packages/Python/Python.sublime-syntax",
                        "Packages/Python 3/Python3.tmLanguage",
                        "Packages/Python Improved/PythonImproved.tmLanguage",
                        "Packages/MagicPython/grammars/MagicPython.tmLanguage"
                      ],
                      "wrappers": [
                        {
                          "name": "if / else",
                          "description": "Wrap with: if - else block",
                          template":"\nif ${1}:\n\t<sel>\nelse:\n\t${2}"
                        }
                      ]
                    }
                  ]
  1. Copy definitions from to default to user settings file of the WrapIt package.
  2. Either extend an existing language or define a new one.
  3. “name” - name of language e.g. PYthon
  4. “syntaxed” - array of paths to .tmLanguage files for that language
  5. “wrappers” - array of objects for defining code blocks
  6. code block -
  7. “name” - name code block (label for quick panel)
  8. “descriptions” - one sentence descriptin of code block (sublabl for quick panel)
  9. “template” - template definition

Note: Both “name” and “template” must be filled or the respective code block will not be listed in the quick panel.

templating

  • <sel> - where your selection should be placed
  • \n - new line
  • \t - indent for line, if preceeding tag, all lines of a multiline selection will get indented
  • ${x} - regions for tab navigation, just like in snippets

Custom keybinding

As an alternative to the qick panel, commonly used wrapping can be bound to own key combination. In your user keybindings file, do:

{"keys": [ YOUR KEY COMBINATION ],
    "command": "wrap_it",
    "args": { NAME OF CODE BLOCK},
    "context": [SPECIFY SYNTAX HERE]},

Contributors

  • lattespirit: original idea, primordial version called sublime-wrapper.