nvim-lualine / lualine.nvim

A blazing fast and easy to configure neovim statusline plugin written in pure lua.
MIT License
5.93k stars 462 forks source link

Feat: Hide the tabline conditionally #395

Open snorkysnark opened 2 years ago

snorkysnark commented 2 years ago

Requested feature

In global options, add a function that is called on redraw to determine whether the tabline should be visible. For example, you can only show it if there is more than one tab/more than one buffer, etc.

require('lualine').setup{
  tabline = {
    ...
  },
  tabline_visible = function()
    return vim.fn.tabpagenr('$') > 1
  end
}

Motivation

Currently, this plugin forces the tabline to be always visible, decreasing the available screen space. Since the option is set during the first redraw, I haven't found a good way to override it with autocmds. As people have different tabline configurations (with buffers and other custom components), you need a more flexible alternative to vim's showtabline=1 (that shows and hides the tabline based on tab count)

shadmansaleh commented 2 years ago

This is an interesting proposal I'll definitely think about it.

You can probably catch the event with OptionSet showtabline

shadmansaleh commented 2 years ago

It seems lualine & neo(vim)s current behavior is limiting for this . Only way I can make tabline not take 1 screenline is by setting showtabline to 0 . But then nvim no longer evaluates ex[ression in &tabline so it gets locked into that state and doesn't get updated to show tabline when condition is true 🤷‍♂️. This does seem like a valid optimization on neo(vim)s part but limits our ability at this . The other way would be to make lualines redraw completely independent of how often statusline/tabline evaluates . I'm not yet sure if that's something worth doing just for this.

If you just want the ability to not have tabline when only one tab is present . Then you can set showtablineto 1 with autocommand. For example:

au OptionSet showtabline :set showtabline=1

You can apply cond option per component in tabline too if you want to hide certain component based on some condition.

isaif commented 2 years ago
au OptionSet showtabline :set showtabline=1

I have tried this and it is working. Thanks.

shadmansaleh commented 2 years ago

For now I'm dropping this idea. As it's too complicated to add for too little gain for now.

amerlyq commented 2 years ago

I wanted to achieve the same effect as airline -- to hide tabline when there is only single buffer:

let g:airline#extensions#tabline#buffer_min_count = 2

But I don't understand how to use your workaround above to achieve the same thing. @shadmansaleh do you have any other suggestion?

Maybe simple corner case of "hide when there is only one buffer/tab" can be much more easily hacked, than the proper solution of "evaluate conditional function inside of tabline" ?

AlxHnr commented 2 years ago

This hack does not work in neovim 0.7.0:

au OptionSet showtabline :set showtabline=1

For some reason OptionSet is not fired when lualine does it. I can set showtabline=1 manually, but when switching colorschemes it reappears. Is there any reason why we can't add an option to simply leave showtabline alone here?

mario-amazing commented 2 years ago

@shadmansaleh, because of not working OptionSet in neovim 0.7.0, can we reopen this feature request?

matheussampaio commented 1 year ago

Maybe an easier approach is to let users control if we want Lualine to set showtabline=2?

If we wrap that in an condition, it would allow users to set showtabline=1 in their config and get the default behavior of only displaying the tabline if at least two tabs exists:

'showtabline' 'stal'    number  (default 1)
            global
    The value of this option specifies when the line with tab page labels
    will be displayed:
        0: never
        1: only if there are at least two tab pages
        2: always
    This is both for the GUI and non-GUI implementation of the tab pages
    line.
    See |tab-page| for more information about tab pages.

How #736 supports hiding the tabline conditionally? I couldn't understand from read the code.

isaif commented 1 year ago

Maybe an easier approach is to let users control if we want Lualine to set showtabline=2?

If we wrap that in an condition, it would allow users to set showtabline=1 in their config and get the default behavior of only displaying the tabline if at least two tabs exists:

I agree that this will be very useful as we can use whatever options vim provides by default. If this worked then we could also hide tabline completely using showtabline=0

mike-lloyd03 commented 1 year ago

I added this after require("lualine").setup(...) and it seems to work as desired:

vim.cmd("set showtabline=1")

But I agree that it would be better if Lualine didn't override the default here: https://github.com/nvim-lualine/lualine.nvim/blob/3cf45404d4ab5e3b5da283877f57b676cb78d41d/lua/lualine.lua#L472