Created
April 18, 2015 15:07
-
-
Save oxUnd/ea637786f6fe3480a3cf to your computer and use it in GitHub Desktop.
SortWord.vim
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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