insertSeqInserts or changes integers, Ascii chars, hex numbers, month names, dates or any javascript expressions in any text file. It is very helpful if you need to insert sequences or want to change some selected numbers/chars based on a javascript expression. This extension is based on the wonderful sublimetext extension from James Books (https://github.com/jbrooksuk/InsertNums). I used this extension intensively in the past within sublime text and I could not find such a flexible extension for VSCode. I rewrote this Python extension in JavaScript and extended it further. New in 0.10.0I implemented an easy way to insert date sequences. The start date has to be in the format [-[-]] (e.g. 2024-4-25 for 25th April 2024). Month and day are optional. Instead of numbers as step, you can decide if you want to add days, weeks, months or years. The format is [:integer]. If you want to add 2 days, you have to type ":d2". If you want to subtract 3 days, use "d-3". The first char has to be the unit (first letter of day, week, month or year). You can combine date sequences also with frequency and repetitions, but at the moment not with expressions or stop-expressions! Usage:The extension implements the command "insertSeq" and has a default key binding of The easiest usage is to insert a sequence of integers, starting with "1" when selecting multiple cursors: Select multi-cursors
Press
But the standard behavior can be changed anytime, as a pop-up window shows up after pressing If you want to start with the integer 10 instead of 1, you can do:
If you add a second number in the pop-up windows after a colon ( : ), you define the steps between the integers. To insert only every 5th integer, starting from 5, you type:
You can format the values before including them with ~{FORMAT} (Definition see below),
e.g. an input "
The d at the end stands for "decimal" output. If you need the numbers as hex, replace the d with an x. If you need the output as octal, put an o at the end and binary numbers can be inserted with a b at the end. Sometimes, you might need to start the sequence again after a fixed number of repetitions. (this feature is new and not included in the original sublimetext extension!)
An example would be if you want to include the numbers 1, 2, and 3 only, and after the 3, it should start from 1 again.
This can be done with the optional #{REPEATS}.
Typing
Another need I often have is to repeat the current char/number a few times before increasing the value. (this feature is new and not included in the original sublimetext extension!)
An example would be, if you want to include the numbers 1 three times, then 2 three times, and after this the number 3 three times (so 9 insertions in total).
This can be done with the optional *{FREQUENCY}.
Typing
Another possible need is to add the numbers 1 three times, 5 three times, and so on. Again, if you type It is also possible to have a stop criterion with the option @{STOPEXPRESSION}. STOPEXPRESSION can be any regular javascript but has the advantage, that some special chars can be used (details in the SYNTAX chapter below). Example: no multi-selection at all Start (only current cursor):
After typing
You can combine all of these options in one command.
With one cursor selected and the following command
The order of the input is also important. By default, the extension inserts the sequence in the order of the click order. Example: first click in line 7, then line 2, and third line 4. After the command
If you want to insert the number from the top down (independent of your click order), you can add the
You can set both behaviors as default with a config-switch It's also possible to reverse the input if you add an
And in combination with the
A special sequence of integers is a random sequence. Insertnums can do this easily with the option r{UNTIL} option. UNTIL is either an integer or a plus-char, followed by an integer. Without a plus-char the integer determines the maximal value in the random range. If a plus-char is used, the UNTIL value will be added to the start value (details syntax see below). You want to include 5 random numbers between 15 and 25 (including both). Type the following: Example (5 multi-lines are selected):
Each time you run this command new random numbers will be created. Since version 0.9 you can also insert month names (January, February, etc.) or numbers. To do this, you put a semi-colon in front of it and start with a known month name (e.g. oct for October) or an integer from 1 to 12. The Example with a name
Example with an integer
If you want to change the language, you can provide a valid ISO language within brackets after the month (e.g.
Another sequence are dates (not only months names). To insert dates, you can start the expression with %. As step-counter you can decided if _d_ays, _w_eeks, _m_onths or _y_ears should be added. As example, you want to insert days, starting 25th April 2024, increasing 2 weeks for each step, and output the date in the format , you can insert
The same result, as with the month names input can be achieved with this date sequence insertion:
And there is an even more complex feature called "expressions" you can use. Within such an expression, you can use some (internal) "variables". (see Syntax section) An example could be to insert numbers depending on the previous selection (double the last value). You can type
And because one "variable" within expressions is the Example: you select a list of numbers and want to add 50 to each number individually. Start (all 5 numbers are selected, | shows cursors):
After typing
But not only numbers can be included with this extension. The extension is flexible and can handle Ascii chars, so same selection as above but with
or if you want to format the alpha chars left side:
And "finally" you can use even more complex expressions to insert numbers, floats, strings, or boolean. An example would be: 5 numbers are selected (| shows cursors):
With the expression:
Configuration:Since version 0.9 you can configure the behavior of this extension with configuration variables:
History:The history is stored independently of the currently opened workspace in globalStorage of VSCode. History commandWith the command 'insertseq.showHistory' (default keyboard shortcut is CTRL+ALT+,) you can see the previously typed commands. Select one of them to run this command directly a second time. Two config items can be used:
If you don't find a fitting command in the history, you can choose "new item" and after RETURN you are back in the normal command and can type your new command in the input box. Bash-like historyThere is a bash-like history for the 'normal' command (input box).
You can even add some additional commands to this history, but it is not possible to edit the history commands. Example: if you have run the previous command New commands (including edited commands) will be saved in the history as a new entry. The number of commands in the bash-like history is not limited, but history will be cleared if the extension or VSCode is reloaded. Syntax details:Syntax for numbers:
with
Formatting can be done with the following options:
For more details about the formatting possibilities see the d3-formatting documentation or the Python mini-language documentation. Syntax for alpha:
with
Formatting can be done with the following options:
Syntax for dates:
with
Syntax for month names:
with
Formatting of month output can be done with the following options:
Syntax for expressions:
with
Be aware: You can use the stop expression in expressions, but in contrast to numbers, the stop expression cannot extend the current selection (just stop at last selection). If the stop expression is shorter than the selection, the rest will not be changed. If you want to delete the rest, you have to provide an empty string as return code instead of true for the expression. The "cast" information for expressions defines the output:
The following special chars can be used and will be replaced by some values:
Additional informationFor more examples and information, please look at the original extension here. Release NotesAll release notes are in the Changelog file Contributors 🙏A big thanks to the people that have contributed to improve this project:
Special thanks!This project would not be possible without the original Python code insertnums from James Brooks . I also used d3-format from the d3 group. Thanks a lot! Volker Enjoy!
|