Vincent Beffara wrote:
So here is my question. I have a bibliography in a .bib file, which
(just in case) is just a plain text files containing entries that each
look like this :
@article{key,
author = {Whatshisname, J.},
title = {My paper}
}
(note the '@' at the beginning of the first line - folding a .bib file
is trivial for instance).
I would like to sort the entries according to, say, the author's last
name (though by key or even by first line is ok). What would be a good
way to do this ?
Sure! The approach I'm suggesting uses BlockSort(), available as part
of the vissort plugin.
You can get the vissort plugin from my website:
http://mysite.verizon.net/astronaut/vim/index.html#VISSORT
Here's the relevant blurb from the help:
:'<,'>BS
:'< '>BS nextblock endblock findtag tagpat tagsub
:[range]call BlockSort(nextblock,endblock,findtag,tagpat,tagsub)
:[range]call BlockSort(...)
If any arguments are missing, BlockSort()
will query the user for them.
This function's purpose is to sort blocks of text based on tags
contained within the blocks.
For this particular problem, the following call will work:
%call
BlockSort('[EMAIL PROTECTED]','','^\s*author\s*=','^.*{\s*\(.\{-}\)\s*,.*$','\1')
This assumes: each block starts, at the beginning of the line,
@article
This pattern is also used to separate blocks.
Inside the block is a line satisfying the pattern:
^\s*author\s*=
The next two items are used in a substitute operation on the line
satisfying the
pattern above, and are used to extract the item that the blocks are to
be sorted
with.
Regards,
Chip Campbell