• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 11 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sublime Text plugin for inserting sequences. Supporting alphanumerics and hex, with bitwise operations!

Insert Nums for Sublime Text 2 and 3.

A Sublime Text 2 and 3 plugin, that inserts (consecutive) numbers across multiple selections or modifies the selections' contents with expressions. Huge configurability.

Installation

You can install Insert Nums via Package Control by searching for Insert Nums.

Alternatively, you can download the Zip and copy it to your Sublime Text Packages folder, or use git clone.

Usage

  • Windows and Linux: Ctrl+Alt+N
  • OSX: โŒ˜+โŽ‡+N

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

  • prompt_insert_nums

    Opens an input panel with live preview as explained above. The parameter preview can specify if Insert Nums should show a live preview when editing the format string. Defaults to true.

  • insert_nums

    This is the basic command. Call this with a format parameter and bind it to a keyboard shortcut if you find yourself using a query very often.

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

  • start

    • with numbers (optional): A [decimalinteger]decimalinteger or [floatnumber]floatnumber according to Python's syntax specifications with an optional leading sign (- or +). Default: 1

    • with alphabet (required): A sequence of either lower- or uppercase ASCII characters from the alphabet (a to z and A to Z).

  • step (optional)

  • format (optional)

    • with numbers: A format string in Python's Format Specific Mini-Language (with small and unimportant adjustments for allowed types).

    • with alphabet: Similar to with numbers but a stripped-down version only for strings. This only includes the [[fill]align][width] syntax and additionally accepts a w character at the end (see above).

  • expr (optional)

    • numbers only: A valid Python expression which modifies the value as you please. If specified, the format string is applied afterwards. Here is a list of available variables:

      • s: The value of step (specified in the format query and defaults to 1)
      • n: The number of selections
      • i: Just an integer holding the counter for the iteration; starts at 0 and is increased by 1 in every loop
      • _: The current value before the expression (start + i * step)
      • p: The result of the previously evaluated value (without formatting); 0 for the first value
      • math, random, re and itertools: Useful modules that are pre-imported for you

      Note: The return value does not have to be a number type, you can also generate strings, tuples or booleans.

  • stopexpr (optional)

    A valid Python expression which returns a value that translates to true or false (in a boolean context). Theoretically this can be any value. You can use the same values as in expr with addition of the following:

    • c: The current evaluated value by the expression (without formatting) or just the same as _ if there was no expression specified

    This ignores the number of selections which means that you can also have more or less values than selections. Especially useful when generating numbers from a single selection.

    • If there is more selections than numbers generated when processing the stop expression, all the remaining selections' text will be deleted.
    • If there is more numbers generated than selections, all further numbers are joining by newlines ("\n") and added to the last selection made. This can be the first selection if there is only one.
  • reverse (optional)

    Must be ! and results in the regions being filled in reversed order.

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.

  • cast (optional)

    Can be one of s, i, f or b and means that the string in the selection will be converted to the corresponding type, if possible. An error message is shown otherwise.

    • s: str or unicode (in ST2) (default)
    • i: int
    • f: float
    • b: bool
  • format (optional)

    Same as in insert mode.

  • expr

    Same as in insert mode, except that _ represents the (converted) value of the current selection.

  • stopexpr (optional)

    Usage is the same as in insert mode and the _ for expression mode, but the effects are a bit different:

    • You can not generate more values than there are selections.
    • If you generate less values than there are selections, the remaining selections will be untouched. Return "" in the expression if you want to clear them.
  • reverse (optional)

    Must be ! and results in both the selections being parsed and the regions being filled in reversed order.

Examples

Basic insert

  • 1 or

    1
    2
    3
    4
    5
    6
    
  • -10:2~3

    -10
     -8
     -6
     -4
     -2
      0
      2
      4
    
  • 11:11~+4

     +11
     +22
     +33
     +44
     +55
     +66
     +77
     +88
     +99
    +110
    

Insert with format

  • 0.2:.002~-<5 (see g type (default) in the Python format docs)

    0.2--
    0.202
    0.204
    0.206
    0.208
    0.21-
    0.212
    
  • .2:2e-3~6.4f

    0.2000
    0.2020
    0.2040
    0.2060
    0.2080
    0.2100
    0.2120
    
  • 8:8~#010x!

    0x00000038
    0x00000030
    0x00000028
    0x00000020
    0x00000018
    0x00000010
    0x00000008
    

Expression Insert

  • 0~#06x::1<<_

    0x0001
    0x0002
    0x0004
    0x0008
    0x0010
    0x0020
    0x0040
    0x0080
    0x0100
    
  • ::i**2

    1
    4
    9
    16
    25
    36
    
  • ::list(itertools.product(['a', 'b', 'c'], ['x', 'y', 'z']))[i]

    ('a', 'x')
    ('a', 'y')
    ('a', 'z')
    ('b', 'x')
    ('b', 'y')
    ('b', 'z')
    ('c', 'x')
    ('c', 'y')
    ('c', 'z')
    

Alpha insert

  • z:25~w or z:-1~w

    z
    y
    x
    w
    v
    u
    t
    
  • aa:10000~ ^6 (here, | represents the cursors to visualize trailing spaces)

      aa  |
     nuq  |
     acpg |
     arjw |
     bgem |
     buzc |
     cjts |
    

Stop expressions

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

  • Before:

    1
    2
    3
    4
    5
    

    @_>3

    1
    2
    3
    
    
    
  • Before:

    1
    

    ~02@p==10 or ~02@_>10 or ~02@i==10

    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    

Expression mode

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

  • Before:

    1
    2
    3
    4
    5
    

    i|_+p

    1
    3
    6
    10
    15
    

    i|p+3 if i!= 0 else _!

    27
    24
    21
    18
    15
    
  • Before:

    pointfloat    ::=  {integer}? \. \d+ | {integer} \.
    exponentfloat ::=  (?:{integer} | {pointfloat}) [eE] [+-]? \d+
    float         ::=  {pointfloat} | {exponentfloat}
    numeric       ::=  {integer} | {float}
    signednum     ::=  [+-]? {numeric}
    

    |re.sub(r' +', ' ', _)

    pointfloat ::= {integer}? \. \d+ | {integer} \.
    exponentfloat ::= (?:{integer} | {pointfloat}) [eE] [+-]? \d+
    float ::= {pointfloat} | {exponentfloat}
    numeric ::= {integer} | {float}
    signednum ::= [+-]? {numeric}
    

And many more ...

Contributors

License

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

More Repositories

1

Spacegray

A Hyperminimal UI Theme for Sublime Text
JavaScript
7,188
star
2

LaTeXTools

LaTeX plugin for Sublime Text
Python
2,007
star
3

Origami

Split the window however you like! Create new panes, delete panes, move and clone views from pane to pane.
Python
1,208
star
4

CTags

CTags support for Sublime Text
Python
987
star
5

TrailingSpaces

Highlight trailing spaces and delete them in a flash.
Python
897
star
6

AdvancedNewFile

File creation plugin for Sublime Text
Python
828
star
7

CoffeeScript

Syntax highlighting and checking, commands, shortcuts, snippets, watched compilation and more.
CoffeeScript
439
star
8

PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
Python
436
star
9

VintageEx

An implementation of Vim's command-line mode for Sublime Text 2
Python
381
star
10

PowerShell

Support for the MS PowerShell programming language.
PowerShell
313
star
11

Helium

Let Sublime Text talk with Jupyter.
Python
236
star
12

ColdFusion

ColdFusion Sublime Text Package
Python
197
star
13

VBScript

VBScript package for Sublime Text
Python
185
star
14

WordHighlight

Highlight all copies of the currently selected word.
Python
180
star
15

PhpDoc

PhpDoc support package.
JavaScript
165
star
16

Terraform

Terraform (HCL) configuration file syntax highlighting for Sublime Text
HCL
163
star
17

RSpec

Sublime Text 2 / 3 plugin for RSpec BDD Framework
Python
124
star
18

UnitTesting

Testing Sublime Text Packages
Python
111
star
19

IndentGuides

Draw vertical guides to easily visualize indent depth.
Python
106
star
20

Mote

SFTP Remote Editing for Sublime Text 2
Python
105
star
21

Pywin32

Pywin32 support for sublime (win32api etc)
Python
81
star
22

ElasticTabstops

Tab characters automatically adjust to keep adjacent lines aligned.
Python
67
star
23

PhpBeautifier

Pear Php_beautifier plugin for Sublime Text 2
Python
66
star
24

SaneSnippets

Sublime Text snippets optimized for humans, not robots
Python
59
star
25

LegacyColorSchemes

Color schemes that were part of Sublime Text 2 and older builds of Sublime Text 3
52
star
26

sublime_lib

Utility library for frequently used functionality in Sublime Text and convenience functions or classes
Python
52
star
27

Theme-DAneo

A theme for Sublime Text 3.2+ inspired by the popular DA UI
Python
51
star
28

Sass

Sass and SCSS syntax for Sublime Text
SCSS
50
star
29

material-theme

Material Theme, a theme for Sublime Text 3, made by Mattia Astorino
Python
44
star
30

GenerateUUID

Generate UUID for Sublime Text
Python
42
star
31

NSIS

Sublime Text plugin for the Nullsoft Scriptable Install System
Shell
40
star
32

WinMerge

Plugin that enables comparison of the last 2 activated buffers (even in different windows) using WinDiff (Windows only).
Python
37
star
33

InactivePanes

Sublime Text plugin that slightly dims (or grays) inactive panes in your group view
Python
32
star
34

SublimeHg

Use Mercurial from Sublime Text.
Python
30
star
35

QML

QML support for Sublime Text and Sublime Merge
QML
28
star
36

StatusBarFileSize

Show the file size in the Sublime Text status bar
Python
27
star
37

TailwindCSS

Tailswind CSS syntax for Sublime Text
CSS
24
star
38

MouseEventListener

Adds on_pre_click and on_post_click callbacks to Sublime Text's plugin API.
JavaScript
24
star
39

Mojolicious

Mojolicious package for the Perl Web Dev Framework for Sublime Text 2
JavaScript
22
star
40

Modelines

Vim-like modelines for Sublime Text.
Python
21
star
41

NaturalDocs

NaturalDocs package for SublimeText 2
JavaScript
21
star
42

ExtractSublimePackage

Extract .sublime-package files to the Sublime Text Packages folder.
Python
20
star
43

RevertFontSize

Sublime Text plugin to quickly revert to a preferred font size
Python
20
star
44

LegacyTheme

Sublime Text 2's default theme with retina graphics
19
star
45

YamlPipelines

Sublime Syntax Definitions for YAML CI/CD pipelines like GitHub Actions, AzureDevops, Kong API Gateway, Gitlab CICD, Bitbucket, Drone CI etc.
Python
18
star
46

KnowledgeBase

Sublime Text Knowledge Base
Python
18
star
47

ScrollOffset

Python
18
star
48

UberSelection

Commands to extend the functionality of Sublime Text's multiselection.
Python
17
star
49

PythonOpenModule

Open python modules on sys.path and open folders in window
Python
16
star
50

PowershellUtils

Run powershell commands from within Sublime Text.
Python
16
star
51

Rake

Sublime Text 2 plugin for Ruby Rake
Python
15
star
52

JumpTo

Sublime Text plugin to move (multiple) cursors
Python
13
star
53

SwitchWindow

A plugin to quickly switch between Sublime Text windows via Command Palette
Python
12
star
54

ScopeNamingGuidelines

Collection of documents for scope naming guidelines in Sublime Text syntax definitions
12
star
55

AutoSelect

Sticky Selection
Python
12
star
56

SublimeCMD

Simple command processor for Sublime Text.
Python
12
star
57

syntax-test-action

Github Action to run syntax tests
Shell
12
star
58

OpenDefaultApplication

Sublime Text plugin to open files in the system default application
Python
11
star
59

Terminal

Launch terminals from the current file or the root project folder
Python
11
star
60

Sublime-Snipt

Sublime Text 2 plugin that will sync with snipt.net
Python
10
star
61

sublimetext.github.io

GitHub Organization for Open-Source Sublime Text Package Development
9
star
62

AutoProjects

A Sublime Text plugin to open folders as projects
Python
9
star
63

PackageTesting

Minimal testing framework for Sublime Text packages. (beta)
Python
8
star
64

WslBuild

A Sublime Text package to create build systems running in WSL2
Python
7
star
65

Astro

Astro syntax for Sublime Text
Astro
7
star
66

TJ3-syntax-sublimetext2

Taskjuggler 3 syntax and code snippets for Sublime Text 2
7
star
67

Mustache

Mustache syntax and snippets for Sublime Text
Mustache
6
star
68

Less

Less syntax for Sublime Text
Less
6
star
69

LINQPad

Syntax highlighting and build system for LINQPad scripts
5
star
70

AlpineJS

AlpineJS syntax for Sublime Text
PHP
4
star
71

Ceedling

Sublime Text plugin for Ceedling C unit testing framework
Python
4
star
72

Gaelyk

Gaelyk Sublime Text Package
3
star
73

GoToEndOfLineOrScope

Sublime Text plugin to bind a key (for example the end key) to move/extend the cursor/selection(s) to the end of the line, or to before the specified scope (i.e. a comment) at the end of the line
Python
3
star
74

RichTextFormat

Syntax definition for RTF files in Sublime Text 3
2
star
75

wbond-packages

Packages created, and (mostly) managed by Will Bond
1
star
76

OpenFileInCurrentFolder

Allows opening of files in the same folder as the active view
Python
1
star