Friday, December 30, 2011

Smooth Scrolling in Vim

I have been working on a script to allow smooth scrolling in Vim. I
got it working pretty well, even with a variable pause in between
steps (currently set to speed up for the first 80% of iterations, and
then slow down at the end). I am happy with the result for the most
part, but have an issue with the speed of the scroll especially when
the window is maximized on slow machines. Right now, I am only
setting a delay between steps of 5ms, but it still is taking a bit of
time with 0. I was wondering if there were any ideas of anything I
can be doing differently to get it sped up.

" Smooth Scrolling
nnoremap <c-d> :call DelayedFunc("normal! gjzz",winheight(".")/
2-1,5)<cr>
nnoremap <c-u> :call DelayedFunc("normal! gkzz",winheight(".")/
2-1,5)<cr>

func! DelayedFunc(cmd,...)
" cmd , iter , delay
let iter=10
let delay=20
if a:0 == 2
let iter = a:1
let delay = a:2
endif
let i = 0
" first section
let ot = iter/5*4
let start = range(100,0,eval(-100/(ot-1)))
" second section
let tt = iter - ot
let end = range(0,100,eval(100/(tt-1)))
" list of speeds
let speed = start + end
if a:cmd != ""
while i < iter
execute a:cmd
try
exec "sleep " . eval(delay*speed[i]/100) . "m"
catch *
endtry
let i = i + 1
redraw
endwhile
endif
endfunc

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment