oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

bug: weird behaviour with bufferline.nvim

Open onexbash opened this issue 10 months ago • 1 comments

Did you check the docs and existing issues?

  • [x] I have read the docs
  • [x] I have searched the existing issues

Neovim version (nvim -v)

0.11.1

Operating system/version

MacOS Sequoia 15.4.1

Describe the bug

When opening a file with nvim ~/path/to/file The bufferline gets attached and the next files I open via oil filetree are added as tabs perfectly fine.

When opening nvim in a directory and then opening a file via the oil filetree, the bufferline doesnt get attached and every other files I'm opening are not added to the bufferline.

Really weird. I use the "BufReadPost" & "BufNewFile" events for loading bufferline.nvim so I dont get what the problem is. (opening them via oil.nvim should trigger the same events imo).

Didn't quite know whether to create an issue here or in the bufferline.nvim repo so I did both: https://github.com/akinsho/bufferline.nvim/issues/1017

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

✅ WORKS

  1. Setup bufferline.nvim
  2. nvim /path/to/file
  3. <CMD>Oil<CR>
  4. Open another File => see how the buffers are attached to the bufferline

❌ DOESNT WORK

  1. Setup bufferline.nvim
  2. nvim /path/to/dir
  3. <CMD>Oil<CR>
  4. Open a File
  5. Open another File => see how the bufferline stays empty

Expected Behavior

Buffers are always attached to the bufferline no matter from where they are opened

Directory structure

No response

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • [x] I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.

onexbash avatar Apr 28 '25 17:04 onexbash

This is likely some interaction between the two plugins, not merely a bug in one or the other. The first piece of debugging will have to happen in bufferline. I'll need to know how buffers get added (is it an autocmd? Which ones?). Under the hood oil is opening the file in a somewhat nonstandard way, by first executing bufadd to create the buffer, manually setting buflisted, then switching using vim.cmd.buffer().

https://github.com/stevearc/oil.nvim/blob/685cdb4ffa74473d75a1b97451f8654ceeab0f4a/lua/oil/init.lua#L743-L763

My guess is that bufferline is only adding new buffers if they are buflisted when created, and isn't listening for the OptionSet buflisted autocmd. That wouldn't explain why it works in some situations and not in others, though.

stevearc avatar Jul 02 '25 00:07 stevearc