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

Need a little help with tabclose

Open kalloc opened this issue 1 year ago • 3 comments

I re-opened a question in lazyvim gh, https://github.com/LazyVim/LazyVim/discussions/531 They suggested changing settings in bufferline.

I want to hide/remove tab from bufferline after :tabclose, how can I do it?


my native nvim setup, where tabclose visually close tabs https://asciinema.org/a/jDM3xvesCQPwGT5On9n8NX2Dz

fresh lazyvim, where tabclose do something, but visually tabs stay unclosed https://asciinema.org/a/KKDkFl70gNkwYWO6KgtMgMMf5

kalloc avatar Jan 09 '25 12:01 kalloc

In your config, do you have the 'mode' key set to 'tabs'? e.g.

return {
  -- using lazy.nvim
  {
    'akinsho/bufferline.nvim',
    version = '*',
    dependencies = 'nvim-tree/nvim-web-devicons',
    opts = {
      options = {
      -- [[̣the line below]]--
        mode = 'tabs',
      -- [[̣the line above]]--
        name_formatter = function(buf)
          return buf.name
        end,
        numbers = 'none',
        truncate_names = true,
        separator_style = 'slant',
        indicator = {
          icon = '&',
          style = 'icon',
        },
        show_buffer_icons = true,
        show_buffer_close_icons = false,
        show_close_icon = false,
        always_show_bufferline = true,
        enforce_regular_tabs = false,
      },
    },
  },
}

Vim makes use of buffers, windows and tabs. Buffers hold the text of the files for editing. Windows are collections of buffers alá :vs and the like. Tabs are collections of windows. When you close a buffer, vim will still show it in memory. You can see them with :buffers!

So while closing a tab will indeed close that tab, the buffers still in memory will still be shown. Luckily, the mode = 'tabs' option will disable showing buffers.

Additionally, buffers can be deleted with bdelete or bd if you're nasty ;)

fuguesoft avatar May 02 '25 13:05 fuguesoft

Video example: https://0x0.st/84SW.mp4

https://github.com/user-attachments/assets/7ebae6e2-2066-4f51-8080-6083be6aa8c1

fuguesoft avatar May 02 '25 14:05 fuguesoft

I solved my issue with:

{
  "akinsho/bufferline.nvim",
  event = "VeryLazy",
  dependencies = "nvim-tree/nvim-web-devicons",
  config = function()
    require("bufferline").setup({
      options = {
        mode = "tabs",
      },
    })
  end,
},

and with keymap:

vim.keymap.set("n", "<A-w>", function()
  require("snacks.bufdelete").delete()
  if #vim.api.nvim_list_tabpages() > 1 then
    vim.cmd("tabclose")
  end
end, { desc = "Close Tab" })

kalloc avatar May 02 '25 14:05 kalloc