func! StrICmp(str1, str2) if (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 :call PySort()