Neovim plugin improving access to clipboard history (mirror)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fmt(added stylua format sheet)

+50 -24
+5
.stylua.toml
··· 1 + column_width = 80 2 + line_endings = "Unix" 3 + indent_type = "Spaces" 4 + indent_width = 4 5 + quote_style = "AutoPreferDouble"
+2 -2
lua/yankbank/clipboard.lua
··· 32 32 local rn = vim.v.event.regname 33 33 34 34 -- check changes wwere made to default register 35 - if vim.v.event.regname == '' then 35 + if vim.v.event.regname == "" then 36 36 local yanked_text = vim.fn.getreg(rn) 37 37 38 38 -- NOTE: this only blocks adding to list if something else is in plus register 39 39 if string.len(yanked_text) <= 1 then 40 - return 40 + return 41 41 end 42 42 43 43 M.add_yank(yanks, yanked_text, max_entries)
+11 -4
lua/yankbank/data.lua
··· 15 15 16 16 -- remove trailing newlines 17 17 yank = yank:gsub("\n$", "") 18 - local yank_lines = vim.split(yank, "\n", { plain= true }) 18 + local yank_lines = vim.split(yank, "\n", { plain = true }) 19 19 local leading_space, leading_space_length 20 20 21 21 -- determine the number of leading whitespaces on the first line ··· 27 27 for j, line in ipairs(yank_lines) do 28 28 if j == 1 then 29 29 -- Format the line number with uniform spacing 30 - local lineNumber = string.format("%" .. max_digits .. "d: ", yank_num) 30 + local lineNumber = 31 + string.format("%" .. max_digits .. "d: ", yank_num) 31 32 line = line:sub(leading_space_length + 1) 32 33 table.insert(display_lines, lineNumber .. line) 33 34 else 34 35 -- Remove the same amount of leading whitespace as on the first line 35 36 line = line:sub(leading_space_length + 1) 36 37 -- Use spaces equal to the line number's reserved space to align subsequent lines 37 - table.insert(display_lines, string.rep(" ", max_digits + 2) .. line) 38 + table.insert( 39 + display_lines, 40 + string.rep(" ", max_digits + 2) .. line 41 + ) 38 42 end 39 43 table.insert(line_yank_map, i) 40 44 end ··· 42 46 if i < #yanks then 43 47 -- Add a visual separator between yanks, aligned with the yank content 44 48 if sep ~= "" then 45 - table.insert(display_lines, string.rep(" ", max_digits + 2) .. sep) 49 + table.insert( 50 + display_lines, 51 + string.rep(" ", max_digits + 2) .. sep 52 + ) 46 53 end 47 54 table.insert(line_yank_map, false) 48 55 end
+2 -3
lua/yankbank/helpers.lua
··· 14 14 jumps_made = jumps_made + 1 15 15 last_entry = i 16 16 if jumps_made == steps then 17 - vim.api.nvim_win_set_cursor(0, {i, 0}) 17 + vim.api.nvim_win_set_cursor(0, { i, 0 }) 18 18 return 19 19 end 20 20 end ··· 22 22 -- if steps exceeds number of entries below, jump to last entry 23 23 vim.api.nvim_win_set_cursor(0, { last_entry, 0 }) 24 24 end 25 - 26 25 27 26 -- navigate to the previous numbered item 28 27 function M.prev_numbered_item(steps) ··· 34 33 if line:match("^%s*%d+:") and jumps_made < steps then 35 34 jumps_made = jumps_made + 1 36 35 if jumps_made == steps then 37 - vim.api.nvim_win_set_cursor(0, {i, 0}) 36 + vim.api.nvim_win_set_cursor(0, { i, 0 }) 38 37 return 39 38 end 40 39 end
+2 -1
lua/yankbank/init.lua
··· 20 20 local sep_opt = opts.sep or sep 21 21 opts.keymaps = opts.keymaps or {} 22 22 23 - local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt) 23 + local bufnr, display_lines, line_yank_map = 24 + menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt) 24 25 -- handle empty bank case 25 26 if not bufnr then 26 27 return
+28 -14
lua/yankbank/menu.lua
··· 10 10 function M.create_and_fill_buffer(yanks, max_entries, sep) 11 11 -- check the content of the system clipboard register 12 12 -- TODO: this could be replaced with some sort of polling of the + register 13 - local text = vim.fn.getreg('+') 13 + local text = vim.fn.getreg("+") 14 14 local most_recent_yank = yanks[1] or "" 15 15 if text ~= most_recent_yank then 16 16 clipboard.add_yank(yanks, text, max_entries) ··· 52 52 -- define buffer window width and height based on number of columns 53 53 -- FIX: long enough entries will cause window to go below end of screen 54 54 -- FIX: wrapping long lines will cause entries below to not show in menu (requires scrolling to see) 55 - local width = math.min(max_width + 4, vim.api.nvim_get_option_value("columns", {})) 56 - local height = math.min(display_lines and #display_lines or 1, vim.api.nvim_get_option_value("lines", {})) 55 + local width = 56 + math.min(max_width + 4, vim.api.nvim_get_option_value("columns", {})) 57 + local height = math.min( 58 + display_lines and #display_lines or 1, 59 + vim.api.nvim_get_option_value("lines", {}) 60 + ) 57 61 58 62 -- open window 59 63 local win_id = vim.api.nvim_open_win(bufnr, true, { 60 64 relative = "editor", 61 65 width = width, 62 66 height = height, 63 - col = math.floor((vim.api.nvim_get_option_value("columns", {}) - width) / 2), 64 - row = math.floor((vim.api.nvim_get_option_value("lines", {}) - height) / 2), 67 + col = math.floor( 68 + (vim.api.nvim_get_option_value("columns", {}) - width) / 2 69 + ), 70 + row = math.floor( 71 + (vim.api.nvim_get_option_value("lines", {}) - height) / 2 72 + ), 65 73 border = "rounded", 66 74 style = "minimal", 67 75 }) 68 76 69 77 -- Highlight current line 70 - vim.api.nvim_set_option_value('cursorline', true, { win = win_id }) 78 + vim.api.nvim_set_option_value("cursorline", true, { win = win_id }) 71 79 72 80 return win_id 73 81 end ··· 105 113 return "" 106 114 end, { noremap = true, silent = true, buffer = bufnr }) 107 115 else 108 - vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item, 109 - { noremap = true, silent = true, buffer = bufnr }) 110 - vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item, 111 - { noremap = true, silent = true, buffer = bufnr }) 116 + vim.keymap.set( 117 + "n", 118 + k.navigation_next, 119 + helpers.next_numbered_item, 120 + { noremap = true, silent = true, buffer = bufnr } 121 + ) 122 + vim.keymap.set( 123 + "n", 124 + k.navigation_prev, 125 + helpers.prev_numbered_item, 126 + { noremap = true, silent = true, buffer = bufnr } 127 + ) 112 128 end 113 129 114 130 -- Map number keys to jump to entry if num_behavior is 'jump' ··· 125 141 end 126 142 end 127 143 if target_line then 128 - vim.api.nvim_win_set_cursor(win_id, {target_line, 0}) 144 + vim.api.nvim_win_set_cursor(win_id, { target_line, 0 }) 129 145 end 130 146 end, map_opts) 131 147 end 132 148 end 133 - 134 149 135 150 -- bind paste behavior 136 151 vim.keymap.set("n", k.paste, function() ··· 156 171 if yankIndex then 157 172 local text = yanks[yankIndex] 158 173 -- NOTE: possibly change this to '"' if not using system clipboard 159 - vim.fn.setreg('+', text) 174 + vim.fn.setreg("+", text) 160 175 vim.api.nvim_win_close(win_id, true) 161 176 end 162 177 end, { buffer = bufnr }) ··· 167 182 vim.api.nvim_win_close(win_id, true) 168 183 end, map_opts) 169 184 end 170 - 171 185 end 172 186 173 187 return M