From 946d1e7b4a7e3d2f119fbd3f7210fdde6da16bf5 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 3 Apr 2025 16:27:22 +0100 Subject: [PATCH] Add :LStrip command to strip whitespace on the left --- plugin/commands.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugin/commands.lua b/plugin/commands.lua index 306af5a..4408a16 100644 --- a/plugin/commands.lua +++ b/plugin/commands.lua @@ -1,4 +1,4 @@ --- :RStrip strip white psace from right of all lines, ranges supported +-- :RStrip strip white space from right of all lines, ranges supported vim.api.nvim_create_user_command('RStrip', function(opts) local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win()) local range = opts.line1 .. ',' .. opts.line2 @@ -7,6 +7,15 @@ vim.api.nvim_create_user_command('RStrip', function(opts) vim.fn.setpos('.', pos) end, { range = '%' }) +-- :LStrip strip white space from left of all lines, ranges supported +vim.api.nvim_create_user_command('LStrip', function(opts) + local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win()) + local range = opts.line1 .. ',' .. opts.line2 + vim.cmd.execute("'" .. range .. 's/^\\s\\+//e' .. "'") + vim.cmd.nohlsearch() + vim.fn.setpos('.', pos) +end, { range = '%' }) + -- :TabWidth set the tab width for the current buffer vim.api.nvim_create_user_command('TabWidth', function(opts) -- Set the tab width for the current filetype