summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-06-24 19:32:22 +0200
committerThomas Vanbesien <tvanbesi@proton.me>2026-06-24 19:32:22 +0200
commitc4ff1dc44373f03e8e940670f9610a6005d960b0 (patch)
tree4e2f01381e12a30b5aaf9a2bc69a03bae1dd05a3 /plugin
parent03f7f69ffd508f71f86e82149f7748fde3c9b4d6 (diff)
downloadnvim-config-c4ff1dc44373f03e8e940670f9610a6005d960b0.tar.gz
nvim-config-c4ff1dc44373f03e8e940670f9610a6005d960b0.zip
refactor(nvim): refactor smooth scroll plugin
Diffstat (limited to 'plugin')
-rw-r--r--plugin/50-smooth_scroll.lua41
1 files changed, 33 insertions, 8 deletions
diff --git a/plugin/50-smooth_scroll.lua b/plugin/50-smooth_scroll.lua
index 6b31bf4..4915238 100644
--- a/plugin/50-smooth_scroll.lua
+++ b/plugin/50-smooth_scroll.lua
@@ -1,3 +1,13 @@
+--
+-- 50-smooth_scroll.lua
+--
+-- * Animates a half-page scroll by stepping <C-e>/<C-y> (plus j/k) over a short timer.
+--
+-- User commands:
+-- `ScrollSmoothDown`: scroll down smoothly
+-- `ScrollSmoothUp`: scroll up smoothly
+--
+
local Dir = {
UP = 1,
DOWN = 2,
@@ -20,15 +30,16 @@ local function smooth_scroll(dir)
return vim.fn.line(".") == 1
end
end
- -- bail only when the cursor itself can't move further; at the viewport
- -- boundary <C-e>/<C-y> no-op but we still want j/k to walk the cursor
+ -- bail only when the cursor itself can't move further; at the viewport boundary <C-e>/<C-y>
+ -- no-op but we still want j/k to walk the cursor
if cursor_at_boundary() then
return
end
local win_height = vim.api.nvim_win_get_height(0)
local duration, sleep_duration = 100, 16 -- 60 fps
local distance = math.floor(win_height / 2)
- local steps_number = math.ceil(duration / sleep_duration) -- We want a movement every `sleep_duration` msec
+ -- We want a movement every `sleep_duration` msec
+ local steps_number = math.ceil(duration / sleep_duration)
local step = distance / steps_number
local scroll_keys = dir == Dir.DOWN and "\\<C-e>j" or "\\<C-y>k"
local cursor_keys = dir == Dir.DOWN and "j" or "k"
@@ -50,9 +61,23 @@ local function smooth_scroll(dir)
end
end
-vim.api.nvim_create_user_command("ScrollSmoothDown", function()
- smooth_scroll(Dir.DOWN)
-end, { desc = "Scroll down smoothly" })
-vim.api.nvim_create_user_command("ScrollSmoothUp", function()
+local function smooth_scroll_up()
smooth_scroll(Dir.UP)
-end, { desc = "Scroll up smoothly" })
+end
+
+local function smooth_scroll_down()
+ smooth_scroll(Dir.DOWN)
+end
+
+----------------------------------------------------------------------------------------------------
+
+vim.api.nvim_create_user_command(
+ "ScrollSmoothDown",
+ smooth_scroll_down,
+ { desc = "Scroll down smoothly" }
+)
+vim.api.nvim_create_user_command(
+ "ScrollSmoothUp",
+ smooth_scroll_up,
+ { desc = "Scroll up smoothly" }
+)