On Thursday, June 26, 2014 8:06:34 AM UTC-5, Jun T. wrote: > 2014/06/26 01:07, Ben Fritz <fritzophre...@gmail.com> wrote: > > > On Tuesday, June 24, 2014 10:39:28 AM UTC-5, Ben Fritz wrote: > >> > >> I thought your sort could be done in Vim with 2 passes, but unfortunately > >> it does not work: > >> > >> sort r /^\d\+/ > >> sort! /.*#/ > >> > > > > Bram, any chance that a way to guarantee a stable sort could be included, > > I guess the :sort command *is* stable (although the sort() function is not). > If you look into ex_cmds.c, end of the function sort_compare(), lines 340-341: > > if (result == 0) > return (int)(l1.lnum - l2.lnum); > > this indicates that if the two lines are "equal" by the current comparison, > then just compare by the line number; this should result in the stable sort.
Thanks for the analysis! I guess this line in ":help :sort" is not correct, then? > The details about sorting depend on the library function used. There > is no guarantee that sorting is "stable" or obeys the current locale. > You will have to try it out. > I guess the effect of the '!' flag is just to reverse the order of the > final output. > :sort! r /\a\a/ > is equivalent to > :sort r /\a\a/ > and reverse the order of whole output (reading the output from bottom > to top). This would of course then reverse the order of the already sorted lines, meaning you can chain :sort commands together, but ONLY if none of them are in reverse order. Could this be fixed, by using (l2.lnum - l1.lnum) rather than (l1.lnum - l2.lnum) if lines are equal, when using reverse sort? -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.