vimdoc says:
BufUnload
Before unloading a buffer.
...
NOTE: When this autocommand is executed, the
current buffer "%" may be different from the
buffer being unloaded "<afile>".
Don't change to another buffer or window, it
will cause problems!
If the current buffer isn't the deleted/unloaded buffer, then can I access b: variables? I have a buffer that has a temp file and if the buffer goes away, I want to clean up the temp file.
Example:
let b:example_tempfile = tempname()
augroup example
au!
au BufUnload <buffer> call delete(b:example_tempfile)
augroup END