Insert sequential Line Numbers

Insert sequential Line Numbers

2
NewbieNewbie
2

    Aug 07, 2011#1

    Search for a script to insert sequential line numbers at the beginning of each line starting with 1. Line numbers to be followed by a dot, then space and content.
    Example:
    FROM
    Line 1
    Line 2
    Line 3

    TO
    1. Line 1
    2. Line 2
    3. Line 3

    Thank You,
    Robert

    6,686585
    Grand MasterGrand Master
    6,686585

      Aug 07, 2011#2

      I would do that simply with
      • Column - Column Mode to turn column editing mode on,
      • Column - Insert/Fill Columns to insert ". ",
      • Column - Insert Number to insert the numbers,
      • Column - Column Mode to turn column editing mode off
      • and perhaps additionally a simple tagged regular expression to move the spaces right the inserted numbers to left.
      Those commands can be either executed on entire file or just some lines selected in column mode.

      But you want a script, so here is a script executing the commands as listed above:

      Code: Select all

      if (UltraEdit.document.length > 0)
      {
         UltraEdit.insertMode();
         UltraEdit.activeDocument.top();
      
         if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
         else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
         UltraEdit.activeDocument.columnInsert(". ");
         UltraEdit.activeDocument.columnInsertNum(1,1,false,false);
         if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
         else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      
         // Move the inserted spaces right the inserted numbers to left.
         UltraEdit.ueReOn();
         UltraEdit.activeDocument.findReplace.mode=0;
         UltraEdit.activeDocument.findReplace.matchCase=false;
         UltraEdit.activeDocument.findReplace.matchWord=false;
         UltraEdit.activeDocument.findReplace.regExp=true;
         UltraEdit.activeDocument.findReplace.searchDown=true;
         UltraEdit.activeDocument.findReplace.preserveCase=false;
         UltraEdit.activeDocument.findReplace.replaceAll=true;
         UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
         UltraEdit.activeDocument.findReplace.replace("%^([0-9]+^)^( +^)","^2^1");
      }

      2
      NewbieNewbie
      2

        Aug 08, 2011#3

        This is the script I have been loking for.
        Appreciate your help,
        Robert