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

[request]: multi modular plugins. [bug]: BarbarDisable

Open juanMarinero opened this issue 6 months ago • 0 comments

bufferline.nvim explains in Why this and not Vim tabs? the not Vim default approach to buffers and tabs. I guess barbar uses same approach.

Closing buffers might not be desired:

Maybe this was discussed in v2.0.0 Tracking Issue #394 or among private chats (btw. dear reader, collab is needed: #227).

I do like the Vim way actually, I like hidden buffers not occupying any tab but hanging in their [hidden] bufferlist, so I can reopen any time just checking the bufflist. Thus I don't think this plugin is for me. But some features are really awesome, like BufferPick and the git/diagnostic symbols in each tap. So, I wonder:

  • [ ] Any plans to make this plugin modular? I mean, I guess some features like those two above do not require to discard hidden buffers (aka work with tabs as buffers), a nvim user could just load the desired modules.
  • [ ] How to toggle this plugin? I tried GIF steps below to just take advantage of the BufferPick but BarbarDisable overwrites the tab where I was before the jump.

Image

Initially, with plugin disabled, or after run BarbarEnable-BufferPick

:buffers                                         
  1 %a   "model/model01.rb"              
  2  a   "model/model01.java"              
  3  a   "model/model01.log"
  4  a   "model/model01.csv"

Image

Image

but after BarbarDisable

:buffers   
  1 #h   "model/model01.rb"
  2  a   "model/model01.java"
  3  a   "model/model01.log"
  4 %a   "model/model01.csv"

Image

If above works maybe I can code alike next to just take advantage of BufferPick when needed. Of course if another plugin achieves just this (easy jumping to tabs), without conflicting with the Vim's way to treat buffers, then I would love to hear from them please.

-- Update mappings (global)
function _G.Barbar_close_mapping()
  -- Remove existing mapping first to avoid duplicates
  vim.keymap.del('n', '<C-E>')
  -- Set new mapping based on state
  vim.keymap.set('n', '<C-E>', 
    _G.barbar_enabled and '<Cmd>BufferClose<CR>' or '<Cmd>q<CR>',
    { noremap = true, silent = true }
  )
end
function _G.Barbar_pick_tab()
  -- Remove existing mapping first to avoid duplicates
  vim.keymap.del('n', '<leader>gt')
  -- Set new mapping based on state
  vim.keymap.set('n', '<leader>gt', 
    -- https://github.com/junegunn/fzf.vim
    _G.barbar_enabled and '<Cmd>BufferPick<CR>' or '<Cmd>Buffers<CR>',
    { noremap = true, silent = true }
  )
end
function _G.Barbar_move_to_tab()
  -- Remove existing mapping first to avoid duplicates
  vim.keymap.del('n', 'gr')
  vim.keymap.del('n', 'gt')
  -- Set new mapping based on state
  vim.keymap.set('n', 'gr', _G.barbar_enabled and '<Cmd>BufferPrevious<CR>' or '<Cmd>execute "normal! gT"<CR>',
    { noremap = true, silent = true })
  vim.keymap.set('n', 'gt', _G.barbar_enabled and '<Cmd>BufferNext<CR>'     or '<Cmd>execute "normal! gt"<CR>',
    { noremap = true, silent = true })
end
function _G.Barbar_remaps()
  _G.Barbar_close_mapping()
  _G.Barbar_pick_tab()
  _G.Barbar_move_to_tab()
end
-- Initial setup
_G.Barbar_remaps()

-- Ensure state and maps update
vim.api.nvim_create_user_command('BarbarEnableCustome', function()
  vim.cmd('BarbarEnable')  -- Call original command
  _G.barbar_enabled = true
  _G.Barbar_remaps()
end, {})
vim.api.nvim_create_user_command('BarbarDisableCustome', function()
  vim.cmd('BarbarDisable')  -- Call original command
  _G.barbar_enabled = false
  _G.Barbar_remaps()
end, {})

_G.barbar_enabled = false -- Debug with `:lua =barbar_enabled`
if not _G.barbar_enabled then
  vim.cmd('BarbarDisable')
end

function _G.Barbar_enable_toggle()
  if _G.barbar_enabled then
    vim.cmd('BarbarDisableCustome')
  else
    vim.cmd('BarbarEnableCustome')
  end
end
vim.keymap.set('n', '<leader>gt!', function() _G.Barbar_enable_toggle() end,
  { noremap = true, silent = true, desc = "Toggle barbar.nvim" })

Thanks in advance!

juanMarinero avatar Jun 29 '25 17:06 juanMarinero