How to insert a column of increasing numbers in Sublime Text 2?
Sublimetext2Sublimetext2 Problem Overview
text
text
text
text
after the editing, those text becomes to
1 text
2 text
3 text
4 text
It's easy in Notepad ++ with the Column Editor, but I don't know how to do the same in Sublime Text 2.
Sublimetext2 Solutions
Solution 1 - Sublimetext2
The Text Pastry plugin does the job very well. It offers the Insert Numbers Syntax.
Select multiple lines with CMD+SHIFT+L (Sublime default):
text|
text|
text|
text|
Move the cursor where you want it:
| text
| text
| text
| text
And insert numbers with Text Pastry by hitting CMD+ALT+N and entering 1 space 1 space 0:
1| text
2| text
3| text
4| text
Where 1 space 1 space 0 stands for:
- Integer to start with 1
- Increment by 1
- Padd leading zeros 0
Replace CMD with CTRL on Windows or Linux machines.
Solution 2 - Sublimetext2
copy of this post https://stackoverflow.com/a/64083371/5902698
You want to have a number at each row that you selected, but not the same. For exemple, you select 5 cursors and you want to write 1 2 3 4 5.
select your 5 cursors (maybe you can use the shortcut ctrl + shift + L)
ctrl + shift + P and select arithmetic
Because you have 5 cursors, it propose 1 2 3 4 5
If you want you can change your step of iteration
Solution 3 - Sublimetext2
For this particular case you can use Increment Selection package. Just press Ctrl+Alt+I (Command+Control+I) while having multiple cursors at the beginning of each line. In addition to melinath answer, here's an example of how to do it:
You will need Package Control first. It shouldn't take more than 30 seconds to install both things.
Steps:
- Install Package Control.
- Open Command Palette: Ctrl+Shift+P (Mac: Command+Shift+P).
- Type
Install Package Control
and click to install.
- Install Increment Selection package.
- Open Command Palette again.
- Type
Package Control: Install Package
, click on it and wait a short period. - Type
Increment Selection
and click on it to install.
- Add line numbers to the beginning of each line.
- Select all lines with Ctrl+A (Mac: Command+A)
- Change selection to multiple lines with Ctrl+Shift+L (Mac: Command+Shift+L)
- Go to the start of each line by pressing Home (Mac: Command+←)
- Use Increment Selection with Ctrl+Alt+I (Mac: Command+Control+I)
Result:
Other examples for Increment Selection
Increment Selection can also replace numbers, prefix numbers with leading zeroes, increment letters, increment by a step and more.
[1] text [1] text [1] -> 1| text 2| text 3|
[a] text [a] text [a] -> a| text b| text c|
[01] text [01] text [01] -> 01| text 02| text 03|
[05,3] text [05,3] text [05,3] -> 05| text 08| text 11|
[5,-1] text [5,-1] text [5,-1] -> 5| text 4| text 3|
Hint: []
stands for a selection, |
stands for a caret.
Featured similar plugins
-
Selection Evaluator: Evaluate selected mathematical expression with Ctrl+Shift+M (Mac: Command+Shift+M).
Solution 4 - Sublimetext2
The IncrementSelection plugin enables this behavior. If you have Package Control installed, you can just search for and install it. Easy peasy!
Solution 5 - Sublimetext2
Use Emmet package try this :
{$ text${newline}}*4
Solution 6 - Sublimetext2
My simple workaround (up until now when I found this thread) was to go to my spreadsheet editor generate the sequence there, copy, back to subl, expand the cursor over however many lines and paste.
This approach can be applied in any text editor that allows you to expand (clone) the cursor.
Solution 7 - Sublimetext2
You can use the plugin ConyEdit to do this, use its command line cc.abl '#1 '
to append before lines with the contents that you want.
Solution 8 - Sublimetext2
@Nicoolasens This answer is great! Just adding one detail: On macOS you can follow these steps to put a curser at the end of each line:
- Use command+A to choose all lines;
- Use command+shift+L to put a curser after each line.