In a pinch, I needed to randomize the order of a few thousand lines of plain text. In Linux you can just pipe the file through
sort, even right inside Vim:
But I was stuck on Windows. And I don't know how to randomize a file in native Vim script. But doing it in Ruby is pretty easy, and luckily, Vim has awesome Ruby support. Tne minutes' work and a few peeks at
:h ruby and we have a successful, working kludge:
function! ShuffleLines() ruby << EOF buf = VIM::Buffer.current firstnum = VIM::evaluate('a:firstline') lastnum = VIM::evaluate('a:lastline') lines =  firstnum.upto(lastnum) do |lnum| lines << buf[lnum] end lines.shuffle! firstnum.upto(lastnum) do |lnum| buf[lnum] = lines[lnum-firstnum] end EOF endfunction
2011-07-07 23:32 - Edited to remove a superfluous line.
2011-07-09 21:33 - Wrong parameter for