(If your chunks are long, tread carefully with :set ul=-1).
It's a variation on the decorate-sort-undecorate method. If your first lines aren't distinctive other than being preceded by an empty line, I found I had to do two decorate steps, and other fiddling:
:normal ggO " start file with blank line, so that the first
" first line has a blank line before it
:g/\(^\n\)\@<=./s/$/xyzzy " mark first lines
:v/xyzzy/s/$/plugh/ " mark the others
:1dd " delete the added line
:g/plugh/-j! " join non-first lines to the one before it
:%s/plughplugh/\r/g " split lines again
To sort the chunks randomly, you'd have to decorate the lines with a random number. If you're on something Gnu-ish, piping through shuf would do; replace the :sort with
Regards, John Little
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
> Given a document with text blocks separated by empty lines:
> chunk one
> chunk two
> chunk three
> I need to both (for different purposes) 1) sort the blocks by their
> first lines and then 2) randomize the blocks by their first line.
> How might one (I) do this?