4a73b6f
Branches > main > 4a73b6f > files / nvim / lua / fuzzy.lua
Merge remote-tracking branch 'origin/main'
Commit: 4a73b6f5aa95e79f25a6c75a3c439d01a5595e9c
Parent: 9e15467
Parent: 646bf84
1 changed file:
nvim/lua/center.lua view file
@@ -2,16 +2,14 @@ --- including when at the top of a buffer. --- It does this by adding a bunch of fake virtual lines above the first line of the buf, --- and scrolling the screen to the correct place-local api = vim.api-local ac = vim.api.nvim_create_autocmd-local ag = vim.api.nvim_create_augroup-local fn = vim.fn+local autocmd = vim.api.nvim_create_autocmd+local augroup = vim.api.nvim_create_augroup -local ns = api.nvim_create_namespace("dev.grahp.nvim.padding_lines")+local ns = vim.api.nvim_create_namespace("dev.grahp.nvim.padding_lines") local function set_padding_lines(lines)- api.nvim_buf_clear_namespace(0, ns, 0, -1)- api.nvim_buf_set_extmark(0, ns, 0, 0, {+ vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)+ vim.api.nvim_buf_set_extmark(0, ns, 0, 0, { virt_lines = lines, virt_lines_above = true })@@ -34,17 +32,17 @@ --- Centers the screen, and then feeds enough <C-y>s to scroll the cursor to the very center of the screen --- If you're completely past the top of the buffer, just `zz` works and it won't scroll anything. local function center()- local win_height = api.nvim_win_get_height(0)+ local win_height = vim.api.nvim_win_get_height(0) local padding_lines = math.ceil(win_height / 2) local blank_line = {{""}} set_padding_lines(replicate(win_height, blank_line)) - local _, _, col, off, curswant = unpack(fn.getcurpos())+ local _, _, col, off, curswant = unpack(vim.fn.getcurpos()) vim.cmd("norm! zz") - local line_number = fn.line(".")+ local line_number = vim.fn.line(".") local offset = padding_lines - line_number if offset > 0 then vim.cmd("norm! " .. offset .. "")@@ -52,12 +50,12 @@ -- Reset cursor back to the column it was at before -- Without this, zz and <C-y> muck up the cursor position when in insert mode- fn.cursor({vim.fn.getcurpos()[2], col, off, curswant})+ vim.fn.cursor({vim.fn.getcurpos()[2], col, off, curswant}) end --- When moving the cursor, entering a buffer, etc., center the screen-ag("TopPad", {clear = true})-ac({ "BufWinEnter", "BufEnter", "WinResized", "WinScrolled", "CursorMoved", "CursorMovedI"}, {+augroup("TopPad", {clear = true})+autocmd({ "BufWinEnter", "BufEnter", "WinResized", "WinScrolled", "CursorMoved", "CursorMovedI"}, { group = "TopPad", callback = center, })