preservim / tagbar

Vim plugin that displays tags in a window, ordered by scope
https://preservim.github.io/tagbar
Other
6.13k stars 488 forks source link

All setting a relative (percent?) width #567

Closed alerque closed 4 years ago

alerque commented 4 years ago

Splitting out a request from user @a-b in #545, it would be nice to be able to set the g:tagbar_width using a relative size instead of an absolute value. Instead of setting the number or characters wide, saying it should be 10% of the current window or something like that would be add flexibility.

raven42 commented 4 years ago

This can be handled in your .vimrc using the g:tagbar_width option. Use something like the following. I have something like this in my config:

let usr_width = winwidth(0) / 4
let usr_min_width = 10    ; minimum window width
let usr_max_width = 80    ; maximum window width
let g:tagbar_width = usr_width > usr_max_width ? usr_max_width : 
        \ usr_width < usr_min_width ? usr_min_width : 
        \ usr_width

This will set a minimum width of 10 so we don't go below that, but a maximum of 80 so we don't go bigger than that. Otherwise it will default to 1/4 of the window width.

Alternatively for a shorter static value, something like this:

let g:tagbar_width = winwidth(0) / 4
raven42 commented 4 years ago

Are we ok closing this issue out with the available option of g:tagbar_width = winwidth(0) / X?

alerque commented 4 years ago

I'm totally fine with that being the solution, but as I recall I ran across this request a couple of places so lets at least document it in brief (even if the documentation is a one-liner linking here).