Thanks for the coding suggestion – I am looking at the ST API Reference page to get a handle on it.
Also have a look on Text Pastry
Textpad provides by far the easiest way to add line numbers at the start of lines – simply find “^” and replace with "\i. " (a regular expression without the quotes). Then create a macro to apply this expression on selected lines. Simple and compact – one click to run.
I like text pastry better, although for just adding the line numbers, there is an extra step of course. Time wise, not much difference?
Select the area, split into lines, command-P and add numbers x to y
My philosophy of user interfaces is that every step that can be eliminated absolutely must be eliminated. It’s all about the Darwinian survival of the fittest in the competition among tools for ease of use. Every reduction of friction provides an advantage.
The Textpad approach is slicker and more minimal, in my opinion.
But Text Pastry is a great package for numerous operations.
I personally use Minipy, which evaluates python and can also used for this issue.
Just select the text, split the selection (
ctrl+shift+l), insert and select
$ at the start of the line, and evaluate python (
ctrl+shift+x) to get increasing numbers.
This can also recorded as a macro to have it in one click.
When I recorded this as a macro, Minipy made the assumption that all future selections would include the same number of lines as the current selection.
Start record the macro after selecting the text and before pressing
ctrl+shift+l works for me:
You’re right – that sequence works.
What are some other cool Minipy tip and tricks you would recommend?
Have you tried Copy With Line Numbers Reloaded?
You pretty much get the result you’re looking for with one step, and then you can paste the output straight into its final destination.
It also works with multiple selections and has a few useful options @
BTW, what is your intended output for this?
ExportHTML is awesome for extracting your code + line numbers + color scheme to html.
The package just evaluates python code using
eval. You can do a lot of stuff, if you know python (there are similar packages for other languages as well). I mostly use it
- for stuff with increasing numbers as in your example
- for inline calculations without using an external tool, e.g. calculate
992 + 345or binary/hex strings
- for creating repeating characters, e.g. create 37 a’s by writing
However you can even open the current file in firefox:
exec('import subprocess; subprocess.Popen(["firefox", view.file_name()])')
By the way, how did you capture that graphic above? Nice.
I used ScreenToGif for that.
Check out ActivePresenter. I used ScreenToGIF as my primary for a while, but now use AP since it has a much easier to use timeline ( perfect for removing unnecessary frames & sequencing annotations ) & an awesome set of annotation features ( customizable shape presets, fade in/out, shadows, etc. ). It doesn’t export directly to GIF, so I still run the exported video through ScreenToGIF.
Thanks for the pointer.
How do I install this copy with line numbers reloaded?
yes, that was a great start. Thanks for posting this! The offset didn’t work properly once the count got higher than 10.
This works for me…
import sublime import sublime_plugin class LineNumbersAddCommand(sublime_plugin.TextCommand): def run(self, edit, suffix=""): selections = self.view.sel() totalOffset = 0 for selection in selections: lines = self.view.split_by_newlines(selection) for i, line in enumerate(lines): line_number_string = str(i+1)+suffix offset = len(line_number_string) # print offset, "just" self.view.insert(edit, line.begin() + totalOffset, line_number_string) totalOffset += offset