diff options
author | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2023-01-11 12:20:00 +0100 |
---|---|---|
committer | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2023-01-11 12:20:00 +0100 |
commit | 763df8e9d428422d7db6fe157dd8f14656aba6e2 (patch) | |
tree | 987e8f41252a4caf67802598d172ebfcc8de0a4c /Common/nvim/lua/helper_functions.lua | |
parent | 2c9ca86b6a834e1be66678eee78246f8339b3e73 (diff) | |
download | dotfiles-763df8e9d428422d7db6fe157dd8f14656aba6e2.tar.gz dotfiles-763df8e9d428422d7db6fe157dd8f14656aba6e2.zip |
Add some convenience functions
Diffstat (limited to 'Common/nvim/lua/helper_functions.lua')
-rwxr-xr-x | Common/nvim/lua/helper_functions.lua | 20 |
1 files changed, 20 insertions, 0 deletions
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 [[ |