Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 increment numbers

I have a JSON file that looks like this:

    "Algeriet" :
    [
        {
            "name" : "Nyårsdagen",
            "date" : "2013-01-01",
            "ID" : "1"
        },
        {
            "name" : "Mawlid En Nabaoui Echarif",
            "date" : "2013-01-24",
            "ID" : "2"
        },
        {
            "name" : "Första maj",
            "date" : "2013-05-01",
            "ID" : "3"
        },
       ...
     ]

Now I would like to begin incrementing the IDs from 0 instead of 1. How can I do this with Sublime Text 2? I have installed the Text Pastry plugin but I'm not sure how to select the IDs in the text so that I can replace these values.

like image 557
Peter Warbo Avatar asked Mar 04 '13 10:03

Peter Warbo


People also ask

How do I use multiple cursors in Sublime Text 3?

While you can place multiple text cursors in Sublime Text with Cmd–Click (Mac) or Ctrl–Click (Windows), here's another technique that comes in handy. Hold Ctrl–Shift (Mac) or Ctrl–Alt (Windows) and hit Up or Down Arrow to place an additional text cursor above or below the current cursor.

How do you select multiple lines in Sublime Text?

To select multiple regions using the keyboard, select a block of text, then press Ctrl+Shift+L to split it into one selection per line.


1 Answers

Solved it by doing these steps:

  1. Do a find and replace for regex "ID" : "\d+" and replacing it with a string which I know does not exist anywhere in the file (I replaced it with "ID" : "xyz"
  2. Make a multiple selection on "ID" : "xyz"
  3. Using the Text Pastry plugin "Number Sequence (\i)" on the multiple selection
like image 174
Peter Warbo Avatar answered Sep 20 '22 01:09

Peter Warbo