Skip to main content
Module

x/ddc_vim/deps.ts>fn.sort

Dark deno-powered completion framework for neovim/Vim8
Go to Latest
function fn.sort
import { fn } from "https://deno.land/x/ddc_vim@v2.3.0/deps.ts";
const { sort } = fn;

Sort the items in {list} in-place. Returns {list}. If you want a list to remain unmodified make a copy first: :let sortedlist = sort(copy(mylist)) When {func} is omitted, is empty or zero, then sort() uses the string representation of each item to sort on. Numbers sort after Strings, |Lists| after Numbers. For sorting text in the current buffer use |:sort|. When {func} is given and it is '1' or 'i' then case is ignored. When {func} is given and it is 'l' then the current collation locale is used for ordering. Implementation details: strcoll() is used to compare strings. See |:language| check or set the collation locale. |v:collate| can also be used to check the current locale. Sorting using the locale typically ignores case. Example: " ö is sorted similarly to o with English locale. :language collate en_US.UTF8 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') ['n', 'o', 'O', 'ö', 'p', 'z'] ~ " ö is sorted after z with Swedish locale. :language collate sv_SE.UTF8 :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') ['n', 'o', 'O', 'p', 'z', 'ö'] ~ This does not work properly on Mac. When {func} is given and it is 'n' then all items will be sorted numerical (Implementation detail: this uses the strtod() function to parse numbers, Strings, Lists, Dicts and Funcrefs will be considered as being 0). When {func} is given and it is 'N' then all items will be sorted numerical. This is like 'n' but a string containing digits will be used as the number they represent. When {func} is given and it is 'f' then all items will be sorted numerical. All values must be a Number or a Float. When {func} is a |Funcref| or a function name, this function is called to compare items. The function is invoked with two items as argument and must return zero if they are equal, 1 or bigger if the first one sorts after the second one, -1 or smaller if the first one sorts before the second one. {dict} is for functions with the "dict" attribute. It will be used to set the local variable "self". |Dictionary-function| The sort is stable, items which compare equal (as number or as string) will keep their relative position. E.g., when sorting on numbers, text strings will sort next to each other, in the same order as they were originally. Can also be used as a |method|: mylist->sort() Also see |uniq()|. Example: func MyCompare(i1, i2) return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1 endfunc let sortedlist = sort(mylist, "MyCompare") A shorter compare version for this specific simple case, which ignores overflow: func MyCompare(i1, i2) return a:i1 - a:i2 endfunc

Parameters

denops: Denops
list: unknown
optional
func: unknown
optional
dict: unknown

Returns

Promise<unknown>