On Tue, Jun 24, 2014 at 8:06 PM, Christian Brabandt <[email protected]> wrote:
> On Di, 24 Jun 2014, Axel Bender wrote:
>
>> Does anyone know a UTF-8-aware (respecting $LC_ALL and/or $LANGUAGE) sort
>> tool for Windows (GNUWin32's doesn't work), preferably a working GNU sort
>> that does the job? [OFF-TOPIC]
>
> Cygwin, Msys, Interix? Not sure, but not sure, which one does support
> UTF-8. I can't believe GNUWin32 doesn't support UTF-8.
>
>> It would be a nice idea [NO LONGER OFF-TOPIC] to add the possibility to add
>> sort columns (like in GNU's --key=<field>.<char>) to vim's :sort command.
>> Doing so would the first problem above obsolete...
>
> It should be possible, to Script something using viml.
How about something like that:
function! s:Compare(l1, l2)
for [index, reverse] in s:keys
let k1 = get(a:l1[1], index, '')
let k2 = get(a:l2[1], index, '')
if k1 != k2
return reverse * (k1 < k2 ? -1 : +1)
endif
endfor
return 0
endfunction
function! Sort(...) range
if 0 == a:0
exe a:firstline.','.a:lastline.'sort'
return
endif
let s:keys = []
let delim = '\s\+'
for a in a:000
if a =~ '^-t.'
let delim = a[2:]
elseif a =~ '^-k\d\+r\?$'
let reverse = a =~ 'r$'
let index = (reverse ? a[2:-2] : a[2:]) - 1
if index < 0
echoerr 'invalid key index: '.a
return
endif
call add(s:keys, [index, reverse ? -1 : 1])
else
echoerr 'invalid argument: '.a
return
endif
endfor
let lines = []
for l in getline(a:firstline, a:lastline)
call add(lines, [l, split(l, delim)])
endfor
call sort(lines, 's:Compare')
call map(lines, 'v:val[0]')
call append(a:lastline, lines)
silent exe a:firstline.','.a:lastline.'delete'
endfunction
Cheers,
--
A: Because it destroys the flow of conversation.
Q: Why is top posting dumb?
--
--
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/d/optout.