From 8c9f1173208e54471b1618976ff3abdc148353dc Mon Sep 17 00:00:00 2001 From: ray Date: Mon, 5 Jan 2026 17:34:27 +0000 Subject: [PATCH] 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. --- lua/plugins/none-ls.lua | 4 ++++ lua/plugins/treesitter.lua | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/plugins/none-ls.lua b/lua/plugins/none-ls.lua index bdb25d5..31bc519 100644 --- a/lua/plugins/none-ls.lua +++ b/lua/plugins/none-ls.lua @@ -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, }) diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index b72784c..b34fba5 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -51,10 +51,10 @@ return { incremental_selection = { enable = true, keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = "", - node_decremental = "", + init_selection = "+", + node_incremental = "+", + scope_incremental = "g+", + node_decremental = "-", }, },