nh_wzg wrote: > I have test it with commands below correctly: > :Sort " sort by the current column > :Sort 3 " sort by column 3 > :Sort! 3 " same, reverse order > :5,12Sort! 3 " same, but sort only lines 5 to 12 inclusive
That's the good news - thanks. > I have test it with command is wrong: > :Sort 1 n " numeric sort by column 1 Ugh. OK so I've had a closer look at what Vim is actually doing. My superficial testing made me hope that ':sort n' was sorting floating point ok. But it was self-delusion. It turns out that ':sort n' does the following: - Skip any leading nondigits. - If last nondigit was '-' take final number as negative. - Convert number to a long integer (ignoring overflow). - Number is a string of digits ending with any nondigit. - Sort using the signed long integers. So 'xxx12.65' is regarded as exactly 12, and '-0.34' is exactly 0, and (on a 32-bit machine) 2147483660 is a large negative number (overflow). I'll contemplate how this mess might be improved. Al's code (in the talk page at http://vim.wikia.com/wiki/Talk:Working_with_CSV_files#Sorting_by_column) attempts to detect the type of string, and convert it to an appropriate value, while handling floats. It would be a real shame to tack on our own compare function, particularly one which converts each string each time, but it might have to be done. The correct way to handle this would be to extend Vim to: - Make ':sort n' handle floats (probably not). -or- - Make ':sort f' (say) handle floats. Of course quite a lot would have to happen before such a patch to Vim saw daylight. John --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---