From dd012828bd4560b159fd6631f4a17f2d627534b3 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 29 Dec 2024 12:44:49 +0100 Subject: [PATCH] Make document wrap function more compact --- lua/keymaps.lua | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/lua/keymaps.lua b/lua/keymaps.lua index cc194a6..75cea58 100644 --- a/lua/keymaps.lua +++ b/lua/keymaps.lua @@ -84,19 +84,12 @@ vim.keymap.set('n', '[', 'tabprevious', { desc = 'Previous vim.keymap.set('n', '\\', 'Neotree toggle', { desc = 'Toggle Neotree' }) vim.keymap.set('n', '0', 'ToggleTerm', { desc = 'Toggle Terminal' }) --- Define a function to wrap lines to 80 columns +-- Wraps document to specified column width vim.keymap.set('n', '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