By default, Neoscroll uses linear easing. You can provide a different easing function to setup() or directly to a scroll()/helper call to make the start and end of animations more natural.
Supported Easing Functions:
linear, quadratic, cubic, quartic, quintic, circular, sine.
Example usage with custom easing:
neoscroll = require('neoscroll')
neoscroll.setup({
easing = "quadratic"
})
local keymap = {
["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250; easing = 'sine' }) end;
["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250; easing = 'sine' }) end;
["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450; easing = 'circular' }) end;
["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450; easing = 'circular' }) end;
["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor=false; duration = 100 }) end;
["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor=false; duration = 100 }) end;
}
local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
vim.keymap.set(modes, key, func)
end
neoscroll = require('neoscroll')
neoscroll.setup({
-- Default easing function used in any animation where
-- the `easing` argument has not been explicitly supplied
easing = "quadratic"
})
local keymap = {
-- Use the "sine" easing function
["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250; easing = 'sine' }) end;
["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250; easing = 'sine' }) end;
-- Use the "circular" easing function
["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450; easing = 'circular' }) end;
["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450; easing = 'circular' }) end;
-- When no value is passed the `easing` option supplied in `setup()` is used
["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor=false; duration = 100 }) end;
["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor=false; duration = 100 }) end;
}
local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
vim.keymap.set(modes, key, func)
end