Cool vim random line shuffle trick
by Kyle Skrinak on May.17, 2009, under Technology
Recently, I needed to perform a random sort of lines in vim. After a little bit of googling, I came up with the following:
(Works on Mac OS X Leopard and ubuntu 9.4)
Create the following perl script file:
#!/usr/bin/perl -w
use strict;
use List::Util 'shuffle';
my @lines = <>;
print shuffle( @lines );
Save the file and make it executable as well as easily accessible. Such as a directory that is in your PATH variable.
Now, fire up vim and visually select the lines you want to randomly select. Now, type:
!randsort.pl
There it is — randomly sorted lines.


December 14th, 2009 on 3:18 am
Look up the Unix command shuf.