-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vim-bufferline integration #36
Comments
How about the following config? let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'filename' ], [ 'bufferline' ] ],
\ },
\ 'component': {
\ 'bufferline': '%{bufferline#refresh_status()}%{g:bufferline_status_info.before . g:bufferline_status_info.current . g:bufferline_status_info.after}'
\ }
\ } |
To change the color: \ 'bufferline': '%{bufferline#refresh_status()}%{g:bufferline_status_info.before}%#TabLineSel#%{g:bufferline_status_info.current}%#LightLineLeft_active_3#%{g:bufferline_status_info.after}' |
Cool, thanks for the quick reply! Didn't think about looking at other functions in in bufferline. It is also quite appearant that using your model makes it much easier to configure things like this yourself, both for you as the developer of lightline as you don't have to care about other plugins, and for the user since you have the full power to change it to whatever you like. The only "downside" is that my .vimrc is growing a lot. Ultimately I would like it to replace the filename when applicable (i.e. not when using ctrlp/nerdtree or whatever), and to blend in with the background if not used, so not with []. Somewhat like the demo for vim-airline I guess, but with the colors respecting the background/colorscheme of lightline (which btw is so so easy to edit!). I don't have time to take a look at it right now, so if you're fine with it I'd like to keep this issue open so I can resolve it when I get it to work as described, or post questions if I have. Thanks again for your great work! |
Yeah, "downside", exactly. You want to change the foreground color conditionally (when the selected buffer is modified)? |
I don't have a big problem with having a lot in my The first example works pretty well, but it would be nice to arbitrarily change the background/foreground color as you like. If included in the group for filename I think it gets too much focus: Adding it to the middle (left) it looks much better, and this is what I currently use and and I'm happy just using this. However what if you want current to have another foreground color instead of brackets? I tried adding I guess it's because this is run before bufferline is ready/run, but not sure how to solve that. Additionally not sure how one would add colors if using it as a function as such. How would I go about writing the bufferline component as a function? I can post more information if needed (don't want this to be too much of a tl;dr). It also needs some function for automatically collapse/resize/hide when the window is too small. If I could get a component function for bufferline to work I could just check the window width ( For reference; current lightline configuration: http://bpaste.net/show/HtlhenF5BgGEMTHT6gAb/ |
You should look into the document of bufferline more carefully. let g:bufferline_active_buffer_left = ''
let g:bufferline_active_buffer_right = '' You got an error that You can define the bufferline component as a function using the following config. let g:lightline = {
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'filename' ], ['bufferline'] ],
\ },
\ 'component_function': {
\ 'bufferline': 'MyBufferline'
\ }
\ }
function! MyBufferline()
call bufferline#refresh_status()
let b = g:bufferline_status_info.before
let c = g:bufferline_status_info.current
let a = g:bufferline_status_info.after
return b . c . a
endfunction But you cannot change the color of the current buffer from a component function. \ 'bufferline': '%{bufferline#refresh_status()}%{g:bufferline_status_info.before}'.
\ '%#TabLineSel#%{g:bufferline_status_info.current}'.
\ '%#LightLineLeft_active_3#%{g:bufferline_status_info.after}' If you want to collapse the component based on the window size, use the following config. function! MyBufferline()
call bufferline#refresh_status()
let b = g:bufferline_status_info.before
let c = g:bufferline_status_info.current
let a = g:bufferline_status_info.after
let alen = strlen(a)
let blen = strlen(b)
let clen = strlen(c)
let w = winwidth(0) * 4 / 9
if w < alen+blen+clen
let whalf = (w - strlen(c)) / 2
let aa = alen > whalf && blen > whalf ? a[:whalf] : alen + blen < w - clen || alen < whalf ? a : a[:(w - clen - blen)]
let bb = alen > whalf && blen > whalf ? b[-(whalf):] : alen + blen < w - clen || blen < whalf ? b : b[-(w - clen - alen):]
return (strlen(bb) < strlen(b) ? '...' : '') . bb . c . aa . (strlen(aa) < strlen(a) ? '...' : '')
else
return b . c . a
endif
endfunction |
Still, you want to fulfil the both desire, change return statements of the MyBufferline function to return [(strlen(bb) < strlen(b) ? '...' : '') . bb, c, aa . (strlen(aa) < strlen(a) ? '...' : '')]
else
return [b, c, a]
endif and define the bufferline component as \ 'component': {
\ 'bufferline': '%{bufferline#refresh_status()}%{MyBufferline()[0]}'.
\ '%#TabLineSel#%{g:bufferline_status_info.current}'.
\ '%#LightLineLeft_active_3#%{MyBufferline()[2]}'
\ }, |
Really appriciate your quick and extensive responses, thanks! |
OK. I'm a student, too and I understand lots of work makes us busy weekdays. |
Great, thanks! |
Hello? |
Hi, really sorry for the delay. I had a hard time finding time to really sit down and take a proper look at your answer for the longest time. It wasn't my intention to ignore your help, because I really do appriciate it! The missing Now, the collapsing works really well, the use of "..." was a good fix. Pretty much a drop-in replacement to my own configuration. I did have to change the calculation of when to collapse it according to the window with because I also have the Git branch displayed for some files, e.g. However the bufferline (tabline) highlighting seems to be somewhat borked. I think I'm going to settle with just using brackets anyway because it's cleaner. But not really sure why the use of tabline would not work so you might want to look into that. Here is the configuration I used when getting this bug (just your example configuration combined with mine). If you can't reproduce it I can see if I can help you further with it. My current configuration can be found in this version. Thanks for the help! |
Use |
Oh, it was that simple. Got it, might be handy if I change my mind. |
…k as expected (close itchyny#155, related: itchyny#36, itchyny#89)
Ref: #155 (comment) |
How would I go about integrating vim-bufferline to my statusline, somewhat similar to what is done in vim-airline?
I found a part about statusline integration, but not really sure how to do this for lightline so it updates when needed etc.
It doesn't have to change the background if selected and all that jazz, but being able to change the frontground and/or background color of the chosen buffer would definitely be a bonus.
I'd like to note that I like idea with lightline where usage of other plugins should be defined by the user instead letting the plugin do the "magic" or "hiding" it all in the plugin as is done in (vim-)powerline and airline. However adding things like the bufferline seems to be a bit tricky unless you're quite comfortable in vimscript.
The text was updated successfully, but these errors were encountered: