Open pablospe opened 8 years ago
Plop this in your .vimrc! Just change your scrolling settings This works for folds as well, that's why I count line numbers with normal k and normal j
"Smooth scroll {
nnoremap <silent> <c-u> :call smooth_scroll#up(&scroll, 5, 2)<CR>
nnoremap <silent> <c-d> :call smooth_scroll#down(&scroll, 5, 2)<CR>
nnoremap <silent> <c-b> :call smooth_scroll#up(&scroll*2, 3, 4)<CR>
nnoremap <silent> <c-f> :call smooth_scroll#down(&scroll*2, 3, 4)<CR>
" Change these to your scrolling settings
let g:smooth_scroll_duration = 3
let g:smooth_scroll_speed = 4
" Extra Smooth scrolling {
nnoremap <silent> zz :call Smoothzz()<CR>
function! Smoothzz()
let s:origLine = line(".")
let s:origCurs = col(".")
let s:absTop = line("w0")
" count visble difference to top
let s:visTopDif = 0
while (line('.') > s:absTop )
normal 1k
let s:visTopDif = s:visTopDif + 1
endwhile
let s:visCenter = winheight(".") /2
let s:visDifToCenter = s:visCenter - s:visTopDif
if (s:visDifToCenter > 0) "scroll up by the #visiblelines & return
let s:arglist = [s:visDifToCenter, g:smooth_scroll_duration, g:smooth_scroll_speed]
call call(function('smooth_scroll#up'), s:arglist)
else
let s:arglist = [s:visDifToCenter*-1, g:smooth_scroll_duration, g:smooth_scroll_speed]
call call(function('smooth_scroll#down'), s:arglist)
endif
call cursor(s:origLine, s:origCurs)
endfunction
nnoremap <silent> zt :call Smoothzt()<CR>
function! Smoothzt()
let s:curLine = line(".")
let s:curCurs = col(".")
let s:absTop = line("w0")
let s:visTopDif = 0
while (line('.') > s:absTop )
normal 1k
let s:visTopDif = s:visTopDif + 1
endwhile
let s:arglist = [s:visTopDif+3, g:smooth_scroll_duration, g:smooth_scroll_speed]
call call(function('smooth_scroll#down'), s:arglist)
call cursor(s:curLine, s:curCurs)
endfunction
nnoremap <silent> zb :call Smoothzb()<CR>
function! Smoothzb()
let s:curLine = line(".")
let s:curCurs = col(".")
let s:absTop = line("w0")
let s:visTopDif = 0
" counts difference to top
while (line('.') > s:absTop )
normal 1k
let s:visTopDif = (s:visTopDif + 1)
endwhile
let s:visBotDif = winheight(".") - s:visTopDif
let s:arglist = [s:visBotDif+3, g:smooth_scroll_duration, g:smooth_scroll_speed]
call call(function('smooth_scroll#up'), s:arglist)
call cursor(s:curLine, s:curCurs)
endfunction
"}
"}
@Gwatcha solution works great! it would be cool to merge it into the plugin
A possible improvement would be to apply the same smooth scrolling to the zz, zt, zb. How could this be implemented?