Skip to content

Instantly share code, notes, and snippets.

@oxUnd
Created April 18, 2015 15:07
Show Gist options
  • Save oxUnd/ea637786f6fe3480a3cf to your computer and use it in GitHub Desktop.
Save oxUnd/ea637786f6fe3480a3cf to your computer and use it in GitHub Desktop.
SortWord.vim
function! Strcmp(...)
let a1 = a:1
let a2 = a:2
if a1 =~ '^\d\+$'
let a1 = 0 + a1
endif
if a2 =~ '^\d\+$'
let a2 = 0 + a2
endif
if a1 == a2
return 0
elseif a1 > a2
return 1
else
return -1
endif
endfunction
function! SortWord()
let lnum = 1
while lnum <= line("$")
let words = split(getline(lnum), " ")
call sort(words, function("Strcmp"))
call setline(lnum, join(words, " "))
let lnum = lnum + 1
endwhile
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment