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

An option to turn off show all buffers by default

Open khalidchawtany opened this issue 4 years ago • 15 comments

In each tab I would like to see only the buffers of the current tab. I would like an option to make this the default behaviour.

khalidchawtany avatar Aug 16 '21 09:08 khalidchawtany

Can you define “buffers of a current tab”? Currently, when you run the TablineBuffersBind … command, the file names passed into the command as arguments are stored in a global variable and that is used to keep track of the buffers in the current tab. However, if you open a buffer without using any of the tabline commands that this plugin provides, then there is no way for this plugin to know whether the buffers “belongs” to this tab or not.

There is a TablineTabNew … that does what you are asking by default. You can pass in arguments s file names to bind to that tab. Also there’s a toggle command which you can run manually or after running :tabnew yourself.

Does that help? I’m open to hearing feedback on how to improve the functionality to making it work the way you describe it.

kdheepak avatar Aug 16 '21 13:08 kdheepak

if you open a buffer without using any of the tabline commands that this plugin provides, then there is no way for this plugin to know whether the buffers “belongs” to this tab or not.

Cannot we just hook into BufCreate autocomand and if it does not belong to the list of the current tab buffers then insert it.

I wanted to see all the buffers that were created while this tab was active not the others.

khalidchawtany avatar Aug 16 '21 20:08 khalidchawtany

Yeah, I didn’t think of BufCreate. That’s a good idea. I can add that as a feature.

That still doesn’t help if someone wants to just open a subset of open buffers be sticky in a new separate tab.

kdheepak avatar Aug 16 '21 21:08 kdheepak

@kdheepak is there an option to disable tabline in certain filetypes ?

ashincoder avatar Sep 30 '21 02:09 ashincoder

Not at this point. What did you have in mind?

kdheepak avatar Sep 30 '21 02:09 kdheepak

Not at this point. What did you have in mind?

I did wanna disable tabline in 'alpha' filetype.

ashincoder avatar Sep 30 '21 02:09 ashincoder

You want to disable the entire tabline? Or just the buffers? One easy way to do it would be to create your own custom function that checks for the file type of the current buffer and returns an empty string when needed or calls the default tabline function and returns that output.

kdheepak avatar Sep 30 '21 02:09 kdheepak

You want to disable the entire tabline? Or just the buffers? One easy way to do it would be to create your own custom function that checks for the file type of the current buffer and returns an empty string when needed or calls the default tabline function and returns that output.

entire tabline.

ashincoder avatar Sep 30 '21 03:09 ashincoder

I just found tabline.nvim and thank you so much for creating it! I love how it looks and I never realised how useful it can be until I tried it.

I found that I always do :TablineToggleShowAllBuffers to isolate the buffers shown to only be what's visible in the current tab. It would be nice to make this configurable so I don't have to keep on toggling every time :)

I'm not a big fan of having all buffers visible - when I'm deep into working on a codebase, I may have as much as 30 buffers loaded, but only a handful visible. I would use something like Telescope.nvim to switch buffers instead. What's more useful for me is to have a nice way of organising tabs.

Just sharing my use case, hope it helps understand the need for it!

rstacruz avatar Oct 03 '21 11:10 rstacruz

I tried both tabline.nvim and shadmansaleh/lualine's tabline components, but neither can provide the function as described above. I think vim's command :tabs would be helpful when implementing this function. Using :tabs, vim would list the tab pages and the windows they contain.

Here is Vim's implementaition, and here is Neovim's implementation.

Mayrixon avatar Oct 06 '21 12:10 Mayrixon

I tried this:

augroup TablineBuffers
  autocmd!
  au! TabEnter,BufEnter * lua require('lualine-config').setTablineShowBuffers()
augroup END

and I copied the handler from the repo:

local function setTablineShowBuffers()
  local data = vim.fn.json_decode(vim.g.tabline_tab_data)[vim.fn.tabpagenr()]
  if(data and data.show_all_buffers) then
    vim.cmd('TablineToggleShowAllBuffers')
  end
end

But it doesn't work always. For example when I do "open in new tab"...

escorponox avatar Dec 21 '21 07:12 escorponox

I was looking for the same feature I think the OP was describing, or at least the title of the issue suggests. My workflow is similar to what @rstacruz was describing above.

To clarify, in the current state of the plugin, all buffers are shown in the tabline by default, and, the TablineToggleShowAllBuffers is available to hide buffers (not displayed in a window) from the tabline.

What would be useful to me, would be to have an option that lets me set the opposite as the default. Meaning the tabline skips all "hidden buffers" by default, and the command TablineToggleShowAllBuffers is there to show them if I need to.

This would help me have a "clean" tabline and use some finder like Telescope or Fzf to browse through all open buffers.

Thanks for your time.

lyndhurst avatar Jun 15 '22 14:06 lyndhurst

Unfortunately I'm swamped with personal life obligations and I won't be able to look into this at the moment. I am happy to review a PR, but I suspect I'll only be able to get around to this in a few months.

kdheepak avatar Jun 15 '22 14:06 kdheepak

Thank you for taking the time to answer, and good luck with all your obligations :)

lyndhurst avatar Jun 16 '22 09:06 lyndhurst

I wrote following solution and it is working for me.

local tabline = require("tabline")

tabline.setup({
        enable = true,
        options = {
                -- If lualine is installed tabline will use separators configured in lualine by default.
                -- These options can be used to override those settings.
                max_bufferline_percent = 66, -- set to nil by default, and it uses vim.o.columns * 2/3
                show_tabs_always = false, -- this shows tabs only when there are more than one tab or if the first tab is named
                show_devicons = true, -- this shows devicons in buffer section
                show_bufnr = false, -- this appends [bufnr] to buffer section,
                show_filename_only = true, -- shows base filename only instead of relative path in filename
                modified_icon = "+ ", -- change the default modified icon
                modified_italic = false, -- set to true by default; this determines whether the filename turns italic if modified
                show_tabs_only = false, -- this shows only tabs instead of tabs + buffers
        },
})
vim.cmd([[
    set guioptions-=e " Use showtabline in gui vim
    set sessionoptions+=tabpages,globals " store tabpages and globals in session
]])

local augroup = vim.api.nvim_create_augroup("TablineBuffers", {})

function ShowCurrentBuffers()
        local data = vim.t.tabline_data
        if data == nil then
                tabline._new_tab_data(vim.fn.tabpagenr())
                data = vim.t.tabline_data
        end
        data.show_all_buffers = false
        vim.t.tabline_data = data
        vim.cmd([[redrawtabline]])
end

vim.api.nvim_create_autocmd({ "TabEnter" }, {
        group = augroup,
        callback = ShowCurrentBuffers,
})

Now when I create a new tab then I see only this tab's buffers starting with a single unnamed buffer that is created by default.

asyncee avatar Jul 12 '22 05:07 asyncee