···4646| keymaps.paste | string | `"<CR>"` |
4747| keymaps.yank | string | `"yy"` |
4848| keymaps.close | table of strings | `{ "<Esc>", "<C-c>", "q" }` |
4949+| num_behavior | string defining jump behavior "prefix" or "jump" | `"prefix"` |
495050515152If no separator is desired, pass in an empty string for sep:
···5859 navigation_next = "j",
5960 navigation_prev = "k",
6061 },
6262+ num_behavior = "prefix",
6163 })
6264 end,
6365```
64666767+The 'num_behavior' option defines in-popup navigation behavior when hitting number keys.
6868+- `num_behavior = "prefix"` works similar to traditional vim navigation with '3j' moving down 3 entries in the bank.
6969+- `num_behavior = "jump"` jumps to entry matching the pressed number key (i.e. '3' jumps to entry 3)
7070+ - Note: If 'max_entries' is a two-digit number, there will be a delay upon pressing numbers that prefix a valid entry.
7171+6572## Usage
66736774The 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.
···7683## Potential Improvements
7784- Persistence between sessions (through either sqlite database or just a file)
7885- Polling on unnamedplus register to populate bank in more intuitive manner (could be enabled as option)
7979-- Number based navigation of menu
8086- nvim-cmp integration
8187- fzf integration
8288- Setup options configuring which registers are included
+24-10
lua/yankbank/helpers.lua
···22local M = {}
3344-- navigate to the next numbered item
55-function M.next_numbered_item()
55+function M.next_numbered_item(steps)
66+ steps = steps or 1 -- Default to 1 if no steps are provided
67 local current_line = vim.api.nvim_win_get_cursor(0)[1]
78 local total_lines = vim.api.nvim_buf_line_count(0)
99+ local jumps_made = 0
1010+ local last_entry = current_line
811 for i = current_line + 1, total_lines do
912 local line = vim.api.nvim_buf_get_lines(0, i - 1, i, false)[1]
1010- -- search for the correct line start
1111- if line:match("^%s*%d+:") then
1212- vim.api.nvim_win_set_cursor(0, {i, 0})
1313- break
1313+ if line:match("^%s*%d+:") and jumps_made < steps then
1414+ jumps_made = jumps_made + 1
1515+ last_entry = i
1616+ if jumps_made == steps then
1717+ vim.api.nvim_win_set_cursor(0, {i, 0})
1818+ return
1919+ end
1420 end
1521 end
2222+ -- if steps exceeds number of entries below, jump to last entry
2323+ vim.api.nvim_win_set_cursor(0, { last_entry, 0 })
1624end
172518261927-- navigate to the previous numbered item
2020-function M.prev_numbered_item()
2828+function M.prev_numbered_item(steps)
2929+ steps = steps or 1 -- Default to 1 if no steps are provided
2130 local current_line = vim.api.nvim_win_get_cursor(0)[1]
3131+ local jumps_made = 0
2232 for i = current_line - 1, 1, -1 do
2333 local line = vim.api.nvim_buf_get_lines(0, i - 1, i, false)[1]
2424- -- search for the correct line start
2525- if line:match("^%s*%d+:") then
2626- vim.api.nvim_win_set_cursor(0, {i, 0})
2727- break
3434+ if line:match("^%s*%d+:") and jumps_made < steps then
3535+ jumps_made = jumps_made + 1
3636+ if jumps_made == steps then
3737+ vim.api.nvim_win_set_cursor(0, {i, 0})
3838+ return
3939+ end
2840 end
2941 end
4242+ -- if steps exceeds the number of entries above, jump to first entry.
4343+ vim.api.nvim_win_set_cursor(0, { 1, 0 })
3044end
31453246-- customized paste function that functions more like 'p'
+42-4
lua/yankbank/menu.lua
···8989 -- merge default and options keymap tables
9090 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {})
91919292+ -- check table for number behavior option (prefix or jump, default to prefix)
9393+ opts.num_behavior = opts.num_behavior or "prefix"
9494+9295 -- popup buffer navigation binds
9393- vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item,
9494- { noremap = true, silent = true, buffer = bufnr })
9595- vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item,
9696- { noremap = true, silent = true, buffer = bufnr })
9696+ if opts.num_behavior == "prefix" then
9797+ vim.keymap.set("n", k.navigation_next, function()
9898+ local count = vim.v.count1 > 0 and vim.v.count1 or 1
9999+ helpers.next_numbered_item(count)
100100+ return ""
101101+ end, { noremap = true, silent = true, buffer = bufnr })
102102+ vim.keymap.set("n", k.navigation_prev, function()
103103+ local count = vim.v.count1 > 0 and vim.v.count1 or 1
104104+ helpers.prev_numbered_item(count)
105105+ return ""
106106+ end, { noremap = true, silent = true, buffer = bufnr })
107107+ else
108108+ vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item,
109109+ { noremap = true, silent = true, buffer = bufnr })
110110+ vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item,
111111+ { noremap = true, silent = true, buffer = bufnr })
112112+ end
113113+114114+ -- Map number keys to jump to entry if num_behavior is 'jump'
115115+ if opts.num_behavior == "jump" then
116116+ -- TODO: deal with delayed trigger upon hitting number that is part of valid sequence
117117+ -- i.e. '1' when '10' is a valid entry
118118+ for i = 1, opts.max_entries do
119119+ vim.keymap.set("n", tostring(i), function()
120120+ local target_line = nil
121121+ for line_num, yank_num in pairs(line_yank_map) do
122122+ if yank_num == i then
123123+ target_line = line_num
124124+ break
125125+ end
126126+ end
127127+ if target_line then
128128+ vim.api.nvim_win_set_cursor(win_id, {target_line, 0})
129129+ end
130130+ end, map_opts)
131131+ end
132132+ end
133133+9713498135 -- bind paste behavior
99136 vim.keymap.set("n", k.paste, function()
···130167 vim.api.nvim_win_close(win_id, true)
131168 end, map_opts)
132169 end
170170+133171end
134172135173return M