SublimeText / InsertNums

Sublime Text plugin for inserting sequences. Supporting alphanumerics and hex, with bitwise operations!
https://james-brooks.uk
MIT License
123 stars 15 forks source link

Insert Nums

A Sublime Text plugin, to insert (consecutive) numbers across multiple selections or modifiy selections' contents with expressions using sophisticated expressions syntax.

Installation

Package Control

The easiest way to install is using Package Control. It's listed as Insert Nums.

  1. Open Command Palette using ctrl+shift+P or menu item Tools → Command Palette...
  2. Choose Package Control: Install Package
  3. Find Insert Nums and hit Enter

Manual Setup

Alternatively, you can clone this repository into Sublime Text's Packages folder.

[!NOTE]

To find Packages folder call Menu > Preferences > Browse Packages..

OSX

#!/usr/bin/env bash
cd ~/Library/Application\ Support/Sublime\ Text/Packages/
git clone https://github.com/SublimeText/InsertNums "Insert Nums"

Linux

cd ~/.config/sublime-text/Packages
git clone https://github.com/SublimeText/InsertNums "Insert Nums"

Windows

cd "%APPDATA%\Sublime Text\Packages"
git clone https://github.com/SublimeText/InsertNums "Insert Nums"

Usage

An input panel opens which live-previews your current format string. If you close the panel (e.g. by pressing Esc), the changes will be undone. If you prefer to not have this live preview, you can disable it by also pressing the Shift key.

Insert a string in the format <start>:<step> and press enter. Both can be omitted and default to 1 (meaning 1:1).

For every selected region the inserted number (starting with start) will then be increased by step. But there is more!

Commands

Usage with numbers

Insert Nums supports both, integers and floating numbers, as start and step values respectively, also negative numbers. This means you can use 1:.4 on 4 selections and get this:

1.0
1.4
1.8
2.2

Furthermore, you can use arbitrary Python expressions to generate your numbers, e.g. for bitflags. An example can be found in the Examples.

See the Advanced usage section for information about using a specific formatting.

Usage with the alphabet

Insert Nums can also insert the alphabet. Just use a as start value, or change a to whatever character you'd like to start from. step only accepts integers because there are obviously no fractions of the characters in the alphabet.

One of the side effects of introducing alpha sequences is that you can generate seemingly (but definitely not) random sequences. For instance, using a:12345 will generate the following across three selections:

a
rfv
ajmq

All that's happening there is that the next letter in the sequence is shunted across by the step amount.

If you'd rather like Insert Nums to wrap when the last character (z) is reached, you can append ~w. Thus, a:12345~w will generate this:

a
v
q

For more options see the following Advanced usage section.

Expression Mode

Other than inserting numbers or alphas this mode takes the value of a selection and allows you to modify it with a Python expression. This will be explained in detail further below.

Advanced usage (insert)

The complete syntax is: <start>:<step>~<format>::<expr>@<stopexpr><reverse>, the corresponding separator is only required if you actually supply the following part. Every part itself is optional (defaulting to 1:1), but if you want the alpha mode you have to supply the alphabetical start value.

Below is an abstract example showing the syntax with all optional parts (indicated by []):

numbers: [<start>][:<step>][~<format>][::<expr>][@<stopexpr>][!]
alpha:   <start>[:<step>][~<format>][@<stopexpr>][!]

Detailed syntax definition: format_syntax.txt

Advanced usage (Expression)

In addition to the insert mode Insert Nums also specifies a way to modify the current selection(s). The syntax is as follows:

[<cast>]|[~<format>::]<expr>[@<stopexpr>][!]

Again, for the detailed syntax specification, see: format_syntax.txt.

The | pipe is used to show the meaning of piping the current selection to the following expression. stopexpr behaves a bit different than in insert mode and the current value _ is adjusted.

Examples

Basic insert

Insert with format

Expression Insert

Alpha insert

Stop expressions

Note: Assuming everything in Before has been selected with one selection spanning each line.

Expression mode

Note: Assuming everything in Before has been selected with one selection spanning each line.

And many more ...

Contributors

License

MIT - http://jbrooksuk.mit-license.org