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

now that there's sort(), why not :[range]sort [oattern]???

Expand Messages
  • Charles E. Campbell, Jr.
    Hello! The subject says most of it... I may be wrong (its late here at the moment); but it seems that if I want to sort lines in text I need to a) transform
    Message 1 of 6 , Apr 6, 2005
      Hello!

      The subject says most of it... I may be wrong (its late here at the
      moment); but it seems that if I want to sort
      lines in text I need to

      a) transform the lines into a list
      b) delete the lines
      c) sort the list
      d) put the (now sorted) list elements back into the text
      e) probably delete the list

      I'm sure I can come up with a :Sort command to do this, but shouldn't
      this operation be simply
      available as a built-in? Seems like it'd be useful for regular editing,
      not just script writing, esp
      for those platforms with difficulties in executing commands (cmd vs
      bash, for example).

      And then there could be special sort operations such as : sort lines
      based on a portion of them
      satisfying a regex (which would allow column-extents to be specified,
      BTW), sort only portions
      of lines (such as a column) based on regex-delineated portions.
      Visual-block selected sorts:

      :[range]sort [pattern]

      would do for all of this.

      Anyway, I was just pondering having netrw use the new built-in sort()
      instead of the current
      script-based sort (Piet Delport's insertion sort).

      If :[range]sort [pattern] is a Bad Idea, how about a function to
      generate a list based on a range of lines:

      let mylist= linelist(rowstart,rowstop)

      and a function to put a list back into the text. Apologies if this
      already exists.

      Regards,
      Chip Campbell
    • Mikolaj Machowski
      ... IMO :[range] sort is great idea :) ... let mylist = getlines(rowstart, rowstop) m. -- LaTeX + Vim = http://vim-latex.sourceforge.net/ Vim-list(s) Users
      Message 2 of 6 , Apr 7, 2005
        Dnia czwartek, 7 kwietnia 2005 08:13, Charles E. Campbell, Jr. napisał:
        > If :[range]sort [pattern] is a Bad Idea, how about a function to
        > generate a list based on a range of lines:

        IMO :[range] sort is great idea :)
        >
        > let mylist= linelist(rowstart,rowstop)
        >
        > and a function to put a list back into the text. Apologies if this
        > already exists.

        let mylist = getlines(rowstart, rowstop)

        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
      • A. J. Mechelynck
        ... ... oops ... getline(rowstart,rowstop) Best regards, Tony.
        Message 3 of 6 , Apr 7, 2005
          Mikolaj Machowski wrote:
          > Dnia czwartek, 7 kwietnia 2005 08:13, Charles E. Campbell, Jr. napisał:
          >
          >>If :[range]sort [pattern] is a Bad Idea, how about a function to
          >>generate a list based on a range of lines:
          >
          >
          > IMO :[range] sort is great idea :)
          >
          >> let mylist= linelist(rowstart,rowstop)
          >>
          >>and a function to put a list back into the text. Apologies if this
          >>already exists.
          >
          >
          > let mylist = getlines(rowstart, rowstop)
          >
          > m.
          >

          ... oops ... getline(rowstart,rowstop)

          Best regards,
          Tony.
        • Bram Moolenaar
          ... Except that setline() doesn t accept a List yet... ... It s possible. I thought it was in the todo list, but I can t find it. Main reason it wasn t
          Message 4 of 6 , Apr 7, 2005
            Charles Campbell wrote:

            > The subject says most of it... I may be wrong (its late here at the
            > moment); but it seems that if I want to sort
            > lines in text I need to
            >
            > a) transform the lines into a list
            > b) delete the lines
            > c) sort the list
            > d) put the (now sorted) list elements back into the text
            > e) probably delete the list

            Yes:

            :call setline(1, sort(getline(1, "$")))

            Except that setline() doesn't accept a List yet...

            > I'm sure I can come up with a :Sort command to do this, but shouldn't
            > this operation be simply available as a built-in? Seems like it'd be
            > useful for regular editing, not just script writing, esp for those
            > platforms with difficulties in executing commands (cmd vs
            > bash, for example).

            It's possible. I thought it was in the todo list, but I can't find it.
            Main reason it wasn't implemented yet is that we need to figure out what
            extra features should be supported. Such as sorting on a specified
            field, removing duplicate lines and that kind of thing.

            > And then there could be special sort operations such as : sort lines
            > based on a portion of them satisfying a regex (which would allow
            > column-extents to be specified, BTW), sort only portions of lines
            > (such as a column) based on regex-delineated portions.
            > Visual-block selected sorts:
            >
            > :[range]sort [pattern]
            >
            > would do for all of this.

            Possible, but it won't be fast. Many people will just want to sort on
            something like "the third field" with ":1,5sort 3". Typing a regexp for
            that is complicated.

            > If :[range]sort [pattern] is a Bad Idea, how about a function to
            > generate a list based on a range of lines:
            >
            > let mylist= linelist(rowstart,rowstop)
            >
            > and a function to put a list back into the text. Apologies if this
            > already exists.

            getline(start, end) already does the get part. setline(start, list)
            doesn't work yet.

            --
            From "know your smileys":
            :-H Is missing teeth

            /// 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 ///
          • Mikolaj Machowski
            ... OOPS :) m.
            Message 5 of 6 , Apr 7, 2005
              Dnia czwartek, 7 kwietnia 2005 10:59, A. J. Mechelynck napisał:
              > > let mylist = getlines(rowstart, rowstop)
              > ... oops ... getline(rowstart,rowstop)

              OOPS :)

              m.
            • Clint Harames
              Ok, I have to ask... I am a user that would benefit from sort functionality. But I fail to see why it needs to be built into vim since it is already built
              Message 6 of 6 , Apr 7, 2005
                Ok, I have to ask...
                I am a user that would benefit from sort functionality. But I fail to
                see why it needs to be built into vim since it is already built into
                both Windows and *nix. In fact, it works for ranges (already).
                I use it all the time, sometimes to sort an entire file (:%!sort -k
                <keys>)
                And sometimes to sort ranges, by either a visual selection or an
                explicit range (:'<,'> !sort -k <keys>).

                The caveat is that I have to use a slightly different syntax on Windows
                vs. *nix when I am telling the sort utility which column I want to sort
                on.

                Since there is already a pretty decent solution for sorting based on
                ranges (and columns within a range), I'd prefer to see development
                efforts focused on new features that I can't get easily by some other
                means.
                -Clint


                -----Original Message-----
                From: Bram@... [mailto:Bram@...]
                Sent: Thursday, April 07, 2005 2:41 AM
                To: Charles E. Campbell, Jr.
                Cc: vim-dev@...
                Subject: Re: now that there's sort(), why not :[range]sort [oattern]???


                Charles Campbell wrote:

                > The subject says most of it... I may be wrong (its late here at the
                > moment); but it seems that if I want to sort
                > lines in text I need to
                >
                > a) transform the lines into a list
                > b) delete the lines
                > c) sort the list
                > d) put the (now sorted) list elements back into the text
                > e) probably delete the list

                Yes:

                :call setline(1, sort(getline(1, "$")))

                Except that setline() doesn't accept a List yet...

                > I'm sure I can come up with a :Sort command to do this, but shouldn't
                > this operation be simply available as a built-in? Seems like it'd be
                > useful for regular editing, not just script writing, esp for those
                > platforms with difficulties in executing commands (cmd vs
                > bash, for example).

                It's possible. I thought it was in the todo list, but I can't find it.
                Main reason it wasn't implemented yet is that we need to figure out what
                extra features should be supported. Such as sorting on a specified
                field, removing duplicate lines and that kind of thing.

                > And then there could be special sort operations such as : sort lines
                > based on a portion of them satisfying a regex (which would allow
                > column-extents to be specified, BTW), sort only portions of lines
                > (such as a column) based on regex-delineated portions.
                > Visual-block selected sorts:
                >
                > :[range]sort [pattern]
                >
                > would do for all of this.

                Possible, but it won't be fast. Many people will just want to sort on
                something like "the third field" with ":1,5sort 3". Typing a regexp for
                that is complicated.

                > If :[range]sort [pattern] is a Bad Idea, how about a function to
                > generate a list based on a range of lines:
                >
                > let mylist= linelist(rowstart,rowstop)
                >
                > and a function to put a list back into the text. Apologies if this
                > already exists.

                getline(start, end) already does the get part. setline(start, list)
                doesn't work yet.

                --
                From "know your smileys":
                :-H Is missing teeth

                /// 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.