Skip to content

Multi-Insert of numbers, words, sequences or UUIDs

Notifications You must be signed in to change notification settings

antoniomolram/Text-Pastry

 
 

Repository files navigation

Text Pastry

Text Pastry is a plugin for Sublime Text 2 and gives you the tools to insert a sequence of text or numbers on multiple locations.

Installation

Thanks for using the excelent Package Control to install Text Pastry.

Usage

To use Text Pastry, we need to open a Document in ST2 and use Multiple Selection to mark the insert locations (in this document also refered to as selections).

Please keep in mind that the selected text could be replaced when we run the Text Pastry command. To avoid that, we can alway place the cursor between letters by using CMD + Click or even select a whole column by using ALT + Click

All we need to do now is to press CMD + ALT + N to open the Text Pastry command line. The input panel will show up at the bottom of ST2.

Now its time to run our first command. Let's enter first second third and hit enter to run the command. Text Pastry will add first to our first selection, second to the next selection and so on.

Text Pastry will only replace as many words as we type into the command line. So if we have more selections then words, the rest of our selection will remain intact.

Key Bindings

The default key bindings are stored at /Text Pastry/Default.sublime-keymap. As always, you can use your user keymap file to overrule the default key bindings.

Shortcut Action
CMD + ALT + T Show Text Pastry Menu
CMD + ALT + N Open Command Line

Note: The commands from the Text Pastry menu are also available through the Command Palete (CMD + SHIFT + P)

Command Reference

Text

Replaces the first selection with Lorem, the second selection with Ipsum, etc.:

Lorem Ipsum Dolor

Number Sequence

Inserts a sequence, starting at 1:

\i

Inserts a sequence, starting at 0:

\i0

Inserts a sequence by defining start index and step size:

\i(N,M)
  • N the start index
  • M the step size

Note: The Number Sequence command uses the syntax from TextPad.

Additionally, we can leave the brackets away if we want to:

\i1000,100

Clipboard

Inserts the content of the clipboard into our selections by splitting the words:

\p

Same as above with a specified string separator:

\p(sep)
  • sep the string separator used to split the clipboad data.

Note: The Clipboard command uses syntax from TextPad.

UUID

NEW Text Pastry will generate a UUID for each selection we have made:

\uuid

This command will generate a random UUID by using pythons uuid.uuid4() method:

dbf8326e-5243-406e-abd9-bd0425d3e842

We can use the following command to generate a random UUID in UPPERCASE:

\UUID

Insert Nums

Text Pastry has a build in support for the Insert Nums syntax by providing three numbers separated by one space:

N M P
  • N: the start index.
  • M represents the step size which will be added to the index for each selection.
  • P must be > 0 and will be used to pad the index with leading zeroes.

Note:

Examples

Here are some examples, assuming we have selected every ocurence of null and Text Pastry was called by pressing CMD + ALT + N:

Using a text list

Enter a list of words, separated by one space, into the command line:

INPUT SELECT TEXTAREA DIV P A

Text

var a = document.getElementsByTagName('null');
var b = document.getElementsByTagName('null');
var c = document.getElementsByTagName('null');
var d = document.getElementsByTagName('null');
var e = document.getElementsByTagName('null');
var f = document.getElementsByTagName('null');

Result

var a = document.getElementsByTagName('INPUT');
var b = document.getElementsByTagName('SELECT');
var c = document.getElementsByTagName('TEXTAREA');
var d = document.getElementsByTagName('DIV');
var e = document.getElementsByTagName('P');
var f = document.getElementsByTagName('A');

###Using the Clipboard###

The same as above, but this time we copy the list of words into our clipboard:

Clipboard Data

INPUT SELECT TEXTAREA DIV P A

Command

Insert this into the input panel:

\p

Text

var a = document.getElementsByTagName('null');
var b = document.getElementsByTagName('null');
var c = document.getElementsByTagName('null');
var d = document.getElementsByTagName('null');
var e = document.getElementsByTagName('null');
var f = document.getElementsByTagName('null');

Result

var a = document.getElementsByTagName('INPUT');
var b = document.getElementsByTagName('SELECT');
var c = document.getElementsByTagName('TEXTAREA');
var d = document.getElementsByTagName('DIV');
var e = document.getElementsByTagName('P');
var f = document.getElementsByTagName('A');

Note

If we copy following list, we will get the same result:

INPUT
SELECT
TEXTAREA
DIV
P
A

Clipboard Data v2

Lets assume we want to paste some test data into our code:

71602	White Hall
71603	Pine Bluff
71611	Pine Bluff
71612	White Hall
71613	Pine Bluff
71630	Arkansas City
71631	Banks
71635	Crossett
71638	Dermott
71639	Dumas

Command

This command will tell Text Pastry to split up our clipboard data by using the newline character as separator:

\p(\n)

Text

var a = load('null');
var b = load('null');
var c = load('null');
var d = load('null');
var e = load('null');
var f = load('null');

Result

var a = load('71602	White Hall');
var b = load('71603	Pine Bluff');
var c = load('71611	Pine Bluff');
var d = load('71612	White Hall');
var e = load('71613	Pine Bluff');
var f = load('71630	Arkansas City');

Note

Each line of the clipboard data will be stripped/trimmed, so there won't be any leading spaces.

The following list would therefore give us the same result when we use \p(\n) as command:

Data without leading/trailing whitespace

INPUT
SELECT
TEXTAREA
DIV
P
A

Data with leading whitespace:

INPUT
	SELECT
		TEXTAREA
		DIV
	P
A

We can change this behaviour in the <Packages>/Text Pastry/TextPastry.sublime-settings file:

"clipboard_strip_newline": false

From 1 to 3

Start at 1, adding 1 for each selection:

\i

Text

var a = null;
var b = null;
var c = null;

Result

var a = 1;
var b = 2;
var c = 3;

From 1000 to 1300

Start at 1000, adding 100 for each selection:

\i(1000,100)

Text

var a = null;
var b = null;
var c = null;

Result

var a = 1000;
var b = 1100;
var c = 1200;

From 100 to 50

You can also use negative numbers to create a negative sequence:

\i(100,-10)

Text

var a = null;
var b = null;
var c = null;
var d = null;
var e = null;
var f = null;

Result

var a = 100;
var b = 90;
var c = 80;
var d = 70;
var e = 60;
var f = 50;

Insert Nums Syntax

1 100 1

Text

var a = null;
var b = null;
var c = null;
var d = null;
var e = null;
var f = null;

Result

var a = 1;
var b = 101;
var c = 201;
var d = 301;
var e = 401;
var f = 501;

Insert Nums Syntax v2

1 1 3

Text

var a = null;
var b = null;
var c = null;
var d = null;
var e = null;
var f = null;

Result

var a = 001;
var b = 002;
var c = 003;
var d = 004;
var e = 005;
var f = 006;

Todo

  • Command List Overlay
  • Command History
  • UUID generation
  • Settings for word manipulation
  • Paste as Block
  • Add documentation for menu and history
  • Alphabetical sequence (upper/lower case)
  • Random numbers

See Also

For further information please take the time to look at following links:

About

Multi-Insert of numbers, words, sequences or UUIDs

Resources

Stars

Watchers

Forks

Packages

No packages published