Hi Charles! On Do, 14 Okt 2010, Charles Campbell wrote:
> Bee wrote: >> On Oct 13, 10:00 pm, Bee<[email protected]> wrote: >> >>> On Oct 13, 6:56 pm, Charles E Campbell Jr<[email protected]> >>> wrote: >>> >>>> Bee wrote: >>>> >>>>> sort bug? >>>>> >>> >>>>> vim 7.3.27 Linux >>>>> vim 7.3.21 Mac 10.4.11 >>>>> >>> >>>>> Select the lines between the rules (including the blank lines) and >>>>> sort: >>>>> '<,'>sort n >>>>> >>> >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> xxx yyy: 0 >>>>> xxx yyy: 1 >>>>> xxx yyy: 2 >>>>> xxx yyy: 3 >>>>> xxx yyy: 4 >>>>> >>> >>>>> xxx yyy: 5 >>>>> xxx yyy: 6 >>>>> xxx yyy: 7 >>>>> xxx yyy: 8 >>>>> xxx yyy: 9 >>>>> >>> >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> >>> >>>>> The result is: >>>>> >>> >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> xxx yyy: 0 >>>>> >>> >>>>> xxx yyy: 1 >>>>> xxx yyy: 2 >>>>> xxx yyy: 3 >>>>> xxx yyy: 4 >>>>> xxx yyy: 5 >>>>> xxx yyy: 6 >>>>> xxx yyy: 7 >>>>> xxx yyy: 8 >>>>> xxx yyy: 9 >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> >>> >>>>> I would expect this and it is what I get when using the shell: >>>>> '<,'>!sort -n >>>>> >>> >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> >>> >>>>> xxx yyy: 0 >>>>> xxx yyy: 1 >>>>> xxx yyy: 2 >>>>> xxx yyy: 3 >>>>> xxx yyy: 4 >>>>> xxx yyy: 5 >>>>> xxx yyy: 6 >>>>> xxx yyy: 7 >>>>> xxx yyy: 8 >>>>> xxx yyy: 9 >>>>> "--------1---------2---------3---------4---------5---------6---- >>>>> >>> >>>> I tried your example and was unable to duplicate the problem. Have you >>>> tried putting this in a file, say sort.test: >>>> vim -u NONE -N sort.test >>>> :%sort >>>> >>> >>>> I tried that, and I tried using V and selecting all the lines, and each >>>> time I got the "I would expect this..." result. >>>> >>> Thank you, I did not think to do "vim -u NONE -N" and... >>> I then get the expected result! >>> That means something in my vimrc is causing the sort problem. >>> I will remember to do that first next time. >>> >> Oops! >> I copied what you had done and that works, but that is not the case I >> was using. >> >> Try it selecting the lines and >> >> :'<,'>sort n >> >> Do not forget the "n" numeric sort option. >> >> With [n] sorting is done on the first decimal number >> in the line (after or inside a {pattern} match). >> One leading '-' is included in the number. >> >> > OK, now that I'm using sort n -- I can duplicate the behavior. Yes empty lines are considered as they would contain a zero. And in case another line has the same number, the original order would remain. In this case, the line with the 0 stays on top. (Really strange is the result, if you have an empty line, followed by a line containing a zero followed by an empty line.) Attached patch fixes that. regards, Christian -- 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
# HG changeset patch # Parent b8dbee14a3d8e29383c979b5bdb59ba1d0585ddf diff --git a/src/ex_cmds.c b/src/ex_cmds.c --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -491,7 +491,11 @@ s = skiptodigit(p); if (s > p && s[-1] == '-') --s; /* include preceding negative sign */ - vim_str2nr(s, NULL, NULL, sort_oct, sort_hex, + if (*s == NUL) + /* empty lines should be first */ + nrs[lnum - eap->line1].start_col_nr = SHRT_MIN; + else + vim_str2nr(s, NULL, NULL, sort_oct, sort_hex, &nrs[lnum - eap->line1].start_col_nr, NULL); (*s2) = c; }
