Kyle D. Skrinak

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.

1 comment for this entry:
  1. Tim

    Look up the Unix command shuf.

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!