Is there a package/function for shuffling the paragraphs in the buffer? (I mean to sort the paragraphs with a random order, not changing the paragraphs, just randomizing their order).

Motivation: For learning vocabulary of a foreign language, research shows that it is better to change the order of the words you study. There is such a thing as “serial” learning such that a fixed order becomes itself a trigger in remembering the word. See http://rharriso.sites.truman.edu/vocabulary-and-word-formation/vocabulary-home/tips-on-learning-vocabulary/. Imagine you have a buffer in which every paragraph contains a word and its meaning. It would be great to change the order of paragraphs.

Edit: Based on the idea given by Politza, here is a solution:

(defun random-sort-paragraphs (reverse beg end)
  (interactive "P\nr")
      (if (region-active-p) (narrow-to-region beg end))
      (goto-char (point-min))
      (sort-subr reverse
                  (lambda ()
                    (while (and (not (eobp)) (looking-at paragraph-separate))
                      (forward-line 1))))
                 'forward-paragraph nil nil
                 (lambda (s1 s2) (eq (random 2) 0))))))
  • 2
    Look at sort-paragraph and then change the sort-predicate.
    – politza
    Commented Dec 29, 2016 at 14:48
  • 1
    You may find org-drill useful.
    – Juancho
    Commented Dec 29, 2016 at 14:59
  • 1
    @politza thank you for the idea. If you like and find it helpful, consider to post a complete solution.
    – Name
    Commented Dec 29, 2016 at 15:47

1 Answer 1


In a comment, @politza provided the best answer (and hopefully @politza will post it as an answer): use sort-paragraphs.

In addition, you can use transpose-paragraphs to move the previous paragraph down past the next one (or up, with a negative prefix arg).

You can repeat transpose-paragraphs (easiest if bound to a key) to, essentially, drag a paragraph down to a given spot. Not a replacement for sort-paragraphs, by any means, but a quick way to interactively make some changes in paragraph order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.