Update
kakoune-smooth-scroll is now updated to support many more keys by default, including for searching and selection rotation, and movements through goto
and object
modes.
If you were using it before and you use default movement keys, you can remove the old configuration and enable it per window with smooth-scroll-enable
. You can check out the README for automatically enabling it for all windows. Also if you remap default keys (e.g. if you adapted your mappings for Dvorak/Colemak etc.) or if you are not happy with the default behavior, configuration options are described in the README to support customizing keybindings.
Any feedback is welcome regarding improving the configuration or any issues you might have.
Original post
Hi folks, even though it is a bit frivolous, something I have been missing since switching from Vim to Kakoune has been a smooth scrolling implementation, specifically something like vim-smooth-scroll. It didn’t look trivial to implement with Kakoune’s approach to plugins. I have been working on it on the side, tried a few different ways it could be done and it has been a decent learning experience.
I very naively started with printing scroll keys in a execute-keys
block, which obviously didn’t work since it waits the shell expansion in its argument to finish before executing the keys. Then I discovered sending keys to the server through kak -p
inside a %sh
block, which also led me to discover how to not block Kakoune by using the >/dev/null 2>&1 </dev/null &
trick, like in the make
and grep
implementations. This was a workable solution however it turned out a bit too slow for smooth scrolling, since the 3 process calls I made in the main loop took about 10-15ms per scroll tick.
After asking in IRC if there is a kak -p
-like pipe that I can send commands to so I don’t have to invoke it every time (apparently there isn’t), mawww pointed me to Kakoune’s remote API which has a pretty simple protocol using Unix sockets. So I wrote a Python script that uses this API to send the scrolling events, which resolved the performance issue.
Then for fun, I also added a physics-based scrolling implementation with constant friction which is present in some Vim plugins like comfortable-motion.vim. I initially thought it was a gimmick but it kind of grew on me as I used it.
Today I packaged my implementation and put it up here, if anyone else’s interested: GitHub - caksoylar/kakoune-smooth-scroll: Smooth scrolling for Kakoune with inertial movement. Below is the screencast from the README showing the smooth scrolling behavior:
I also have a pure sh
implementation in the plugin using kak -p
that is used as a fallback in case Python 3.6+ isn’t available. Since the Python implementation uses an internal API it is not guaranteed to keep the same interface or even exist in the future. For that reason I am not super comfortable using it in a public plugin, but let me know if you have any comments.
If in the future we get timer hooks in Kakoune it should be possible to implement this plugin in a performant way without resorting to the remote API.-