1

I would like to echo the filename before deleting any buffer (:bd, :q). I wanted to achieve this by using auto-commands like this:

augroup DummyCodeGroup
    autocmd!
    autocmd BufDelete * lua print("path", vim.fn.expand('%:p'))
augroup END

But it seems like nothing is printed (just the "path" path). When I am just executing the following:

:lua print("path", vim.fn.expand('%:p'))

Then the right path is printed on the message line.

How can I achieve this? Should I use BufUnload instead as that's called before the BufDelete?

0

1 Answer 1

1

It is written under :h BufDelete

NOTE: Current buffer "%" may be different from the buffer being deleted

And the same holds for about a half of auto-commands in Vim. Therefore, it must be vim.fn.expand("<afile>:p") instead.

I would like to echo the filename before deleting any buffer (:bd, :q).

Note that BufDelete is only triggered before the option buflisted being switched to nobuflisted. See this topic for a more detailed explanation.

Your Answer

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

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