├── LICENSE ├── README.md ├── autoload └── responsive_tabline.vim ├── images └── demo.gif └── plugin └── responsive_tabline.vim /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Takahiro Abe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-responsive-tabline 2 | 3 | ![vim-responsive-tabline demo](https://raw.githubusercontent.com/yami-beta/vim-responsive-tabline/master/images/demo.gif) 4 | 5 | ## Installation 6 | 7 | Use plugin manager 8 | 9 | ### [vim-plug](https://github.com/junegunn/vim-plug) 10 | 11 | ```vim 12 | Plug 'yami-beta/vim-responsive-tabline' 13 | ``` 14 | 15 | ## Option 16 | 17 | If you want manually to enable vim-responsive-tabline, use `g:responsive_tabline_enable` option. 18 | 19 | ```vim 20 | let g:responsive_tabline_enable = 0 21 | set tabline=%!responsive_tabline#get_tabline() 22 | ``` 23 | 24 | If you want to customize tabline's label, use `g:Responsive_tabline_custom_label_func` option. 25 | Note: If you use `g:Responsive_tabline_custom_label_func`, tabpage label is disabled. 26 | 27 | ```vim 28 | function! s:show_buffers_to_tabline() 29 | let buffers = getbufinfo({ 'buflisted': 1 }) 30 | return map(copy(buffers), '{ "active": v:val.bufnr == bufnr("%"), "name": v:val.bufnr." ".fnamemodify(v:val.name, ":t") }') 31 | endfunction 32 | let g:Responsive_tabline_custom_label_func = function('s:show_buffers_to_tabline') 33 | ``` 34 | 35 | ## Known Bugs 36 | 37 | - `E541` is shown in tabline if 20 and over tabpages are created. 38 | - Detail: `:h E541` 39 | 40 | # LICENSE 41 | 42 | MIT 43 | -------------------------------------------------------------------------------- /autoload/responsive_tabline.vim: -------------------------------------------------------------------------------- 1 | if get(g:, 'loaded_autoload_responsive_tabline') 2 | finish 3 | endif 4 | let g:loaded_autoload_responsive_tabline = 1 5 | let s:save_cpo = &cpo 6 | set cpo&vim 7 | 8 | function! s:resize_label(tabpagenr, tabpage_label, tab_width) 9 | let filename = a:tabpage_label.name 10 | let tab_width = str2nr(a:tab_width) 11 | " highlight current tabpage 12 | let hi = a:tabpage_label.active ? '%#TabLineSel#' : '%#TabLine#' 13 | 14 | " `2` means insert a space to before and after label 15 | " e.g. `let label = ' '.filename.' '` 16 | let label_margin = 2 17 | let filename_length = strwidth(filename) + label_margin 18 | if filename_length > tab_width 19 | " Truncate filename 20 | let ellipsis = '...' 21 | let filename = filename[0:(tab_width - strwidth(ellipsis) - label_margin - 1)].ellipsis 22 | else 23 | " Append spacer 24 | let filename = filename . repeat(' ', tab_width - filename_length) 25 | endif 26 | let label = ' ' . filename . ' ' 27 | 28 | " Disable tabpage label if `g:Responsive_tabline_custom_label_func` is `Funcref` 29 | if exists('g:Responsive_tabline_custom_label_func') && type(g:Responsive_tabline_custom_label_func) ==# type(function('tr')) 30 | return hi . label . '%#TabLineFill#' 31 | endif 32 | return '%' . a:tabpagenr . 'T' . hi . label . '%T%#TabLineFill#' 33 | endfunction 34 | 35 | function! s:get_tabline_label(tabline_names) 36 | let width = &columns 37 | let tab_width = float2nr(width / len(a:tabline_names)) 38 | return map(copy(a:tabline_names), 's:resize_label(v:key + 1, v:val, '.tab_width.')') 39 | endfunction 40 | 41 | function! s:get_tabpage_name(tabpagenr) 42 | let tabpage_buflist = tabpagebuflist(a:tabpagenr) 43 | let active_bufnr = tabpage_buflist[tabpagewinnr(a:tabpagenr) - 1] 44 | 45 | let filename = bufname(active_bufnr) 46 | if filename ==# '' 47 | let filename = '[No Name]' 48 | else 49 | let filename = fnamemodify(filename, ':t') 50 | endif 51 | let filename = a:tabpagenr.' '.filename 52 | 53 | let is_active = a:tabpagenr is tabpagenr() 54 | return { 'active': is_active, 'name': filename } 55 | endfunction 56 | 57 | function! s:get_tabline_names() 58 | return map(range(1, tabpagenr('$')), 's:get_tabpage_name(v:val)') 59 | endfunction 60 | 61 | function! responsive_tabline#get_tabline() abort 62 | let Get_tabline_names = get(g:, 'Responsive_tabline_custom_label_func', function('s:get_tabline_names')) 63 | let tabline_names = Get_tabline_names() 64 | let labels = s:get_tabline_label(tabline_names) 65 | let tabpages = join(labels, '') . '%#TabLineFill#%T' 66 | 67 | return tabpages . '%=' 68 | endfunction 69 | 70 | 71 | let &cpo = s:save_cpo 72 | unlet s:save_cpo 73 | -------------------------------------------------------------------------------- /images/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yami-beta/vim-responsive-tabline/089419bedc447ff2d093ff01b732a2bc9c466627/images/demo.gif -------------------------------------------------------------------------------- /plugin/responsive_tabline.vim: -------------------------------------------------------------------------------- 1 | if get(g:, 'loaded_responsive_tabline') 2 | finish 3 | endif 4 | let g:loaded_responsive_tabline = 1 5 | let s:save_cpo = &cpo 6 | set cpo&vim 7 | 8 | let s:enable = get(g:, 'responsive_tabline_enable', 1) 9 | if s:enable 10 | set tabline=%!responsive_tabline#get_tabline() 11 | endif 12 | 13 | let &cpo = s:save_cpo 14 | unlet s:save_cpo 15 | --------------------------------------------------------------------------------