4

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

1 Answer 1

8

Use :h <afile> to get unloading buffer name, use :h getbufvar() to get buffer local variable.

let b:example_tempfile = tempname()
augroup example
    au!
    au BufUnload <buffer> echom getbufvar( expand('<afile>'), 'example_tempfile' )
augroup END
bunload %

--------------------------------
/tmp/vovl8Be/48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.