Created
October 11, 2011 11:44
-
-
Save ynkdir/1277884 to your computer and use it in GitHub Desktop.
vim cui scrollbar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" require: term.vim | |
" http://www.vim.org/scripts/script.php?script_id=2812 | |
autocmd CursorMoved,CursorMovedI * call s:update_scrollbar_absolute() | |
" how to get curwin->w_winrow and curwin->w_wincol? | |
function! s:update_scrollbar_absolute() | |
let winline = winline() | |
let wincol = wincol() | |
let winwidth = &columns | |
let winheight = &lines | |
let line = line('.') + 0.0 | |
let lastline = line('$') + 0.0 | |
let percent = float2nr(((line - 1) / lastline) * winheight) | |
let barheight = float2nr(ceil(winheight / lastline)) | |
call term#save_cursor() | |
for i in range(winheight) | |
call term#put(i + 1, winwidth, ' ', (percent <= i && i < percent + barheight) ? 45 : 44) | |
endfor | |
call term#attr() | |
call term#restore_cursor() | |
call term#out() | |
endfunction | |
" buggy | |
function! s:update_scrollbar_relative() | |
" XXX: Since cursor is not drawn yet, update cursor. | |
redraw | |
let winline = winline() | |
let wincol = wincol() | |
let winwidth = winwidth(0) | |
let winheight = winheight(0) | |
let line = line('.') + 0.0 | |
let lastline = line('$') + 0.0 | |
let percent = float2nr(((line - 1) / lastline) * winheight) | |
let barheight = float2nr(ceil(winheight / lastline)) | |
call term#save_cursor() | |
call term#preceding_line(winline - 1) | |
for i in range(winheight) | |
call term#forward(winwidth - 1) | |
call term#text(' ', (percent <= i && i < percent + barheight) ? 45 : 44) | |
call term#next_line() | |
endfor | |
call term#attr() | |
call term#restore_cursor() | |
call term#out() | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment