String Values ​​Sublime Text 2

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 start increasing identifiers from 0 instead of 1. How can I do this with Sublime Text 2? I installed the Text Pastry plugin, but I'm not sure how to select the identifiers in the text so that I can replace these values.

+8
source share
3 answers

Having solved it, follow these steps:

  • Find and replace for regex "ID" : "\d+" and replace it with a line that, as I know, does not exist anywhere in the file (I replaced it with "ID" : "xyz"
  • Take some pictures on "ID" : "xyz"
  • Using the Text Pastry plugin "Number Sequence (\ i)" for multiple selection
+24
source

With the new text pasting function in the Text Pastry plugin, this is even one step less:

  1. Find all "ID": "\d+" (with regex search enabled)
  2. At the Text Pastry prompt, type as "ID": "0"
+4
source

You can use the increment of selection . Just press Ctrl + Alt + I to select multiple numbers.

First you need packet control . All this should not take more than 30 seconds to install.

Steps:

  1. Install the management pack .
    • Open the command palette: Ctrl + Shift + P (Windows / Unix) / Command + Shift + P (Mac).
    • Enter Install Package Control and click to install.
  2. Install the increment selection package.
    • Reopen the command palette.
    • Enter Package Control: Install Package , click on it and wait a while.
    • Type Increment Selection and click on it to set.
  3. Select multiple numbers and press Ctrl + Alt + I (Windows / Unix) / Command + Control + I (Mac).

Result:

invert-selection.gif


Other examples

The increment of choice can also add prefixes to numbers with leading zeros, letters of increment, increment by step, generate line numbers and much 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| [#] line -> 1| line [#] line -> 2| line [#] line -> 3| line [#] line -> 4| line [#] line -> 5| line 

Hint: [] stands for selection, | denotes a carriage.

0
source

All Articles