I have a long bibliography file for a latex document and I must put
the references in order. Unfortunately the different authors have used
different styles, so that I have two blocks.
In the first block all references look like

------------------------------------------------------------
\bibitem[ {Aarseth}, 1999]{Aarseth99}{Aarseth}, S.~J. (1999).\newblock
{From NBODY1 to NBODY6: The Growth of an Industry}.\newblock {\em
PASP}, 111:1333--1346.
----------------------------------------------------------

(note that each entry is a single row)

And in the second block I have

----------------------------------------------------------
\bibitem{stroeer06emri} Stroeer A, Gair J R and Vecchio A, 2006,
Proceedings of 6th LISA Symposium submitted, preprint gr-qc/0605227
----------------------------------------------------------

(idem, single rows)

Well, if a few liberties can be taken, Vim7's sorting functionality offers a killer solution to this problem:

        :%sort /\\bibitem[^{]*{\zs/

Since each bib item is on its own line (and not overflowing to multiple lines), a simple sort at the "right" offset (as kindly found by the regexp) will do the trick. In this case, the pattern is "start ("\zs") the sorting comparison after '\bibitem up through the first open-curly-bracket' ("\\bibitem[^{]*{")"

(okay, now /that/ had some odd quoting and parenthesizing in it...)

It does have the side effect that the block are no longer separated by whitespace, but this can then be rectified with

        :%s/$/\r

which will doublespace them again.

Adjust the "%" for to be your desired range.

I have more than 200 references and I don't feel like doing this per hand!


Hopefully this does the trick for you. If not, drop a line to the list with the details of went gonzo (likely some precondition I'm missing).

-tim


Reply via email to