• Zach Pfeffer

Bug on page 134 of Vi IMproved—Vim by Steve Oualline

There is a bug on page 134 of Vi IMproved—Vim by Steve Oualline (ISBN 0-7357-1001-5) when the instructions listed are tried on VIM - Vi IMproved 7.4 installed from the Vim package version 2:7.4.1689-3ubuntu1.2.

The Bug

The DateInsert() autocommand doesn't get called when you do a


The Fix

To get the autocommand to execute you must execute a partial write with:

:1 write!

Alternative Fix

Define the autocommand with:

:autocmd FileWritePre,BufWritePre * :call DateInsert()

DateInsert() is defined as:

:function DateInsert()

: $read !date



From [9]:


Before writing to a file, when not writing the whole buffer. Use the '[ and '] marks for the range of lines.

BufWrite or BufWritePre

Before writing the whole buffer to a file.

Because of this, the only way to get FileWritePre to fire is to use the range form of write:

:[range]w[rite][!] [++opt] Write the specified lines to the current file. This is unusual, because the file will not contain all lines in the buffer.


In the autocmd doc it suggests setting verbose to 9 [7]:

While testing autocommands, you might find the 'verbose' option to be useful: :set verbose=9 This setting makes Vim echo the autocommands as it executes them.

A verbose level of 9 enables:

'verbose' 'vbs' number (default 0) global {not in Vi, although some versions have a boolean verbose option} When bigger than zero, Vim will give messages about what it is doing. Currently, these messages are given: >= 1 When the viminfo file is read or written. >= 2 When a file is ":source"'ed. >= 5 Every searched tags file and include file. >= 8 Files for which a group of autocommands is executed. >= 9 Every executed autocommand. >= 12 Every executed function. >= 13 When an exception is thrown, caught, finished, or discarded. >= 14 Anything pending in a ":finally" clause. >= 15 Every executed Ex command (truncated at 200 characters).

This option can also be set with the "-V" argument. See |-V|. This option is also set by the |:verbose| command.

When the 'verbosefile' option is set then the verbose messages are not displayed.

The -V argument is defined as:

-V[N][fname] Be verbose [level N] [log messages to fname]

Here's an example of calling vim with the -V argument:

vim -V9myVim.log

level [N] is 9

[fname] is myVim.log


1. Is there a “vim runtime log”?

2. Debugging Vim Scripts

3. Event-driven scripting and automation

4. Vi iMproved (VIM) by Steve Oualline

5. FileWritePre

6. Vi IMproved—Vim Errata

7. autocmd documentation

8. verbose documentation

9. FileWritePre and BufWritePre documentation

10. write documentation

Our Recent Posts



©2020 by Zach Pfeffer