4243021

dotfiles.git > main > 4243021 > files / nvim / .gitignore

Keep cursor centered on wrapped lines

Grahp, 2026-11-09

Commit: 42430218800d225dd454a3ca511f19855fa153df
Parent: e8fb987

1 changed file:

nvim/lua/center.lua modified (view file)

@@ -44,10 +44,12 @@    local _, _, col, off, curswant = unpack(vim.fn.getcurpos())    vim.cmd("norm! zz") -   local line_number = vim.fn.line(".")-   local offset = padding_lines - line_number+   --- Wrapped lines take up more than one screen row, so go by where the cursor actually is on screen+   local offset = padding_lines - vim.fn.winline()    if offset > 0 then-     vim.cmd("norm! " .. offset .. "")+     vim.cmd("norm! " .. offset .. "\25")+   elseif offset < 0 then+     vim.cmd("norm! " .. -offset .. "\5")    end     -- Reset cursor back to the column it was at before@@ -55,6 +57,9 @@    vim.fn.cursor({vim.fn.getcurpos()[2], col, off, curswant}) end +--- Lets <C-e>/<C-y> scroll by screen rows instead of whole wrapped lines+vim.opt.smoothscroll = true+ --- When moving the cursor, entering a buffer, etc., center the screen augroup("TopPad", {clear = true}) autocmd({ "BufWinEnter", "BufEnter", "WinResized", "WinScrolled", "CursorMoved", "CursorMovedI"}, {