Saturday, December 5, 2020

Re: the :sort command does not appear to give expected result

On Thu, Nov 05, 2020 at 05:27:22PM EST, Chris Jones wrote:

> So I have two problems:
>
> 1. sort the output by key value (couldn't think of a simple way
> to do this off the batน...
>
> 2. until the issue I described earlier in this thread is addressed
> I need to invoke gnu/coreutils' sort utility...
>
> The solution to problem #1 should be pretty straightforward.
>
> As to the second problem I need to pass my dictionary's entries to
> gnu/sort in a way that somehow will return them sorted alphabetically.
>
> Is this feasible using an external sort program?
>
> Thanks,
>
> CJ
>
> น In python:
>
> | for k, v in sorted(dict.items()):
> | print(k, v)

As it turns out the above is incorrect: python does not do it correctly
either... at least if you use its native sort() method.

It turns out that one possibility is to use IBM's 'ICU' library: on
debian I only had to install the pyICU bindings via python's pip/pip3
and this appears to intall the correct version of the library...

Here's a vim wrapper to work around this difficulty:

| function! Lsort(list, locale)
| py3 << EOP
| import vim, icu
| list = vim.eval('a:list')
| locale = vim.eval('a:locale')
| collator = icu.Collator.createInstance(icu.Locale(locale))
| slist = sorted(list, key=collator.getSortKey)
| # pass back the sorted list to vim
| vim.command("let lst = %s"% slist)
| EOP
| return lst
| endfunc

e.g.

| :let sorted_list = Lsort(unsorted_list, 'fr_FR.UTF-8')

Should also work with other western languages or fancy English words
with diacritics (untested).

As to GNU/sort I have not been able to figure out how to invoke it from
a vim wrapper function.

BTW... How can I keep an eye on if/when/how this issue will be addressed
natively in vim?

Thanks,

CJ

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201206003339.GD5952%40turki.local.

No comments: