All pastes #98531 Raw Edit

Someone

public text v1 · immutable
#98531 ·published 2006-07-24 16:13 UTC
rendered paste body
func! StrICmp(str1, str2)
    if (a:str1 <? a:str2)
       return -1
    elseif (a:str1 >? a:str2)
       return 1
    else
       return 0
    endif
endfunction

let s:cmpref = function( 'StrICmp' )

fun! PySort()

    let ai_revert = 0
    let tw_revert = 0
    let ignorecase_revert = 0
    if ! &autoindent
        let ai_revert = 1
        set autoindent
    endif
    if &textwidth == 0
        let tw_revert = 1
        set textwidth=90
    endif

    normal! gv"ay
    let text = matchstr(@a, '\s*\zs.*\ze\s*')
    let list = split(text, '\_s*,\_s*')
    call sort(list, s:cmpref)
    let @a = join(list, ', ')
    normal! gv"ap

        normal! >>
        normal! >>
        normal! gqq

    if ai_revert
        set noautoindent
    endif
    if tw_revert
        set textwidth=0
    endif

endfun

map <C-S> :call PySort()<CR>