Sublime Forum

How I do incremental numbering of empty lines in one file?

#1

If somebody knows how to work with ReGex, please helpme.

I have a file with some thousands of empty lines and I need to ad to every empty line an incremental number. First empty line to have number 1, second empty line to have number2, etc.
The every empty line is repeated, so I have two empty lines, and I want to insert the number just to the second empty line.


some text

more text

even more text

to transform into yhis:

1
some text

2
more text

3
even more text

Unfortunately Regex is just to complicated and cant find any documentation regarding to this subject.

0 Likes

#2

Hi attanze,

The regular expression you should use is “\n\n\n” (without the quotes). Search for this with the find panel and make sure that the regular expressions option is selected. Now do a “find all” (from the find panel), which will create multiple selections. Use your arrow keys to re-position the multiple selections so the cursors are on the second empty line (right then left worked for me). Now you should have multiple selections, each one on the second of the empty lines (exactly where you want to insert the numbers).

Now you need to insert the incremental numbers into the selections, but you’ll need a plugin for that. Luckily there already is one available for you: http://www.sublimetext.com/forum/viewtopic.php?f=5&t=1604&start=0. It might be easier to setup the plugin first (before you do the selection above).

Hope that helps.

Cheers,
Josh

0 Likes

#3

By the way, there is tons of very helpful information about regular expressions available online, for example: http://www.regular-expressions.info/. Sublime Text uses normal regular expressions so you won’t find any specific documentation here.

0 Likes