The main scrolling commands in Vim are:
- Ctrl-B and Ctrl-F, as well as PageUp and PageDown scroll by full page
- Ctrl-U and Ctrl-D scroll half a page by default
- 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 first 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.
Shameless plug, but I created a plugin here that you can use to easily adjust the distance, speed, and duration of the scrolling animation: https://github.com/terryma/vim-smooth-scroll
I just found this plugin called "accelerated-smooth-scroll" ("Vim plugin for accelerated smooth scroll (mapping to
<C-D>/<C-U>
,<C-F>/<C-B>)
") which can be for example used through Vundle by putting this line in your .vimrc:Then by restarting Vim and running the
:PluginInstall
command, then again restart Vim and use the<C-D>
(Ctrl+D) and<C-O>
(Ctrl+O) commands normally.Sadly, this plugin also moves the cursor instead of what I wanted: to just scroll the screen like the
<C-E>
and<C-Y>
commands.A Recent Plugin
I have posted something similar here, but basically there is a great plugin that we can use now for scrolling, called terryma/vim-smooth-scroll. It provides a very nice and smooth scrolling.
The install is quite easy:
1 I use Vundle so I simply appended this in .vimrc.bundles :
In the latest version of Vundle available today, 29th April of 2016, you can put this in your .vimrc:
2 As stated in the doc, you can set up 3 arguments: distance, duration and speed.
I am using this in my .vimrc file:
This isn't exactly smooth scrolling, but it's how I handle not losing context when jumping pages.
set so=7
'scrolloff' 'so' number (default 0) global
{not in Vi}
Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. If you set it to a very large value (999) the cursor line will always be in the middle of the window (except at the start or end of the file or when long lines wrap). For scrolling horizontally see 'sidescrolloff'. NOTE: This option is set to 0 when 'compatible' is set.
What I do is I set the keyboard repeat to very fast, about 120 chars / second, and the delay small. Then I map to 4j and to 4k I navigate up and down source code using j and k which moves the cursor up and down nice and quick, pretty smooth. But here's the good part, and this works on Linux, not Windows. For a number of years now, X11's keyboard input works in such a way that when you press and hold j it obviously starts putting out j characters. But when you then keep holding down j and then also press the ctrl key, X11 starts putting out c-j characters without you having to re-press the j key. Then when you let go of the ctrl key and still keep on pressing j, X11 continues to put j's again. So j makes the cursor start moving nice and smooth downwards, and you can periodically hit ctrl without letting go of j to give it a boost, a jolt.
Also, I do what Devin does, and I set scrolloffset to 5.
Lastly, I swap ctrl and cap lock. The default position of the ctrl key is completely retarded (no offense intended). It makes you have to rotate your left hand. I almost never use caps lock, so I swap them. Then my left pink finger can reach the ctrl key without any yoga moves.
These things have worked for me for years. I only use vim, never gvim.
There is a simple remap hack in vim's tips.txt: