Incremental renaming any text editor

Daniel Lowes
Daniel Lowes used Ask the Experts™
on
Using you favourite text editor (I use PHP storm and VSCODE)
Is there a feature to incremental renaming  while multi selecting here is pseudo desired output.
var1
var2
var3
var4
ar5
Note:there will be code in between which does not need changing imagine it's a JSON file and all I wan to do is change the id number incrementally.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
and all I wan to do is change the id number incrementally.

can you provide an example for clearer explanation?
Daniel LowesPHP Web Developer And Computer Tech

Author

Commented:
suppose we have this code and assume it has many variables:
<?php 
$var= "cat";
$var="horse";
$Var="animal";
?>

Open in new window



I want to easily edit the number to get this result
,I already know how to edit multiple lines at once,.
but with the same piece of text..
So assume I selected all the lines at once and with some magic shortcut I got this:
<?php 
$var1= "cat";
$var2="horse";
$Var3="animal";
?>

Open in new window

Ryan ChongSoftware Team Lead
Commented:
I can't find another tool to do such replacement but I would try this using an Excel maco:

Function SetTextWithRunningNumber(ByVal Content As String, ByVal FindText As String)
    Dim tmp As String, RunningNumber As Integer
    tmp = Content
    RunningNumber = 1
    Do While tmp <> ""
        If InStr(1, tmp, FindText, vbTextCompare) > 0 Then
            SetTextWithRunningNumber = SetTextWithRunningNumber & Left(tmp, InStr(1, tmp, FindText, vbTextCompare) - 1) & FindText & RunningNumber
            tmp = Mid(tmp, InStr(1, tmp, FindText, vbTextCompare) + Len(FindText))
            RunningNumber = RunningNumber + 1
        Else
            SetTextWithRunningNumber = SetTextWithRunningNumber & tmp
            Exit Do
        End If
    Loop
End Function

Open in new window


try like:

= SetTextWithRunningNumber(B2,"var")

Open in new window


once output is generated, copy and paste it to the editor you needed.
29129995.xlsm
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018
Commented:
You could use sublime text for this, follow these steps :

1. Open Sublime Text 3
2. Make sure you have Package Control installed (https://sublime.wbond.net/installation)
3. Press CTRL + SHIFT + P
4. Type Install onto the dialog window
5. Select “Package Control: Install Package” and press “Enter”
6. Search for and install “Increment Selection”
7. Select lines you want by keep pressing “ctrl” and select with “left mouse click”
8. Then press “ctrl” + “alt” + “i”
9. Boom, it will auto-increment each line 1,2,3,4 etc.

Tested solution.
Source : https://rricketts.com/add-auto-incrementing-number-selection-sublime-text-3/
Analyst Developer
Distinguished Expert 2018
Commented:
Here is the solution for PHPStorm :

1. First of all, make sure you can select multiple lines :

  • Go to setting.
  • Keymap.
  • Search for "Clone Caret Above" & "Clone Caret Below" then give them keymap you want to use.
  • Save changes.

2- Start Selecting :

  • Select the lines you want.
  • Then type '0' and you will have a bunch of zeros.
  • Press shift+left to select them all.
  • Then ctrl+shift+a and type 'Create Sequence'.
  • Chose it, AND YES, You have a series of digits.
Daniel LowesPHP Web Developer And Computer Tech

Author

Commented:
Thank you Ryan Chong for thinking outside of the box and using excel.
Thank you Zakaria Acharki for focusing on PHPstorm .
Zakaria Acharki note to myself and other experts out there;
We need to install the string manipulation plugin
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Commented:
You're welcome, glad to help Daniel, and thanks for adding the missing part in your comment.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial