Mercurial > dotfiles
comparison .chezmoitemplates/init.lua @ 617:d130c5c8b4e9
improve indent trimming on copy
author | zegervdv <zegervdv@me.com> |
---|---|
date | Tue, 26 Jul 2022 09:30:08 +0200 |
parents | 08bb1c92e5e5 |
children | 7d581ebd5508 |
comparison
equal
deleted
inserted
replaced
616:08bb1c92e5e5 | 617:d130c5c8b4e9 |
---|---|
30 'ojroques/nvim-osc52', | 30 'ojroques/nvim-osc52', |
31 config = function() | 31 config = function() |
32 require('osc52').setup { trim = false } | 32 require('osc52').setup { trim = false } |
33 local copy = function(lines, _) | 33 local copy = function(lines, _) |
34 -- Trim indent before copying | 34 -- Trim indent before copying |
35 local indent, _ = lines[1]:find '[^ ]' | 35 local indent = 0 |
36 for key, line in ipairs(lines) do | 36 for _, line in ipairs(lines) do |
37 lines[key] = line:sub(indent) | 37 local index, _ = line:find '[^ ]' |
38 if index ~= nil then | |
39 indent = index | |
40 break | |
41 end | |
42 end | |
43 if indent ~= nil then | |
44 for key, line in ipairs(lines) do | |
45 lines[key] = line:sub(indent) | |
46 end | |
38 end | 47 end |
39 require('osc52').copy(table.concat(lines, '\n')) | 48 require('osc52').copy(table.concat(lines, '\n')) |
40 end | 49 end |
41 local paste = function() return { vim.fn.split(vim.fn.getreg '', '\n'), vim.fn.getregtype '' } end | 50 local paste = function() return { vim.fn.split(vim.fn.getreg '', '\n'), vim.fn.getregtype '' } end |
42 vim.g.clipboard = { | 51 vim.g.clipboard = { |