romgrk / barbar.nvim

The neovim tabline plugin.
2.16k stars 81 forks source link

How to hide the empty buffer after opening a valid one #582

Closed ZouDongj closed 1 month ago

ZouDongj commented 1 month ago

I want to use barbar instead of nvchad's own tabufline, but it seems that barbar will treat nvdash's splash page as a buffer, and after opening other buffers on the startup page, barbar will have an extra buffer x that cannot be closed or hidden, is there a way for this extra buffer to be automatically hidden after opening a valid buffer? image

ZouDongj commented 1 month ago

Another problem is that the sidebar's offset doesn't seem to align correctly, tried :set fillchars=vert:, but it didn't work image

romgrk commented 1 month ago

I don't know much about your setup, you'll need to provide more details if you want assistance. Barbar use the set buflisted flag for listing buffers. try unsetting it.

ZouDongj commented 1 month ago

I don't know much about your setup, you'll need to provide more details if you want assistance. Barbar use the set buflisted flag for listing buffers. try unsetting it.

My bad,here is my config:

    "romgrk/barbar.nvim",
    event = { "BufReadPre", "BufNewFile" },
    dependencies = {
      "lewis6991/gitsigns.nvim", -- OPTIONAL: for git status
      "nvim-tree/nvim-web-devicons", -- OPTIONAL: for file icons
    },
    init = function()
      vim.g.barbar_auto_setup = false
    end,
    opts = {
      -- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:
      animation = true,
      highlight_visible = true,
      icons = {
    inactive = { separator = { left = '', right = '' } },
        separator = { left = '', right = '' },
      },
      insert_at_start = false,
      -- Set the filetypes which barbar will offset itself for
      sidebar_filetypes = {
        -- Use the default values: {event = 'BufWinLeave', text = '', align = 'left'}
        NvimTree = true,
        -- Or, specify the text used for the offset:
        undotree = {
          text = "undotree",
          align = "center", -- *optionally* specify an alignment (either 'left', 'center', or 'right')
        },
        -- Or, specify the event which the sidebar executes when leaving:
        ["neo-tree"] = { event = "BufWipeout" },
        -- Or, specify all three
        Outline = { event = "BufWinLeave", text = "symbols-outline", align = "right" },
      },
      -- …etc.
    },

    config = function(_, opts)
      require("barbar").setup(opts)
      vim.cmd [[
                " For barbar
                highlight BufferTabpageFill guibg=#252931
                highlight BufferTabpages guibg=NONE
                highlight BufferTabpagesSep guibg=NONE
                " barbar - current buffer
                highlight BufferCurrent guibg=NONE guifg=#A6E3A1
                highlight BufferCurrentADDED guibg=NONE
                highlight BufferCurrentCHANGED guibg=NONE
                highlight BufferCurrentDELETED guibg=NONE
                highlight BufferCurrentERROR guibg=NONE guifg=#F38BA8
                highlight BufferCurrentWARN guibg=NONE guifg=#F9E2AF
                highlight BufferCurrentHINT guibg=NONE guifg=#A6E3A1
                " highlight BufferCurrentIcon guibg=NONE
                highlight BufferCurrentIndex guibg=NONE
                " highlight BufferCurrentINFO guibg=NONE
                highlight BufferCurrentMod guibg=NONE guifg=#A6E3A1
                highlight BufferCurrentNumber guibg=NONE
                highlight BufferCurrentSign guibg=NONE
                highlight BufferCurrentSignRight guibg=NONE
                highlight BufferCurrentTarget guibg=NONE

                " barbar - inactive buffer
                highlight BufferInactive guibg=#252931
                highlight BufferInactiveADDED guibg=NONE
                highlight BufferInactiveCHANGED guibg=NONE
                highlight BufferInactiveDELETED guibg=NONE
                highlight BufferInactiveERROR guibg=NONE
                highlight BufferInactiveHINT guibg=NONE
                highlight BufferInactiveIcon guibg=NONE
                highlight BufferInactiveIndex guibg=NONE
                highlight BufferInactiveINFO guibg=NONE
                highlight BufferInactiveMod guibg=NONE
                highlight BufferInactiveNumber guibg=NONE
                highlight BufferInactiveSign guibg=NONE
                highlight BufferInactiveSignRight guibg=NONE
                highlight BufferInactiveTarget guibg=NONE
                highlight BufferInactiveWARN guibg=NONE

                highlight BufferVisible          guibg=NONE
                highlight BufferVisibleADDED     guibg=NONE
                highlight BufferVisibleCHANGED   guibg=NONE
                highlight BufferVisibleDELETED   guibg=NONE
                highlight BufferVisibleERROR     guibg=NONE
                highlight BufferVisibleHINT      guibg=NONE
                highlight BufferVisibleIcon      guibg=NONE
                highlight BufferVisibleIndex     guibg=NONE
                highlight BufferVisibleINFO      guibg=NONE
                highlight BufferVisibleMod       guibg=NONE
                highlight BufferVisibleNumber    guibg=NONE
                highlight BufferVisibleSign      guibg=NONE
                highlight BufferVisibleSignRight guibg=NONE
                highlight BufferVisibleTarget    guibg=NONE
                highlight BufferVisibleWARN      guibg=NONE

                ]]
    end,
    version = "^1.0.0", -- optional: only update when a new 1.x version is released
  },
}
Iron-E commented 1 month ago

As for hiding the buffer, what romgrk said would be the solution. For example, the following in your config will achieve what you're looking for:

-- ftplugin/<startpage-ft>/config.lua
vim.api.nvim_set_option_value('buflisted', false, {scope = 'local'})

Replace <startpage-ft> with the output of `:echo &filetype' while inside the startpage.


As for the offset, I couldn't reproduce— could you post a minimal reproduction? I've left a template below:

--[[ minimal.lua ]]

-- load plugins
local lazy = vim.fn.stdpath('data') .. '/lazy/'
vim.opt.rtp:prepend {
  lazy .. 'barbar.nvim',
  lazy .. 'nvim-web-devicons',
}

-- setup barbar
vim.g.barbar_auto_setup = false
require('barbar').setup {
  -- options
}

-- setup other plugins...

It should be possible to run nvim --clean -u minimal.lua to reproduce the issue.

romgrk commented 1 month ago

For the offset I think it's aligned as it's intended to be aligned, it's just that you use a vertsplit style that makes it seems like the vertical separator is part of the sidebar. Here is how it looks on my side, see how barbar aligns with the vertsplit, it's the same alignment as your case but the style makes it work properly:

image

ZouDongj commented 1 month ago

As for hiding the buffer, what romgrk said would be the solution. For example, the following in your config will achieve what you're looking for:

-- ftplugin/<startpage-ft>/config.lua
vim.api.nvim_set_option_value('buflisted', false, {scope = 'local'})

Replace <startpage-ft> with the output of `:echo &filetype' while inside the startpage.

As for the offset, I couldn't reproduce— could you post a minimal reproduction? I've left a template below:

--[[ minimal.lua ]]

-- load plugins
local lazy = vim.fn.stdpath('data') .. '/lazy/'
vim.opt.rtp:prepend {
  lazy .. 'barbar.nvim',
  lazy .. 'nvim-web-devicons',
}

-- setup barbar
vim.g.barbar_auto_setup = false
require('barbar').setup {
  -- options
}

-- setup other plugins...

It should be possible to run nvim --clean -u minimal.lua to reproduce the issue.

Thx, the initial buffer could be hidden correctly now. As for the offset, I guess it's because I'm using the nvchad ui plugins, and I try to view the barbar's code, I found that after changing the 'offset + 1' in the function total_widths() to 'offset', the offset was fixed image

ZouDongj commented 1 month ago

The last issue I want to ask for help is that every time I try to restore the sessions, the barbar's display area will flash a strange highlight, is there any problems with my highlight configuration? highlight

Iron-E commented 1 month ago

The last issue I want to ask for help is that every time I try to restore the sessions, the barbar's display area will flash a strange highlight, is there any problems with my highlight configuration? highlight

What comedienne colorscheme were you using?

ZouDongj commented 1 month ago

The last issue I want to ask for help is that every time I try to restore the sessions, the barbar's display area will flash a strange highlight, is there any problems with my highlight configuration? highlight

What comedienne were you using?

Sry I don't get what the comedienne means, my colorscheme is OneDark, which is one of the preset themes that comes with NvChad's Base46 theme framework

romgrk commented 1 month ago

Could you post a log of your highlights? Maybe you have a white background to one of the default highlights. Run :let @+ = execute('hi').

ZouDongj commented 1 month ago

Could you post a log of your highlights? Maybe you have a white background to one of the default highlights. Run :let @+ = execute('hi').

I try to reboot my vm and now the highlighting seems to be back to normal😂

Iron-E commented 1 month ago

I'll close this for now, feel free to reopen if the highlighting has problems again!