From 763df8e9d428422d7db6fe157dd8f14656aba6e2 Mon Sep 17 00:00:00 2001 From: "jakob.stendahl" Date: Wed, 11 Jan 2023 12:20:00 +0100 Subject: Add some convenience functions --- Common/nvim/lua/helper_functions.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'Common/nvim/lua/helper_functions.lua') diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua index cac6c00..715c2a7 100755 --- a/Common/nvim/lua/helper_functions.lua +++ b/Common/nvim/lua/helper_functions.lua @@ -21,6 +21,26 @@ function ToggleListChars() vim.opt.listchars = list_chars_enabled and list_chars_when_enabled or 'eol:$' end +-- Command to join lines in buffer as list +function JoinLines(args, quotes) + r = args.args + o = "" + for k, v in pairs(vim.fn.getreg(r, 1, 1)) do + if k > 1 then o = o .. ", " end + if quotes ~= nil then o = o .. quotes end + o = o .. v:match( "^%s*(.-)%s*$" ) -- Strip leading and trailing + if quotes ~= nil then o = o .. quotes end + end + vim.fn.setreg(r, o) +end +function JoinLinesSQ(args) JoinLines(args, "'") end +function JoinLinesDQ(args) JoinLines(args, '"') end +function JoinLinesBT(args) JoinLines(args, "`") end +vim.api.nvim_create_user_command('JoinLines', JoinLines, {bang=false, desc='Joins all lines in a register', nargs='?'}) +vim.api.nvim_create_user_command('JoinLinesSQ', JoinLinesSQ, {bang=false, desc='Joins all lines in a register', nargs='?'}) +vim.api.nvim_create_user_command('JoinLinesDQ', JoinLinesDQ, {bang=false, desc='Joins all lines in a register', nargs='?'}) +vim.api.nvim_create_user_command('JoinLinesBT', JoinLinesBT, {bang=false, desc='Joins all lines in a register', nargs='?'}) + -- Close buffer without closing window --[[ vim.cmd [[ -- cgit v1.2.3