sponsor Vim development Vim logo Vim Book Ad

tbibtools : bibtex-related utilities (sort, reformat, list contents ...)

 script karma  Rating 1/3, Downloaded by 1696    Comments, bugs, improvements  Vim wiki

created by
Tom Link
script type
tbibtools provide a simple regexp-based bibtex parser. Please be aware
that this script makes a few assumptions on how a bib file should look
like and that it may fail on files formatted in unusual ways. Failure
may lead to loss of bib entries and malformed or incomplete output.  
Comments and other text will be stripped when reformatting entries. Any
feature of bibtex I don't know and/or don't use myself is most likely
not supported by this script/class.

Please take care when using this script. Make backups and check the
output, especially when using the -f command-line option. Don't blame me
if you lose information or end up with corrupted bib files.

    - sort bib files
    - reformat bib files
    - list keys in a bib file
    - show bib entries matching a regular expression

From the commands line:

The ruby directory contains a file tbibtools.rb that can be used as a
stand-alone script from the command line. For command-line use, only the
file tbibtools.rb and a ruby interpreter is needed.

    tbibtools [OPTIONS] < IN > OUT

For vim users:

The file plugin/tbibtools.vim provides the commands

    :'<,'>TBibTools [OPTIONS]
        Filter the selected text or the whole buffer through
        tbibtools.rb. The command line options are the same as for the

    :'<,'>TBibList [OPTIONS]
        List keys in a bibtex file (mostly the same as TBibTools --ls
        but lets you select an entry and jump to its position in the
        bibtex file).


    -i          ... case insensitive
    -e REGEXP   ... display entries matching the regexp
    -f FORMATS  ... re-format (order matters, comma-separated list):
                    align, bracket, check, downcaseType, gsub, indent,
                    list, nil, nnIsYear, ls, tml, stripEmpty,
                    stripRedundantTitel, unwrap, upcaseType, wrap
    --ls        ... synonym for: -f list,stripPrelude ("list" implies
    -l FORMAT   ... format string for list
    -q FIELD=RX ... show entries for which field matches the regexp
    -P          ... strip the prelude: same as -f stripPrelude but helps
    to maintain the original formatting
    -s FIELD    ... sort (default: sort by key; key = _id, type = _type)
    -S          ... replace/expand strings
    --strip FIELDS ... ignore/strip fields
    -u          ... unsorted


Formats can be easily plugged in by defining a method (see
TBibTools#format). As the formatters process the entry one after the
other, the order given on the command line matters.

Please scrutinize the output carefully. The use of an incomplete or simply
the wrong set of formatters can easily result in a corrupted bib file
that bibtex cannot read.

         Align the = sign.

         Enclose non-numeric values in curly braces.

         Replace text in the value.

         indent=N (default=4) Indent the entry's key-value pairs.

         Don't print any output.

         If an entry has a title and a booktitle field with the
         same value, only the booktitle field will be propagated.

         Drop fields with empty values.

         Put wrapped text into a single line.

         Try to cheaply wrap the value.

         Print a warning on invalid entries

         Try to correctly sort two-digit numbers in the key, i.e. sort
         example99 before example00.

         Downcase the bibtex type.

         Put the bibtex type in upper case letters.

         List keys only.

         Drop any prelude (useful in conjunction with some other
         commands). It is supposed the bibtex file is made up of a
         prelude containing @string definitions and a series of bibtex

        A shortcut for:
        (see also TBibTools#format_option_tml)


Reformat the bib file

  tbibtools -f tml < monos.bib > monos_sorted.bib

  tbibtools -f gsub=ä:\"a:ö:\"o:ü:\"u < monos.bib > monos_sorted.bib

List the contents (see also TBibTools#format_option_ls)

  tbibtools --ls < monos.bib
  tbibtools --ls -l "#{_lineno}: #{author|editor|institution}: #{title|booktitle}" < monos.bib

Extract a few entries la grep (kind of):

  tbibtools -P -e Hugo < monos.bib
  tbibtools -P -q author=Adorno -q keywords=Adorno < monos.bib
  tbibtools -P -q author="Husserl|Merleau-Ponty" < monos.bib

install details
Install as vim plugin:
Extract the archive to ~/.vim or ~/vimfiles (Windows).

A vim with compiled-in ruby support is required.

The TBibList command requires tlib (vimscript #1863).

Install as script:
The ruby directory contains a rudimentary makefile:
    make -f Makefile.tbibtools install

Also available via git

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
tbibtools.zip 0.5 2007-07-17 7.0 Tom Link - VIM: Require tlib 0.9
tbibtools.zip 0.4 2007-06-18 7.0 Tom Link - sortCrossref: Put cross-referenced entries to the back.
- New format: (un)selectCrossref: View only entries that are (not) cross-referenced
- Improved TBibList (include keywords in list; if g:tbibUseCache is set, the listing will be cached between editing sessions)
tbibtools.zip 0.3 2007-06-08 7.0 Tom Link - Syntax of the query command has changed: query FIELD1 => RX1, FIELD2 => RX2 ...
- Merge duplicate entries
- Merge certain conflicting fields
- FIX: Problem with --ls
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo