fix: neoscroll mappings

This commit is contained in:
Sayantan Santra 2024-09-05 15:41:54 +02:00
parent 03dbb48603
commit fb52609b7a
Signed by: SinTan1729
GPG key ID: EB3E68BFBA25C85F
3 changed files with 57 additions and 52 deletions

View file

@ -1,7 +1,9 @@
local neoscroll = require("neoscroll")
-- Keep cursor away from the edges -- Keep cursor away from the edges
vim.opt.scrolloff = 8 vim.opt.scrolloff = 8
require("neoscroll").setup({ neoscroll.setup({
-- All these keys will be mapped to their corresponding default scrolling animation -- All these keys will be mapped to their corresponding default scrolling animation
mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>', mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>',
'<C-y>', '<C-e>', 'zt', 'zz', 'zb' }, '<C-y>', '<C-e>', 'zt', 'zz', 'zb' },
@ -16,20 +18,19 @@ require("neoscroll").setup({
easing_function = "quadratic", -- Default easing function easing_function = "quadratic", -- Default easing function
}) })
local t = {} local keymap = {
-- Syntax: t[keys] = {function, {function arguments}} ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250 }) end,
-- Use the "sine" easing function ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250 }) end,
t['<C-u>'] = { 'scroll', { '-vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450 }) end,
t['<C-d>'] = { 'scroll', { 'vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450 }) end,
-- Use the "circular" easing function ["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor = false, duration = 100 }) end,
t['<C-b>'] = { 'scroll', { '-vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor = false, duration = 100 }) end,
t['<C-f>'] = { 'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["zt"] = function() neoscroll.zt({ half_win_duration = 250 }) end,
-- Pass "nil" to disable the easing animation (constant scrolling speed) ["zz"] = function() neoscroll.zz({ half_win_duration = 250 }) end,
t['<C-y>'] = { 'scroll', { '-0.10', 'false', '100', nil } } ["zb"] = function() neoscroll.zb({ half_win_duration = 250 }) end,
t['<C-e>'] = { 'scroll', { '0.10', 'false', '100', nil } } }
-- When no easing function is provided the default easing function (in this case "quadratic") will be used
t['zt'] = { 'zt', { '300' } }
t['zz'] = { 'zz', { '300' } }
t['zb'] = { 'zb', { '300' } }
require('neoscroll.config').set_mappings(t) local modes = { 'n', 'v', 'x' }
for key, func in pairs(keymap) do
vim.keymap.set(modes, key, func)
end

View file

@ -1,7 +1,9 @@
local neoscroll = require("neoscroll")
-- Keep cursor away from the edges -- Keep cursor away from the edges
vim.opt.scrolloff = 8 vim.opt.scrolloff = 8
require("neoscroll").setup({ neoscroll.setup({
-- All these keys will be mapped to their corresponding default scrolling animation -- All these keys will be mapped to their corresponding default scrolling animation
mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>', mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>',
'<C-y>', '<C-e>', 'zt', 'zz', 'zb' }, '<C-y>', '<C-e>', 'zt', 'zz', 'zb' },
@ -16,20 +18,20 @@ require("neoscroll").setup({
easing_function = "quadratic", -- Default easing function easing_function = "quadratic", -- Default easing function
}) })
local t = {} local keymap = {
-- Syntax: t[keys] = {function, {function arguments}} ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250 }) end,
-- Use the "sine" easing function ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250 }) end,
t['<C-u>'] = { 'scroll', { '-vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450 }) end,
t['<C-d>'] = { 'scroll', { 'vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450 }) end,
-- Use the "circular" easing function ["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor = false, duration = 100 }) end,
t['<C-b>'] = { 'scroll', { '-vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor = false, duration = 100 }) end,
t['<C-f>'] = { 'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["zt"] = function() neoscroll.zt({ half_win_duration = 250 }) end,
-- Pass "nil" to disable the easing animation (constant scrolling speed) ["zz"] = function() neoscroll.zz({ half_win_duration = 250 }) end,
t['<C-y>'] = { 'scroll', { '-0.10', 'false', '100', nil } } ["zb"] = function() neoscroll.zb({ half_win_duration = 250 }) end,
t['<C-e>'] = { 'scroll', { '0.10', 'false', '100', nil } } }
-- When no easing function is provided the default easing function (in this case "quadratic") will be used
t['zt'] = { 'zt', { '300' } } local modes = { 'n', 'v', 'x' }
t['zz'] = { 'zz', { '300' } } for key, func in pairs(keymap) do
t['zb'] = { 'zb', { '300' } } vim.keymap.set(modes, key, func)
end
require('neoscroll.config').set_mappings(t)

View file

@ -1,7 +1,9 @@
local neoscroll = require("neoscroll")
-- Keep cursor away from the edges -- Keep cursor away from the edges
vim.opt.scrolloff = 8 vim.opt.scrolloff = 8
require("neoscroll").setup({ neoscroll.setup({
-- All these keys will be mapped to their corresponding default scrolling animation -- All these keys will be mapped to their corresponding default scrolling animation
mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>', mappings = { '<C-u>', '<C-d>', '<C-b>', '<C-f>',
'<C-y>', '<C-e>', 'zt', 'zz', 'zb' }, '<C-y>', '<C-e>', 'zt', 'zz', 'zb' },
@ -16,20 +18,20 @@ require("neoscroll").setup({
easing_function = "quadratic", -- Default easing function easing_function = "quadratic", -- Default easing function
}) })
local t = {} local keymap = {
-- Syntax: t[keys] = {function, {function arguments}} ["<C-u>"] = function() neoscroll.ctrl_u({ duration = 250 }) end,
-- Use the "sine" easing function ["<C-d>"] = function() neoscroll.ctrl_d({ duration = 250 }) end,
t['<C-u>'] = { 'scroll', { '-vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-b>"] = function() neoscroll.ctrl_b({ duration = 450 }) end,
t['<C-d>'] = { 'scroll', { 'vim.wo.scroll', 'true', '350', [['sine']] } } ["<C-f>"] = function() neoscroll.ctrl_f({ duration = 450 }) end,
-- Use the "circular" easing function ["<C-y>"] = function() neoscroll.scroll(-0.1, { move_cursor = false, duration = 100 }) end,
t['<C-b>'] = { 'scroll', { '-vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["<C-e>"] = function() neoscroll.scroll(0.1, { move_cursor = false, duration = 100 }) end,
t['<C-f>'] = { 'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '500', [['circular']] } } ["zt"] = function() neoscroll.zt({ half_win_duration = 250 }) end,
-- Pass "nil" to disable the easing animation (constant scrolling speed) ["zz"] = function() neoscroll.zz({ half_win_duration = 250 }) end,
t['<C-y>'] = { 'scroll', { '-0.10', 'false', '100', nil } } ["zb"] = function() neoscroll.zb({ half_win_duration = 250 }) end,
t['<C-e>'] = { 'scroll', { '0.10', 'false', '100', nil } } }
-- When no easing function is provided the default easing function (in this case "quadratic") will be used
t['zt'] = { 'zt', { '300' } } local modes = { 'n', 'v', 'x' }
t['zz'] = { 'zz', { '300' } } for key, func in pairs(keymap) do
t['zb'] = { 'zb', { '300' } } vim.keymap.set(modes, key, func)
end
require('neoscroll.config').set_mappings(t)