Am 31.05.2013 15:14, schrieb mattn:
:echo sort([{"foo":3},{"foo":2},{"foo":4}], "v:lhs.foo - v:rhs.foo")
What I use:
" (copy) sort {list} by comparing strings obtained with {selexpr}
func! MapSort(list, selexpr)
" {list} list to sort
" {selexpr} (string) expression to get a string from list item {v:val}
let strings = map(copy(a:list), a:selexpr)
call map(strings, 'v:val. " ". v:key')
call sort(strings)
call map(strings, '0 + matchstr(v:val, ''\d\+$'')')
return map(strings, 'a:list[v:val]')
endfunc
let s:alpha = 'ZABCDEFGHIJKLMNOPQRSTUVWXY'
" turns a number into a string for sorting purpose; returns the string
func! NumStr(number)
return s:alpha[strlen(a:number)]. a:number
endfunc
---------------
:echo MapSort([{"foo":3},{"foo":2},{"foo":4}], "NumStr(v:val.foo)")
[{'foo': 2}, {'foo': 3}, {'foo': 4}]
--
Andy
--
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.