sponsor Vim development Vim logo Vim Book Ad

smoothPageScroll.vim : smooth page scroll

 script karma  Rating 20/8, Downloaded by 1427  Comments, bugs, improvements  Vim wiki

created by
Hosup Chung
 
script type
utility
 
description
Yet another smooth page scroll implementation.
I found scrolling the number of winheight() is not always correct, because the file could have wrapped lines. Let's say if your window height is 40, but you only see 35 actual lines because you have 5 wrapped lines. Then by scrolling the number of winheight(), 5 lines would be over-scrolled. This script won't skip the extra lines for having wrapped lines.

This script also emualtes one of VIM's normal <PageDown> or <PageUp> behaviors: which is to display first or last 2 lines from the previous screen after scrolling, unless it reaches first or last line, or the current window is showing 3 lines or less.

See other implementation - vimscript #1601, :help scroll-smooth
 
install details
Install:
Copy this script in your plugin directory

Usage:
1) call them directly
:call SmoothPageScrollDown() to scroll page down
:call SmoothPageScrollUp() to scroll page up

2) or remap <PageDown> and <PageUp>
map <PageDown> :call SmoothPageScrollDown()<CR>
map <PageUp>   :call SmoothPageScrollUp()<CR>

Personally, I remapped <Space> and <S-Space> keys, since <Space> in non-insert mode is not that useful (just move the cursor one position right). And many programs such as web browsers or acrobat reader use space key to scroll page.
map <Space>   :call SmoothPageScrollDown()<CR>
map <S-Space> :call SmoothPageScrollUp()<CR>

But remapping <S-Space> may not work on certain console or platform. So you might have to find another candidate, such as <M-Space>, <C-Space> or something else.

If the scrolling speed is too fast, you can delay scrolling speed more by adding g:smooth_page_scroll_delay in your [._]vimrc. Following line will delay extra 5 milliseconds per each line.

let g:smooth_page_scroll_delay = 5
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
smoothPageScroll.vim 0.20 2008-03-10 6.0 Hosup Chung added a function to delay scroll speed
smoothPageScroll.vim 0.13 2008-03-07 6.0 Hosup Chung temporary fix for infinite scrolling attempt on folded line
smoothPageScroll.vim 0.12 2008-03-07 6.0 Hosup Chung fixed problem of not scrolling at long single line
smoothPageScroll.vim 0.11 2008-03-06 6.0 Hosup Chung Smooth page scroll
ip used for rating: 3.17.162.247

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github