Add keymap to format whole file with gw

Introduces `<leader>gw` to format the entire buffer using the internal
formatting operator gw. It preserves the current window view (cursor
position and scroll) during the operation.
This commit is contained in:
2026-02-02 20:30:41 +00:00
parent 31a03cac7b
commit 280c00b272

View File

@@ -50,3 +50,10 @@ vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
-- Mapping to toggle checkboxes -- Mapping to toggle checkboxes
vim.keymap.set('n', '<leader><CR>', ':CheckboxToggle<CR>', opts) vim.keymap.set('n', '<leader><CR>', ':CheckboxToggle<CR>', opts)
-- Format whole file using internal algorithm
vim.keymap.set('n', '<leader>gw', function()
local view = vim.fn.winsaveview()
vim.cmd('normal! gggwG')
vim.fn.winrestview(view)
end, { desc = 'Format whole file with gw' })