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

vim7: natural sort()?

Expand Messages
  • Mikolaj Machowski
    Hello, 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 ? m. -- LaTeX + Vim =
    Message 1 of 2 , May 14, 2005
    • 0 Attachment
      Hello,

      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
      ?

      m.

      --
      LaTeX + Vim = http://vim-latex.sourceforge.net/
      Vim-list(s) Users Map: (last change 12 Feb)
      http://skawina.eu.org/mikolaj/vimlist
      CLEWN - http://clewn.sf.net
    • 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 2 of 2 , May 15, 2005
      • 0 Attachment
        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.