If you can use the rev
command, you could reverse each line, sort and reverse again, using external commands in a pipe:
%!rev | sort | rev
This can be done entirely in Vimscript, but it's way more verbose:
function! RTLSort() range
" reversing function for use with map()
function! Rev(k, str)
" the first argument from map() is an index, so it's ignored.
return join(reverse(split(a:str, '\zs')), '')
endfunction
let l:Rev = function("Rev")
let l:lines = getline(a:firstline, a:lastline)
call setline(a:firstline, map(sort(map(l:lines, l:Rev)), l:Rev))
endfunction
Then, something like:
:%call RTLSort()
:3,9 call RTLSort()