views:

154

answers:

5

The main scrolling commands in VIM are:
1. Ctrl-B and Ctrl-F, as well as PageUp and PageDown scroll by full page
2. Ctrl-U and Ctrl-D scroll half a page by default
3. Ctrl-Y and Ctrl-E scroll one line

I lose visual context every time for the former two, so I have developed the bad habit of hitting the latter (Ctrl-Y and Ctrl-E) repetitively.

Since there is currently no 1st party support for smooth scrolling, what are the least objectionable workarounds/plugins?

I use both vim and gvim depending on the task, and am happy to customize them separately if there is no one really good hack that works for both. The mouse scroll wheel works nicely in gvim, but I'm looking for keyboard based solutions.

A: 

Here is a smooth scroll vim script from 2006:

http://www.vim.org/scripts/script.php?script_id=1601

Drew Wagner
A: 

Here's another vim script from 2008:

http://www.vim.org/scripts/script.php?script_id=2183

Drew Wagner
This script is giving me inconsistent results (i.e. non-smooth, dramatically varying scrolling speed) as well. Not sure what in the display path is creating performance issues. I'm using gvim 7.2 from debian testing.
Drew Wagner
A: 

There is a simple remap hack in vim's tips.txt:

Smooth scrolling                    *scroll-smooth*

If you like the scrolling to go a bit smoother, you can use these mappings:

    :map <C-U> <C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y><C-Y>
    :map <C-D> <C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E><C-E>
Drew Wagner
Why would this be preferable to usng the 'scroll' option setting (e.g., :set scroll=15)? Scroll option seems preferable because you could even create an au command that changes it automatically when window height changes. ( I guess you could do something like that with this mapping method also, but scroll option simplifies things.)
Herbert Sitz
Actually, automatically setting scroll variable is one of the options I was considering too. As you mention, it needs to be appropriate to the window size. The scroll variable defaults to 1/2 the window height, but it doesn't seem to expose a way to change that fraction; you can only change it in terms of the number of lines. You might also have to set a smaller value for scroll than if you also had some sort of smooth scrolling, since your eyes won't have any intermediate scrolled states to improve persistence of vision.
Drew Wagner
Update: I have tried a few variations on this answer, i.e. :map <PageUp> 2<C-Y>2<C-Y>2<C-Y>2<C-Y>2<C-Y>2<C-Y>2<C-Y> :map <PageDown> 2<C-E>2<C-E>2<C-E>2<C-E>2<C-E>2<C-E>2<C-E>and the visual effect seems heavily dependent on how much stuff is on screen. i.e. the speed can vary by something like 4X.
Drew Wagner
To clarify, c-d and c-u will scroll by whatever the 'scroll' option is set to. Default is 1/2 of window height, but you can set it to whatever you want. If you want to make a new value depend on window height then use the 'winheight("%")' function, which returns number of lines in window. So, e.g., the command ':set scroll = winheight("%")/3' would make c-u and c-d scroll 1/3 of window height.
Herbert Sitz