Auto increment number for multiple lines in PhpStorm
Asked Answered
P

3

20

How to achieve auto increment for multiple selection in PhpStorm ie. If I have lines like this selected or taged with multiple cursors

my line das
my line asd
my line sda
my line poi
my line uio
my line kjy

And I want to have them automatically numbered like this

my line das 1
my line asd 2 
my line sda 3 
my line poi 4
my line uio 5
my line kjy 6

Is there any simple method to this with Emmet or any other plugin?

Preponderate answered 6/4, 2016 at 8:16 Comment(3)
youtrack.jetbrains.com/issue/IDEA-124616 ?Grasshopper
@Grasshopper Yup, this is totally what I mean, so I see that I have to use Sublime Text to do this with plugin Text Pastry.Ellinger
Some workaround, but works and can be used also for more complex edit - just use excel sheet with any increment formula that you want. Then copy column with values and paste with multiline editing in intellij :-)Univalence
V
33

Update: This feature is now available in the String Manipulation plugin v4.5

Old: It's far from ideal, but you can use the Duplicate and increment action from the String Manipulation plugin. It's quite easy to do and it does the job:

enter image description here

Add a shortcut to this action or execute it multiple time to increment a line containing a number.

So far no PhpStorm plugin allows to do exactly what to describe.

It may be the occasion to create one !

Vegetal answered 7/4, 2016 at 13:35 Comment(3)
Not really -- his lines have different text (check the word before the numbers).Grasshopper
start at the end of the first line. Ctrl, hold ctrl, press down until you reach the bottom, now you have a multiselect line. Then type '0' and you will have a bunch of zeros. Press shift+left to select them all, then ctrl+shift+a (commands) and type 'Create Sequence' and finally kaboom! You have a series of digits!Mauldon
In order to use the Create Sequence command you first need to go to Settings -> Plugins -> Browser Repositories -> Search: "String Manipulation" and install it. Then you will have access to the Create Sequence command using the Ctrl+Shift+A hotkey.Paronomasia
D
10
  1. String Manipulation is the name of the addon (as already mentioned by Xedecimal).

  2. Create sequence is the name of the action you want to use. (This does exactly what you want!)

Or use InputSequence another plugin for that purpose.

Dowry answered 28/10, 2019 at 19:13 Comment(0)
S
0

Not exactly what you want put I had to increment about 100 lines of code so I went to repl.it and spat this out, copied and pasted.

for(let i = 235; i < 340; i++){
  console.log(`case "board_1_${i}":
  return board_1_${i};`)
}
Sulfapyridine answered 24/7, 2020 at 14:51 Comment(1)
This works but is not effective. I do not recommend using workarounds for things an IDE should provide.Intercostal

© 2022 - 2024 — McMap. All rights reserved.