As I was tired of always using some custom C program using libgsf to dump each of the doc files I was studying before viewing it in Vim, I decided to add some Vim configuration for it to do it automatically. This post will explain how to do that.

In your .vimrc file, add the following line:

autocmd BufReadCmd *.doc,*.xls,*.ppt exe ":silent 1,$!gsf-dump %" | setlocal buftype=nofile

This is calling a script gsf-dump on the currently edited file, replaces the buffer content by the dump result and tells the buffer that its not showing a file. This last part will avoid you to writer the dump in the original file. The gsf-dump program was first a custom C application using libgsf, but I replaced it by a bash script to simplify the installation for you. On openSUSE 11.2, you need to install the libgsf package (the name may vary for other distributions). Here is the shell script to name gsf-dump:


if [[ $# != 1 ]]
    echo "$0 FILE"
    echo " FILE is the GSF archive to dump"
    exit 1

gsf list $1 | while read -r typ sz name
    if [[ "$typ" == "f" ]]
        gsf dump $1 $name

Now you can use directly vim file.doc or vim -d file1.doc file2.doc to inspect the doc files.