Enhance formatting by preserving view on save, update keymaps

Save cursor position and folds before formatting, restoring them
afterwards to improve user experience during format-on-save.
This commit is contained in:
Ray Elliott 2026-01-05 17:34:27 +00:00
commit 8c9f117320
2 changed files with 8 additions and 4 deletions

View file

@ -87,7 +87,11 @@ return {
callback = function()
-- Only format if format-on-save is enabled (global flag)
if vim.g.format_on_save ~= false then
-- Save view (cursor position, folds, etc.) before formatting
local view = vim.fn.winsaveview()
vim.lsp.buf.format({ bufnr = bufnr })
-- Restore view after formatting to preserve folds
vim.fn.winrestview(view)
end
end,
})