├── LICENSE ├── README.md ├── autoload └── winsbar.vim ├── plugin └── winsbar.vim └── winsbar.gif /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Naruhiko Nishino 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 | 2 | # vim-winsbar 3 | 4 | This plugin provides that each window has a scrollbar. 5 | 6 | ![](https://raw.githubusercontent.com/rbtnn/vim-winsbar/master/winsbar.gif) 7 | 8 | ## Requirements 9 | 10 | * Vim only. Does not support Neovim 11 | * Vim must be compiled with `+popupwin` 12 | 13 | ## Installation 14 | 15 | This is an example of installation using [vim-plug](https://github.com/junegunn/vim-plug). 16 | 17 | ``` 18 | Plug 'rbtnn/vim-winsbar' 19 | ``` 20 | 21 | ## License 22 | 23 | Distributed under MIT License. See LICENSE. 24 | -------------------------------------------------------------------------------- /autoload/winsbar.vim: -------------------------------------------------------------------------------- 1 | 2 | let s:prev_args = get(s:, 'prev_args', []) 3 | let s:prev_winids = get(s:, 'prev_winids', []) 4 | let s:prev_timer = get(s:, 'prev_timer', -1) 5 | let s:prev_localtime = get(s:, 'prev_localtime', 0) 6 | 7 | function! winsbar#enabled() abort 8 | if has('popupwin') 9 | if -1 != s:prev_timer 10 | call timer_stop(s:prev_timer) 11 | endif 12 | let s:prev_timer = timer_start(100, function('s:timer_handler'), #{ repeat: -1 }) 13 | endif 14 | endfunction 15 | 16 | function! s:popup_create(w_height, w_winrow, size, col, line, highlight) abort 17 | let diff = (a:size + a:line) - a:w_height 18 | if 0 > diff 19 | let diff = 0 20 | endif 21 | return popup_create(repeat([' '], a:size - diff), #{ 22 | \ minheight: a:size - diff, 23 | \ maxheight: a:size - diff, 24 | \ col: a:col, 25 | \ line: a:line + a:w_winrow, 26 | \ highlight: a:highlight, 27 | \ pos: 'topleft', 28 | \ border: [0, 0, 0, 0], 29 | \ }) 30 | endfunction 31 | 32 | function! s:tabsidebar_size() abort 33 | if has('tabsidebar') 34 | if (&showtabsidebar == 2) || (&showtabsidebar == 1 && 1 < tabpagenr('$')) 35 | return &tabsidebarcolumns 36 | endif 37 | endif 38 | return 0 39 | endfunction 40 | 41 | function! s:set_scrollbar_in_window(w_topline, w_winrow, w_wincol, w_width, w_height, b_linecount) abort 42 | let winids = [] 43 | let winsbar_highlights = get(g:, 'winsbar_highlights', ['PmenuSbar', 'PmenuThumb']) 44 | let col = a:w_wincol + a:w_width + s:tabsidebar_size() 45 | let n = 1.0 * a:b_linecount / a:w_height 46 | let pos = float2nr(a:w_topline / n) 47 | let size = float2nr(a:w_height / n) + 1 48 | if a:w_topline == 1 && a:w_height >= a:b_linecount 49 | let pos = 0 50 | let size = a:w_height 51 | endif 52 | if size > a:w_height 53 | let size = a:w_height 54 | endif 55 | let x = a:w_height - pos - size 56 | if pos > 0 57 | let winids += [s:popup_create(a:w_height, a:w_winrow, pos, col, 0, winsbar_highlights[0])] 58 | endif 59 | if size > 0 60 | let winids += [s:popup_create(a:w_height, a:w_winrow, size, col, pos, winsbar_highlights[1])] 61 | endif 62 | if x > 0 63 | let winids += [s:popup_create(a:w_height, a:w_winrow, x, col, pos + size, winsbar_highlights[0])] 64 | endif 65 | return winids 66 | endfunction 67 | 68 | function! s:timer_handler(timer) abort 69 | let m = mode() 70 | if ('n' == m) || ('i' == m) 71 | let args = [] 72 | for w in getwininfo() 73 | if tabpagenr() == w['tabnr'] 74 | let args += [[ 75 | \ w['topline'], w['winrow'], w['wincol'], w['width'], w['height'], 76 | \ getbufinfo(w['bufnr'])[0]['linecount'] 77 | \ ]] 78 | endif 79 | endfor 80 | let no_scrolling = (s:prev_args == args && empty(s:prev_winids)) 81 | if (s:prev_args != args) || no_scrolling 82 | for winid in s:prev_winids 83 | call popup_close(winid) 84 | endfor 85 | let s:prev_winids = [] 86 | if (1 < localtime() - s:prev_localtime) || no_scrolling 87 | for xs in args 88 | let s:prev_winids += call(function('s:set_scrollbar_in_window'), xs) 89 | endfor 90 | let s:prev_localtime = localtime() 91 | endif 92 | let s:prev_args = args 93 | endif 94 | endif 95 | endfunction 96 | 97 | -------------------------------------------------------------------------------- /plugin/winsbar.vim: -------------------------------------------------------------------------------- 1 | 2 | let g:loaded_winsbar = 1 3 | 4 | augroup winsbar 5 | autocmd! 6 | autocmd VimEnter * :call winsbar#enabled() 7 | augroup END 8 | -------------------------------------------------------------------------------- /winsbar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rbtnn/vim-winsbar/45355911653d3a7831a719fb1c8261288b419fa9/winsbar.gif --------------------------------------------------------------------------------