Wrap

A Sublime Text plugin for fast bracket wrapping.

Code Downloads Package Control Page View More Plugins

Overview

Wrap is a Sublime Text plugin I developed to automate a simple yet frequently performed action: wrapping text with brackets and a prefix. Examples are shown below.

Motivation

I observed that when writing code, I often needed to pass a variable into a function after already having typed the variable itself.

In Python, for instance, I might write the following print statement for debugging purposes.

print(some_list)

At a later time, I might realize that I actually want to print out the length of some_list instead of its elements.

print(len(some_list))

Before Wrap, I had to manually move my cursor to both ends of some_list, insert the parentheses, move my cursor to the left of the opening parenthesis, and then type out len.

I wanted to make this task slightly less manual. Wrap is the result. With Wrap, I now only need to press a keyboard shortcut before typing the function name, in this case len. Wrap automatically inserts the brackets and positions the text correctly.

The example above is just one use case. While the time saved is admittedly minimal each time, the frequency with which I use Wrap translates to a sizable increase in efficiency in the long term.

Demo

The plugin’s wrap command is showcased in the following video.

The command can be triggered from the command palette. Alternatively, as shown in the video, the command can also be run via a keyboard shortcut.

Customization

Users can configure Wrap to suit their exact preferences.

Firstly, users can specify a default bracket_type to be used, such as (), [], or {}.

In addition, users can define context-specific bracket types to be used when editing contents of different syntaxes. For example, a context is defined for \(\LaTeX\) by default, where the {} brackets are used.

Learn More

The code for this plugin can be found here. Its Package Control listing is located here.

To learn more about my other Sublime Text plugins, visit this page.