Loading ...
Sorry, an error occurred while loading the content.
 

Re: vim7: natural sort()?

Expand Messages
  • Bram Moolenaar
    ... You can do it with the function argument: func MyCompare(i1, i2) return (a:i1 + 0) - (a:i2 + 0) endfunc let sortedlist = sort(mylist, MyCompare ) --
    Message 1 of 2 , May 15, 2005
      Mikolaj Machowski wrote:

      > Are any plans or tricks to make sort() to return naturally sorted numbers:
      > 1, 2, 3, 11, 22, 33
      >
      > and not
      > 1, 11, 2, 22, 3, 33
      > ?

      You can do it with the function argument:

      func MyCompare(i1, i2)
      return (a:i1 + 0) - (a:i2 + 0)
      endfunc
      let sortedlist = sort(mylist, "MyCompare")


      --
      ARTHUR: Shut up! Will you shut up!
      DENNIS: Ah, now we see the violence inherent in the system.
      ARTHUR: Shut up!
      DENNIS: Oh! Come and see the violence inherent in the system!
      HELP! HELP! I'm being repressed!
      The Quest for the Holy Grail (Monty Python)

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
      \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
    Your message has been successfully submitted and would be delivered to recipients shortly.