Code Monkey home page Code Monkey logo

Comments (7)

astier avatar astier commented on May 20, 2024 1

Thank you. It works. Bufferline is perfect now haha. You can close this issue if you want.

from bufferline.nvim.

astier avatar astier commented on May 20, 2024

So I figured out that bufferline depends in a weird way on the showtabline setting. I partially achieved my goal with the following autocmd:

autocmd group vimenter,bufadd * if len(getbufinfo({'buflisted':1})) > 1 | set showtabline=2
autocmd group bufdelete * if len(getbufinfo({'buflisted':1})) < 2 | set showtabline=1

The first autocmd works. It I open nvim with only one buffer the bufferline is not shown. It I then open a second buffer the bufferline is shown.

The second autocmd does not work for some reason. If I close the second buffer then the bufferline is still shown. If I then set manually set showtabline=1 it isnt shown anymore.

from bufferline.nvim.

astier avatar astier commented on May 20, 2024

Minimal vimrc

set runtimepath+=~/.local/share/nvim/plugins/nvim-bufferline.lua/
autocmd bufadd,vimenter * if len(getbufinfo({'buflisted':1})) > 1 | set showtabline=2 | endif
autocmd bufdelete * if len(getbufinfo({'buflisted':1})) < 2 | set showtabline=1 | endif
lua require'bufferline'.setup()
set showtabline=1

For some reason it doesn't work if I put set showtabline=1 before lua require'bufferline'.setup()

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

@astier thanks for trying out the plugin 👍🏿 .
I use the showtabline function primarily because it's the only way in vim to specify tabline visibility even though it was originally intended for use with tabs rather than buffers so the showtabline setting doesn't really apply in the same way. 2 makes it show all the time and 1 makes it show if there are 2 or more tab pages rather than buffers specifically.

To add something like that it would need to have specific logic. Tbh I personally don't think I'd ever use such an option but if you'd like to have a go at implementing it I'd be fine with that, if it didn't add too much complexity.

I think re implementation you'd need to pass in another option in the user config passed to the setup and then register some autocommands to watch BufEnter (or something) and check the bufferlist and if it's ever less than 2 then hide the line by setting showtabline=0

from bufferline.nvim.

astier avatar astier commented on May 20, 2024

I find it just weird that I am able to toggle bufferline by setting showtabline manually. However, it doesn't work with the bufdelete autocmd. Do you have a clue why? I understand how showtabline works and its purpose. If it would work with the bufdelete autocmd the issue would be pretty much fixed.

Or maybe it would be easier to offer a command to toggle the bufferline. Then instead of changing showtabline I would call the command with the autocmds.

from bufferline.nvim.

astier avatar astier commented on May 20, 2024

Also I think my proposed solution would be very consistent. Since showtabline is by default 1 and will only be set to 2 if a second buffer is added bufferline would show up if:

  • 1 buffer open, 2+ tabs open
  • 2+ buffers open, 1 tab open
  • 2+ buffers open, 2+ tabs open

Since the bufdelete-autocmd would set showtabline back to 1 bufferline would always disappear if:

  • 1 buffer open, 1 tab open

This would be my expected behavior. The only problem is for some reason bufferline does ignore showtabline if it is set after bufdelete.

from bufferline.nvim.

akinsho avatar akinsho commented on May 20, 2024

@astier the issue with the autocommands you posted is that BufDelete is called before the buffer is actually deleted. so the buffer list number will still be greater than 1. A way that I managed to get it to work is by tweaking you autocommand a little

" I minus the list length by one since it's going to be one down once the buffer is actually deleted
" alternatively you could just add an else clause to your BufEnter autocommand
autocmd BufDelete * if len(getbufinfo({'buflisted':1})) -1 < 2 | set showtabline=1 | endif

lightline bufferline uses a similar solution

Regarding an option within the plugin itself your proposed solution looks fine as long as it still behaves the same way it currently does by default, I'd much rather this was an opt in feature.

from bufferline.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.