Make document wrap function more compact
This commit is contained in:
parent
e13b2a00d6
commit
dd012828bd
1 changed files with 5 additions and 12 deletions
|
@ -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', '\\', '<cmd>Neotree toggle<cr>', { desc = 'Toggle Neotree' })
|
||||||
vim.keymap.set('n', '0', '<cmd>ToggleTerm<cr>', { desc = 'Toggle Terminal' })
|
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()
|
vim.keymap.set('n', '<leader>dw', function()
|
||||||
-- Save the current 'textwidth' setting
|
local current_tw = vim.o.textwidth -- Save the current 'textwidth' setting
|
||||||
local current_tw = vim.o.textwidth
|
vim.o.textwidth = 80 -- Set 'textwidth' to 80 temporarily
|
||||||
|
vim.api.nvim_command 'normal! ggVGgq' -- Reformat all lines in the buffer
|
||||||
-- Set 'textwidth' to 80 temporarily
|
vim.o.textwidth = current_tw -- Restore the original 'textwidth'
|
||||||
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
|
|
||||||
end, { desc = '[D]ocument [W]rap to 80 column width' })
|
end, { desc = '[D]ocument [W]rap to 80 column width' })
|
||||||
|
|
||||||
-- vim: ts=2 sts=2 sw=2 et
|
-- vim: ts=2 sts=2 sw=2 et
|
||||||
|
|
Loading…
Reference in a new issue