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

Configure Feed

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

feat(utilize numbers in navigation): - Provides to modes, 'jump' and 'prefix' (prefix is default)

+73 -15
+7 -1
README.md
··· 46 46 | keymaps.paste | string | `"<CR>"` | 47 47 | keymaps.yank | string | `"yy"` | 48 48 | keymaps.close | table of strings | `{ "<Esc>", "<C-c>", "q" }` | 49 + | num_behavior | string defining jump behavior "prefix" or "jump" | `"prefix"` | 49 50 50 51 51 52 If no separator is desired, pass in an empty string for sep: ··· 58 59 navigation_next = "j", 59 60 navigation_prev = "k", 60 61 }, 62 + num_behavior = "prefix", 61 63 }) 62 64 end, 63 65 ``` 64 66 67 + The 'num_behavior' option defines in-popup navigation behavior when hitting number keys. 68 + - `num_behavior = "prefix"` works similar to traditional vim navigation with '3j' moving down 3 entries in the bank. 69 + - `num_behavior = "jump"` jumps to entry matching the pressed number key (i.e. '3' jumps to entry 3) 70 + - Note: If 'max_entries' is a two-digit number, there will be a delay upon pressing numbers that prefix a valid entry. 71 + 65 72 ## Usage 66 73 67 74 The popup menu can be opened with the command:`:YankBank`, an entry is pasted at the current cursor position by hitting enter, and the menu can be closed by hitting escape, ctrl-c, or q. ··· 76 83 ## Potential Improvements 77 84 - Persistence between sessions (through either sqlite database or just a file) 78 85 - Polling on unnamedplus register to populate bank in more intuitive manner (could be enabled as option) 79 - - Number based navigation of menu 80 86 - nvim-cmp integration 81 87 - fzf integration 82 88 - Setup options configuring which registers are included
+24 -10
lua/yankbank/helpers.lua
··· 2 2 local M = {} 3 3 4 4 -- navigate to the next numbered item 5 - function M.next_numbered_item() 5 + function M.next_numbered_item(steps) 6 + steps = steps or 1 -- Default to 1 if no steps are provided 6 7 local current_line = vim.api.nvim_win_get_cursor(0)[1] 7 8 local total_lines = vim.api.nvim_buf_line_count(0) 9 + local jumps_made = 0 10 + local last_entry = current_line 8 11 for i = current_line + 1, total_lines do 9 12 local line = vim.api.nvim_buf_get_lines(0, i - 1, i, false)[1] 10 - -- search for the correct line start 11 - if line:match("^%s*%d+:") then 12 - vim.api.nvim_win_set_cursor(0, {i, 0}) 13 - break 13 + if line:match("^%s*%d+:") and jumps_made < steps then 14 + jumps_made = jumps_made + 1 15 + last_entry = i 16 + if jumps_made == steps then 17 + vim.api.nvim_win_set_cursor(0, {i, 0}) 18 + return 19 + end 14 20 end 15 21 end 22 + -- if steps exceeds number of entries below, jump to last entry 23 + vim.api.nvim_win_set_cursor(0, { last_entry, 0 }) 16 24 end 17 25 18 26 19 27 -- navigate to the previous numbered item 20 - function M.prev_numbered_item() 28 + function M.prev_numbered_item(steps) 29 + steps = steps or 1 -- Default to 1 if no steps are provided 21 30 local current_line = vim.api.nvim_win_get_cursor(0)[1] 31 + local jumps_made = 0 22 32 for i = current_line - 1, 1, -1 do 23 33 local line = vim.api.nvim_buf_get_lines(0, i - 1, i, false)[1] 24 - -- search for the correct line start 25 - if line:match("^%s*%d+:") then 26 - vim.api.nvim_win_set_cursor(0, {i, 0}) 27 - break 34 + if line:match("^%s*%d+:") and jumps_made < steps then 35 + jumps_made = jumps_made + 1 36 + if jumps_made == steps then 37 + vim.api.nvim_win_set_cursor(0, {i, 0}) 38 + return 39 + end 28 40 end 29 41 end 42 + -- if steps exceeds the number of entries above, jump to first entry. 43 + vim.api.nvim_win_set_cursor(0, { 1, 0 }) 30 44 end 31 45 32 46 -- customized paste function that functions more like 'p'
+42 -4
lua/yankbank/menu.lua
··· 89 89 -- merge default and options keymap tables 90 90 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {}) 91 91 92 + -- check table for number behavior option (prefix or jump, default to prefix) 93 + opts.num_behavior = opts.num_behavior or "prefix" 94 + 92 95 -- popup buffer navigation binds 93 - vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item, 94 - { noremap = true, silent = true, buffer = bufnr }) 95 - vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item, 96 - { noremap = true, silent = true, buffer = bufnr }) 96 + if opts.num_behavior == "prefix" then 97 + vim.keymap.set("n", k.navigation_next, function() 98 + local count = vim.v.count1 > 0 and vim.v.count1 or 1 99 + helpers.next_numbered_item(count) 100 + return "" 101 + end, { noremap = true, silent = true, buffer = bufnr }) 102 + vim.keymap.set("n", k.navigation_prev, function() 103 + local count = vim.v.count1 > 0 and vim.v.count1 or 1 104 + helpers.prev_numbered_item(count) 105 + return "" 106 + end, { noremap = true, silent = true, buffer = bufnr }) 107 + 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 }) 112 + end 113 + 114 + -- Map number keys to jump to entry if num_behavior is 'jump' 115 + if opts.num_behavior == "jump" then 116 + -- TODO: deal with delayed trigger upon hitting number that is part of valid sequence 117 + -- i.e. '1' when '10' is a valid entry 118 + for i = 1, opts.max_entries do 119 + vim.keymap.set("n", tostring(i), function() 120 + local target_line = nil 121 + for line_num, yank_num in pairs(line_yank_map) do 122 + if yank_num == i then 123 + target_line = line_num 124 + break 125 + end 126 + end 127 + if target_line then 128 + vim.api.nvim_win_set_cursor(win_id, {target_line, 0}) 129 + end 130 + end, map_opts) 131 + end 132 + end 133 + 97 134 98 135 -- bind paste behavior 99 136 vim.keymap.set("n", k.paste, function() ··· 130 167 vim.api.nvim_win_close(win_id, true) 131 168 end, map_opts) 132 169 end 170 + 133 171 end 134 172 135 173 return M