packer.nvim
packer.nvim copied to clipboard
Lazy-loading a plugin triggers BufRead autocommands defined elsewhere
-
nvim --version
: 0.8.0
Steps to reproduce
Put the following in your init.lua
:
vim.api.nvim_create_autocmd("BufReadPost", {callback = function() print("Triggered") end})
Also configure a plugin to be lazy-loaded on a given command or key.
Restart Neovim and trigger the command/key to load the plugin.
Actual behaviour
The autocommand will be triggered by the loading of the plugin.
Expected behaviour
No external autocommand will be triggered by the loading of the plugin.
Workaround
Put a condition in the autocommand to make it trigger only once per buffer:
vim.api.nvim_create_autocmd("BufReadPost", {callback = function()
if not vim.b.my_autocmd_triggered then
print("Triggered")
vim.b.my_autocmd_triggered = true
end
end})