From c98608240b63657d09d36cb3a818f783a1d05720 Mon Sep 17 00:00:00 2001 From: Tomas Mirchev Date: Fri, 5 Jun 2026 18:46:00 +0300 Subject: [PATCH] improve ctrl-u/d scroll size --- lua/core/events.lua | 6 ------ lua/core/keymaps.lua | 21 ++++++++++++++------- lua/core/options.lua | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lua/core/events.lua b/lua/core/events.lua index 9053894..ca07c0f 100644 --- a/lua/core/events.lua +++ b/lua/core/events.lua @@ -205,9 +205,3 @@ au('UIEnter', { end) end, }) - -vim.api.nvim_create_autocmd('VimResized', { - callback = function() - vim.opt.scroll = 20 - end, -}) diff --git a/lua/core/keymaps.lua b/lua/core/keymaps.lua index 4f78584..4b031e9 100644 --- a/lua/core/keymaps.lua +++ b/lua/core/keymaps.lua @@ -23,13 +23,20 @@ vim.keymap.set('x', 'K', ":m '<-2gv=gv") vim.keymap.set('n', 's', [[:%s/\<\>//g]]) -- Scroll --- vim.keymap.set('n', '', function() --- vim.cmd('normal! ' .. math.floor(vim.api.nvim_win_get_height(0) * 0.25) .. 'j') --- end) --- --- vim.keymap.set('n', '', function() --- vim.cmd('normal! ' .. math.floor(vim.api.nvim_win_get_height(0) * 0.25) .. 'k') --- end) +local function scroll(cmd) + local count = vim.v.count + local height = vim.api.nvim_win_get_height(0) + vim.opt_local.scroll = math.max(1, math.min(count > 0 and count or 20, height)) + vim.cmd.normal({ vim.api.nvim_replace_termcodes(cmd, true, false, true), bang = true }) +end + +map('n', '', function() + scroll('') +end) + +map('n', '', function() + scroll('') +end) -- Easy to use registers map('x', 'p', '"_dP') diff --git a/lua/core/options.lua b/lua/core/options.lua index 7e3a6b1..49bdb6f 100644 --- a/lua/core/options.lua +++ b/lua/core/options.lua @@ -71,7 +71,7 @@ vim.opt.autoindent = true -- Copy indent from the current line when starting a n vim.opt.smartindent = true -- Automatically inserts indents in code blocks (for C-like languages) -- Scroll and mouse -vim.opt.scroll = 20 +vim.opt.scroll = 0 vim.opt.scrolloff = 10 vim.opt.sidescrolloff = 5 vim.opt.mousescroll = 'hor:1,ver:1'