romgrk / barbar.nvim

The neovim tabline plugin.
2.26k stars 85 forks source link

Highlight colors inconsistent between buffers #551

Closed hersi97 closed 7 months ago

hersi97 commented 7 months ago

I'm not really sure if this is a bug in barbar or how colors are handled in nvim generally. But I realized I did not have separator between tabs while my cursor was in the opened file buffer, but it was visible while in any other buffer (eg. Telescope, help pages, sidebar, etc)

Cursor in opened file: image Cursor in any other buffers (eg. buffer opened with :h, neo-tree, Telescope floating windows, etc.): image

I realize this is solved by setting highlight groups (like :hi BufferCurrentSign guifg=#0db9d7), but then I would need to have BufferCurrent<Part> set to the same as BufferVisible<Part>, which would defeat the purpose, I think.

My current highlight groups: image

I am quite new to neovim, am I overlooking something simple?

Iron-E commented 7 months ago

Thanks for the report :)

Can you post your barbar config and colorscheme?

Edit: I see you found a fix. Since you said you were new, I want to give a couple tips about highlighting:

  1. You can :highlight link two groups together such that changes to one affect the other.
    • In this case you could :hi link BufferVisibleSign BufferCurrentSign
  2. You don't always have to define both guibg and guifg: given their absence, they will be inferred by context (e.g. the background depends on what is around it, if only foreground is defined).
hersi97 commented 7 months ago

Sure! I'm using lazy.nvim to manage plugins. I haven't tried it in a vacuum, with only these 3 plugins, but I don't think anything else would modifiy the colors.

-- ~/.config/nvim/lua/plugins/theme.lua
return {
  {
    "folke/tokyonight.nvim",
    lazy = false,
    priority = 1000,
    opts = {
      style = "storm",
    },
    config = function(_, opts)
      require("tokyonight").setup(opts)
      vim.cmd([[colorscheme tokyonight]])
    end
  },

  "nvim-tree/nvim-web-devicons",

  {
    'romgrk/barbar.nvim',
    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,
      -- insert_at_start = true,
      -- …etc.
      icons = {
        separator = { left = "▎", right = "" },
        separator_at_end = true,
      },
    },
    version = '^1.0.0', -- optional: only update when a new 1.x version is released
    config = function(_, opts)
      require("keymap").loadkeys(require("plugins.mappings.barbar"))
      require("barbar").setup(opts)
      vim.cmd([[hi BufferCurrentSign guifg=#0db9d7]]) -- NOTE: workaround for separator color
    end
  },
}

Also, thank you for the tips! :)

Iron-E commented 7 months ago

It seems that this is because tokyonight has a custom definition for the Buffer*Sign groups which makes them invisible.

You can fix this by: