I want to load a plugin when I enter a buffer, so I set this event to BufEnter. But when I start neovim, the plugin loads at the dashboard buffer. I want to exclude that buffer. How can I do it?


I created the augroup in the init.lua file before lazy.nvim and set the plugin event to the new augroup, but when I enter neovim, I get this error:

Failed to setup handlers for Comment.nvim

...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:68: Invalid 'event': 'BufInit'

# stacktrace:
  - init.lua:65

I changed the augroup name from NVIMCMPtGrp to BufInit.

The plugin unloads when I'm on dashboard, but it doesn't load when I enter a file


2 Answers 2


So I found a solution which is to use the BufRead event, which doesn't affect dashboard for some reason.

return {
   event = "BufRead",
  • Maybe could you elaborate a bit more. I'm not sure I understand your solution fully. Which file did you modified and how? Commented Nov 12, 2023 at 15:00
  • I modified the file of the plugin that I wanted to load as soon as I open a buffer, excluding the dashboard one, and set the event from BufEnter to BufRead. In my case, I modified more than 1 file since I needed this for more plugins, but in my original question, I used nvim-cmp as an example. For the structure of the file you can check lazy.nvim which is the plugin manager I use for my config,
    – Nias26
    Commented Nov 13, 2023 at 15:48

I would put a condition in the autocmd command:

For Startify I would do:

augroup NVIMCMP
autocmd BufEnter * if &filetype!=#'startify' | MyCommand | endif
augroup END

For Dashboard I would do:

augroup NVIMCMP
autocmd BufEnter * if &filetype!=#'dashboard' | MyCommand | endif
augroup END

Or is Lua variant:

local NVIMCMPtGrp = vim.api.nvim_create_augroup('NVIMCMPtGrp ', { clear = true })
vim.api.nvim_create_autocmd({"BufEnter"}, {group = NVIMCMPtGrp , pattern = '*', callback = function()
  if not (vim.bo.filetype == 'dashboard') then
    -- MyCommand
  • I want to exclude something from an existing augroup. I'm using lazy.nvim as a package manager and I load plugins using the event property to load plugins in certain events, which in this case is BufEnter. My question was how can I exclude the dashboard buffer from the BufEnter augroup, not how to create one who excludes Dashboard.
    – Nias26
    Commented Nov 10, 2023 at 16:20
  • 1
    @Nias26 you cannot exclude certain buffers from the BufEnter autocommand. That's why you have to check, when the autocommand triggers if it matches your buffer that you want to exclude and skip it in that case. Commented Nov 11, 2023 at 12:33

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.