joeytwiddle / sexy_scroller.vim

smooth animation of the cursor and the page whenever they move, with easing
89 stars 7 forks source link

sexy_scroller.txt Smooth animation of the cursor and the page whenever they move, with easing.

By joeytwiddle, inspired by Terry Ma's smooth_scroll.vim, one of many Ctrl-U/Ctrl-D scrollers.

Not to be confused with daylilyfield/sexyscroll.vim which lacks easing.

I have not yet seen any other smooth-scrolling scripts that provide easing, operate on general movements, or use winrestview instead of keymappings/cursorhold.

Intro

Usually when you scroll the buffer or motion to a different part of the document, Vim will jump there immediately.

But with SexyScroller, Vim will scroll to the new position smoothly. As well as looking pretty, this provides you with visual feedback about the distance and direction in which you have travelled.

Features

Video: http://www.youtube.com/watch?v=7GqJapCcVyE (thanks Yu-Jie Lin)

Options sexy_scroller_options

Instead of specifying the scrolling speed, SexyScroller asks you to specify how slow you want scrolling to be. You can store these options in your .vimrc once you are happy with them.

Set the time it takes (in milliseconds) for the buffer to scroll one line or column.

:let g:SexyScroller_ScrollTime = 10

Set the time it takes for the cursor to travel one line. Probably only visible if you have :set cursorline. Set it to 0 to never animate the cursor.

:let g:SexyScroller_CursorTime = 5

(I like to pretend the cursor is "lighter" than the buffer.)

Set the maximum amount of time that longer scrolls can take:

:let g:SexyScroller_MaxTime = 500

Choose the easing style (how scrolling accelerates and deccelerates):

:let g:SexyScroller_EasingStyle = 2

where

Interrupts the animation if you press a key. Resumes the animation if they key you pressed causes further scrolling, otherwise just jumps directly to the destination. Resuming animation looks best with EasingStyle 1 or 2.

:let g:SexyScroller_DetectPendingKeys = 1   /   0

This command is provided to enable/disable the scrolling:

:SexyScrollerToggle

Power users with fast machines may prefer to lower MaxTime to 200. This will make Vim feel more snappy and responsive.

Users with slower machines may like to increase MaxTime to 400 or 500, and maybe even change the EasingStyle to 1.

For eye candy (e.g. for presentations), try MaxTime=1000, EasingStyle=3 and increase ScrollTime as well. This can help to visualise the distance travelled when moving slowly and smoothly through the document.

If you are frustrated by SexyScroller slowing down mouse scrolling, you can mitigate this issue by increasing the minimum thresholds:

:let g:SexyScroller_MinLines = 50
:let g:SexyScroller_MinColumns = 200

The disadvantage is that if the cursor or the window move less than these distances, SexyScroller will not engage.

The function g:SexyScroller_ScrollToCursor(...) is available as a globally exposed function. If you want to use this, it is useful to disable the cursor movement related autocommands:

:let g:SexyScroller_AutocmdsEnabled = 0

Issues

CONSIDER TODO: Make a list of exclude keys, and map them so that they set w:SexyScroller_Ignore_Next_Movement. For example this could apply to / and ? with 'hlsearch' enabled, and maybe also to d.

CONSIDER TODO: We could optionally enable cursorline whilst scrolling. (Reproducing the functionality of highlight_line_after_jump.vim)

TODO: We should politely store and restore lazyredraw if we are going to continue to clobber it.

vim: wrap textwidth=0 wrapmargin=0 filetype=help