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. I think the problem is in the way the '!' flag is treated. Suppose we have the following lines: 02 bb 02 aa 01 bb 01 aa If I run :sort r /\a\a/ (or :sort /^.../) then I get the following 02 aa 01 aa 02 bb 01 bb This is as expected, and the sort is "stable". But if I run :sort! r /\a\a/ (or :sort! /^.../) then I get 01 bb 02 bb 01 aa 02 aa which may be not what you expect. 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). -- -- 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.