NvChad / NvChad

Blazing fast Neovim config providing solid defaults and a beautiful UI, enhancing your neovim experience.

Home Page:https://nvchad.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bufferline-like options in tabufline, or theme toggling support for bufferline.nvim

gitaarik opened this issue · comments

commented

Is your feature request related to a problem? Please describe.

I can't seem to find out how I can configure tabufline to look like bufferline:

  • I like my tabs to spread over the full width of the screen. With tabufline, tabs only starts after the nvimtree sidebar. With bufferline, the tab bar is spread over the full width, regardless of whether the nvimtree sidebar is visible or not.
  • bufferline supports alternative styling, like slanted tabs.
  • bufferline supports many other features that I don't know if it's possible and how to configure with tabufline.

But when disabling tabufline and adding bufferline, when I toggle the theme from dark/light with base46's toggle_theme() function, the bufferline colors don't change. However after restarting nvim they are changed.

Describe the solution you'd like

Either have the options from bufferline available in tabufline, or be able to make bufferline toggle the theme along with base46's toggle_theme().

What is actually the reason NvChad uses tabufline? It seems to me bufferline provides all the features tabufline has. Additional tabpages also gives me numbered tabs on the right.

image

What is actually the reason NvChad uses tabufline

tabufline manages buffers per tabs, which bufferline doesnt, you have to use external plugins like scoped.nvim to achieve that.

I like working on multiple project dirs at the same time so i put each of them i new tab and all tab's files dont mix with each other.

Bufferline.nvim shows all buffers , from other tabs too.

And the slant style you see works good on only certain terminals, like kitty btw. i have talked about it with bufferline's creator years ago, it wouldnt look the same on all terminals cuz of glyph issues

I like tabufline as i built it and i want it minimal! Also with the toggle theme stuff, i hope u added bufferline word in your base46. integrations table.

commented

Ok, it took me some time to migrate from NvChad 2.0 to 2.5, but it all works now again. Nice refactor! :)

I added "bufferline" now to the base46.integrations table in chadrc.lua, and added dofile(vim.g.base46_cache .. "bufferline") before initializing bufferline. However, the slanted tabs are not styled properly. And I'm missing some highlight groups, like BufferLineTabSeparator. They are not defined in the integration, and adding them in chadrc.lua in ui.hl_override doesn't seem to work. But I can style it like this, inside the bufferline plugin config function:

local colors = require("base46").get_theme_tb "base_30"
vim.cmd("hi BufferLineTabSeparator guibg=" .. colors.one_bg .. " guifg=" .. colors.one_bg2)

But that is a bit ugly and confusing.

Why doesn't the ui.hl_override work? I guess because there's nothing to override, but would be nice to be able to add highlight groups that aren't defined in the integration. How are these groups forwarded to the plugin anyway?

If I manage to make the slanted tabs look nice, I could add an integration for that. Because I don't know if it will look good for the non-slanted version too, so maybe better to make it a separate integration?

commented

Ok I got it styled nicely now. For reference:

In chadrc.lua, for overriding base46 integration vars:

return {
  -- [...]
  ui = {
    hl_override = {
      BufferLineBackground = {
        bg = "one_bg",
      },
      BufferLineCloseButton = {
        bg = "one_bg",
      },
      BufferLineFill = {
        bg = "one_bg2",
      },
      BufferLineModified = {
        bg = "one_bg",
      },
      BufferLineSeparator = {
        fg = "one_bg2",
        bg = "one_bg",
      },
      BufferLineSeparatorVisible = {
        fg = "one_bg2",
      },
      BufferLineSeparatorSelected = {
        fg = "one_bg2",
        bg = "black",
      },
      BufferLineTab = {
        bg = "one_bg",
      },
      BufferLineTabSelected = {
        fg = "white",
        bg = "black",
      },
      BufferLineTabClose = {
        bg = "one_bg2",
      },
    },
  },
  base46 = {
    integrations = {
      -- [...]
      "bufferline",
    },
  },
}

In bufferline.nvim plugin config, for adding highlight groups not defined in base46 integration:

{
  "akinsho/bufferline.nvim",
  lazy = false,
  dependencies = "nvim-tree/nvim-web-devicons",
  config = function()
    dofile(vim.g.base46_cache .. "bufferline")

    local colors = require("base46").get_theme_tb("base_30")

    local hl = function(group, opts)
      vim.api.nvim_set_hl(0, group, opts)
    end

    -- Style things that can't be styled through base46
    hl("BufferLineTabSeparator", {
      fg = colors.one_bg2,
      bg = colors.one_bg,
    })

    hl("BufferLineTabSeparatorSelected", {
      fg = colors.one_bg2,
      bg = colors.black,
    })

    hl("BufferLineDevIconlua", {
      bg = colors.one_bg,
    })

    hl("BufferLineDevIconluaInactive", {
      bg = colors.black2,
    })

    -- Enable mouse hover events
    -- See `:help bufferline-hover-events`
    -- https://github.com/akinsho/bufferline.nvim?tab=readme-ov-file#hover-events
    vim.opt.mousemoveevent = true

    require("bufferline").setup({
      options = {
        separator_style = "slant",
        hover = {
          enabled = true,
          delay = 200,
          reveal = { "close" },
        },
      },
    })
  end,
}

Preview:

image
commented

I figured it might actually be prettier if I just do everything in one spot. So I am just doing this now in the bufferline plugin config:

local colors = require("base46").get_theme_tb("base_30")
                                                         
local highlights = {
  BufferLineBackground = {
    bg = colors.one_bg,
  },
  BufferLineFill = {
    bg = colors.one_bg2,
  },
  BufferLineModified = {
    bg = colors.one_bg,
  },
  BufferLineCloseButton = {
    bg = colors.one_bg,
  },
  BufferLineBufferVisible = {
    bg = colors.black2,
  },
                                                         
  -- separators
  BufferLineSeparator = {
    fg = colors.one_bg2,
    bg = colors.one_bg,
  },
  BufferLineSeparatorVisible = {
    fg = colors.one_bg2,
    bg = colors.black2,
  },
  BufferLineSeparatorSelected = {
    fg = colors.one_bg2,
    bg = colors.black,
  },
                                                         
  -- tabs
  BufferLineTab = {
    bg = colors.one_bg,
  },
  BufferLineTabSelected = {
    fg = colors.white,
    bg = colors.black,
  },
  BufferLineTabClose = {
    bg = colors.one_bg2,
  },
  BufferLineTabSeparator = {
    fg = colors.one_bg2,
    bg = colors.one_bg,
  },
  BufferLineTabSeparatorSelected = {
    fg = colors.one_bg2,
    bg = colors.black,
  },
                                                         
  -- icons
  BufferLineDevIconlua = {
    bg = colors.one_bg,
  },
  BufferLineDevIconluaInactive = {
    bg = colors.black2,
  },
}
                                                         
for group, opts in pairs(highlights) do
  vim.api.nvim_set_hl(0, group, opts)
end
commented

Although I'm noticing that then sometimes the styling disappears, so I'll also keep the config in chadrc.lua.

hl_add is used for adding new hlgroups, that bufferline integration hasnt been updated since ages, you can make a PR :)

commented

Ah 👍 @ hl_add, hadn't noticed that part of the docs ;)

I'm missing some highlight groups in bufferline to have a default styling for filetype icons. I opened an issue for that at bufferline: akinsho/bufferline.nvim#884

When that gets resolved I'll work on a PR for an updated integration. I must point out though that in tabufline's styling, the inactive tabs are the same color as the filler. That style is also used in the current bufferline integration. But I like to see the tab borders also for inactive tabs. And I do like that the active tab has the same color as the editor background. And since there's only 1 darker color than the editor background, I need to reach out to lighter colors to distinguish between active/inactive tabs and the filler:

image

So not sure if that would be appreciated, or if we rather want to make a separate integration for that?

you can improve the bufferline integration!

or if we rather want to make a separate integration for that?

you could add conditional styling like what I did for cmp, so

local style = require("nvconfig").ui.bufferline.style

that key would have value of your choice,

so in chadrc it'dbe like this

M.ui = {
   ....
     bufferline = {
                 style = "blabla"
        }
   ....
}

i cant add this bufferline opt as default in nvconfig as bufferline plugin isnt used in nvchad. Do know that nvconfig is just a table of all default options used to configure our UI & base46 plugin. And at the end it merges its values from chadrc.

so in the integration file itself you could add lil docs for that chadrc* option

Would you suggest its better to override tabbuffline and statusline if we wanted to add some features from lualine and tabline respectively or would you suggest to integrate it into the modules section.

I really like Bufferlines styling features with the use of base46 but prefer the organization of tabswitching that you have already set up. Similarly for statusline, like the addition of a few modules or styling changes similar to lualine (but maybe not near the complexity of heirline.

@rcmendoza7 you can already add modules ( need to be functions ) to tabufline/statusline https://nvchad.com/docs/config/nvchad_ui

I can see that @siduck. What would i need to do to override the statusline in the ui? I can build the base46 integration for lualine. Similarly, what would i need to do to override the tabuffline in the ui, if i wanted to?

I can see that @siduck. What would i need to do to override the statusline in the ui? I can build the base46 integration for lualine. Similarly, what would i need to do to override the tabuffline in the ui, if i wanted to?

read the doc i sent, it even shows an example