Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

An option to turn off show all buffers by default #14

Open
khalidchawtany opened this issue Aug 16, 2021 · 15 comments
Open

An option to turn off show all buffers by default #14

khalidchawtany opened this issue Aug 16, 2021 · 15 comments

Comments

@khalidchawtany
Copy link
Contributor

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.

@kdheepak
Copy link
Owner

kdheepak commented Aug 16, 2021

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 kdheepak reopened this Aug 16, 2021
@khalidchawtany
Copy link
Contributor Author

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.

@kdheepak
Copy link
Owner

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.

@ashincoder
Copy link

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

@kdheepak
Copy link
Owner

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

@ashincoder
Copy link

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

I did wanna disable tabline in 'alpha' filetype.

@kdheepak
Copy link
Owner

kdheepak commented Sep 30, 2021

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.

@ashincoder
Copy link

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.

@rstacruz
Copy link

rstacruz commented Oct 3, 2021

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!

@Mayrixon
Copy link

Mayrixon commented Oct 6, 2021

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.

@escorponox
Copy link

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"...

@lyndhurst
Copy link

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.

@kdheepak
Copy link
Owner

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.

@lyndhurst
Copy link

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

@asyncee
Copy link

asyncee commented Jul 12, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants