Make document wrap function more compact

This commit is contained in:
Imbus 2024-12-29 12:44:49 +01:00
parent e13b2a00d6
commit dd012828bd

View file

@ -84,19 +84,12 @@ vim.keymap.set('n', '<leader><tab>[', '<cmd>tabprevious<cr>', { desc = 'Previous
vim.keymap.set('n', '\\', '<cmd>Neotree toggle<cr>', { desc = 'Toggle Neotree' })
vim.keymap.set('n', '0', '<cmd>ToggleTerm<cr>', { desc = 'Toggle Terminal' })
-- Define a function to wrap lines to 80 columns
-- Wraps document to specified column width
vim.keymap.set('n', '<leader>dw', function()
-- Save the current 'textwidth' setting
local current_tw = vim.o.textwidth
-- Set 'textwidth' to 80 temporarily
vim.o.textwidth = 80
-- Reformat all lines in the buffer
vim.api.nvim_command 'normal! ggVGgq'
-- Restore the original 'textwidth'
vim.o.textwidth = current_tw
local current_tw = vim.o.textwidth -- Save the current 'textwidth' setting
vim.o.textwidth = 80 -- Set 'textwidth' to 80 temporarily
vim.api.nvim_command 'normal! ggVGgq' -- Reformat all lines in the buffer
vim.o.textwidth = current_tw -- Restore the original 'textwidth'
end, { desc = '[D]ocument [W]rap to 80 column width' })
-- vim: ts=2 sts=2 sw=2 et