From ee01977e762aae013f84ff232e37753ca88e2068 Mon Sep 17 00:00:00 2001 From: ray Date: Sun, 18 Jan 2026 13:11:40 +0000 Subject: [PATCH] Improve hunk navigation with auto-centering behavior Added a delay to center the cursor after moving to the next or previous hunk, enhancing the navigation experience. --- lua/plugins/gitsigns.lua | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lua/plugins/gitsigns.lua b/lua/plugins/gitsigns.lua index 0205547..11f0c63 100644 --- a/lua/plugins/gitsigns.lua +++ b/lua/plugins/gitsigns.lua @@ -25,16 +25,27 @@ return { vim.keymap.set(mode, l, r, opts) end - -- Hunk navigation + -- Hunk navigation (includes zt to center after movement) + -- Note: gs.next_hunk/prev_hunk are async, so zt needs a delay to center after cursor moves map('n', ']h', function() - if vim.wo.diff then return ']c' end - vim.schedule(function() gs.next_hunk() end) + if vim.wo.diff then return ']czt' end + vim.schedule(function() + gs.next_hunk() + end) + vim.defer_fn(function() + vim.cmd('normal! zt') + end, 50) return '' end, { expr = true, desc = 'Gitsigns: Next hunk' }) map('n', '[h', function() - if vim.wo.diff then return '[c' end - vim.schedule(function() gs.prev_hunk() end) + if vim.wo.diff then return '[czt' end + vim.schedule(function() + gs.prev_hunk() + end) + vim.defer_fn(function() + vim.cmd('normal! zt') + end, 50) return '' end, { expr = true, desc = 'Gitsigns: Previous hunk' })