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?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Eryk Wróbel
  • 416
  • 1
  • 4
  • 11
  • https://youtrack.jetbrains.com/issue/IDEA-124616 ? – LazyOne Apr 06 '16 at 13:02
  • @LazyOne Yup, this is totally what I mean, so I see that I have to use Sublime Text to do this with plugin Text Pastry. – Eryk Wróbel Apr 06 '16 at 19:24
  • 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 :-) – Krystian Nov 09 '22 at 16:52

3 Answers3

32

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 !

Harijoe
  • 1,771
  • 1
  • 16
  • 27
  • Not really -- his lines have different text (check the word before the numbers). – LazyOne Apr 07 '16 at 17:23
  • 17
    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! – Xedecimal Aug 30 '16 at 19:55
  • 2
    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. – Chris Sprance May 04 '18 at 17:24
9

String Manipulation* is the name of the addon (as already mentioned by Xedecimal).

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

auipga
  • 300
  • 3
  • 10
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};`)
}
ShadyAmoeba
  • 527
  • 1
  • 4
  • 15
  • 1
    This works but is not effective. I do not recommend using workarounds for things an IDE should provide. – Pateta May 13 '21 at 18:04