···3838The setup function also supports taking in a table of options:
3939| Option | Type | Default |
4040|-------------|--------------------------------------------|----------------|
4141-| max_entries | integer number of entries to show in popup | 10 |
4242-| sep | string separator to show between table entries | "-----" |
4141+| max_entries | integer number of entries to show in popup | `10` |
4242+| sep | string separator to show between table entries | `"-----"` |
4343+| keymaps | table containing keymap overrides | `{}` |
4444+| keymaps.navigation_next | string | `"j"` |
4545+| keymaps.navigation_prev | string | `"k"` |
4646+| keymaps.paste | string | `"<CR>"` |
4747+| keymaps.yank | string | `"yy"` |
4848+| keymaps.close | table of strings | `{ "<Esc>", "<C-c>", "q" }` |
434944504551If no separator is desired, pass in an empty string for sep:
···4854 require('yankbank').setup({
4955 max_entries = 12,
5056 sep = "",
5757+ keymaps = {
5858+ navigation_next = "j",
5959+ navigation_prev = "k",
6060+ },
5161 })
5262 end,
5363```
···6070I would personally also recommend setting a keybind to open the menu.
6171```lua
6272-- map to '<leader>y'
6363-vim.keymap.set("n", "<leader>y", ":YankBank<CR>", { noremap = true })
7373+vim.keymap.set("n", "<leader>y", "<cmd>YankBank<CR>", { noremap = true })
6474```
65756676## Potential Improvements
6767-- Expose popup keybind behavior through setup options
6868-- Access to other registers (number/letter registers?)
7777+- Persistence between sessions (through either sqlite database or just a file)
6978- Polling on unnamedplus register to populate bank in more intuitive manner (could be enabled as option)
7979+- Number based navigation of menu
8080+- nvim-cmp integration
8181+- fzf integration
8282+- Setup options configuring which registers are included
70837184## Alternatives
7272-- [neoclip](https://github.com/AckslD/nvim-neoclip.lua)
7373-- [Yanky](https://github.com/gbprod/yanky.nvim)
8585+- [nvim-neoclip](https://github.com/AckslD/nvim-neoclip.lua)
8686+- [yanky.nvim](https://github.com/gbprod/yanky.nvim)
+8-16
lua/yankbank/init.lua
···1111local sep = "-----"
12121313-- wrapper function for main plugin functionality
1414-local function show_yank_bank(args)
1414+local function show_yank_bank(opts)
1515 -- Parse command arguments directly if args are provided as a string
1616- local opts = {}
1717- if type(args) == "string" and args ~= "" then
1818- local parts = vim.split(args, "%s+", {true})
1919- opts.max_entries = tonumber(parts[1])
2020- opts.sep = parts[2]
2121- elseif type(args) == "table" then
2222- -- If opts is already a table, use it directly (for programmatic calls)
2323- opts = args
2424- end
1616+ opts = opts or {}
25172618 -- Fallback to defaults if necessary
2719 local max_entries_opt = opts.max_entries or max_entries
2820 local sep_opt = opts.sep or sep
2121+ opts.keymaps = opts.keymaps or {}
29223023 local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, max_entries_opt, sep_opt)
3124 -- handle empty bank case
···3326 return
3427 end
3528 local win_id = menu.open_window(bufnr, display_lines)
3636- menu.set_keymaps(win_id, bufnr, yanks, line_yank_map)
2929+ menu.set_keymaps(win_id, bufnr, yanks, line_yank_map, opts)
3730end
38313932-- plugin setup
···42354336 -- parse opts
4437 max_entries = opts.max_entries or max_entries
4545- sep = opts.sep or sep
3838+ -- sep = opts.sep or sep
46394740 -- create clipboard autocmds
4841 clipboard.setup_yank_autocmd(yanks, max_entries)
49425043 -- Create user command
5151- -- TODO: allow params (i.e. keymaps/max_entries/separator)
5252- vim.api.nvim_create_user_command("YankBank", function(args)
5353- show_yank_bank(args.args)
5454- end, { desc = "Show Recent Yanks", nargs = "*" })
4444+ vim.api.nvim_create_user_command("YankBank", function()
4545+ show_yank_bank(opts)
4646+ end, { desc = "Show Recent Yanks" })
5547end
56485749return M
+23-11
lua/yankbank/menu.lua
···5050 end
51515252 -- define buffer window width and height based on number of columns
5353+ -- FIX: long enough entries will cause window to go below end of screen
5454+ -- FIX: wrapping long lines will cause entries below to not show in menu (requires scrolling to see)
5355 local width = math.min(max_width + 4, vim.api.nvim_get_option_value("columns", {}))
5456 local height = math.min(display_lines and #display_lines or 1, vim.api.nvim_get_option_value("lines", {}))
5557···7173end
72747375-- Set key mappings for the popup window
7474--- TODO: configurable options (take in inside setup function)
7575-function M.set_keymaps(win_id, bufnr, yanks, line_yank_map)
7676+function M.set_keymaps(win_id, bufnr, yanks, line_yank_map, opts)
7677 -- Key mappings for selection and closing the popup
7778 local map_opts = { noremap = true, silent = true, buffer = bufnr }
7979+8080+ -- default plugin keymaps
8181+ local default_keymaps = {
8282+ navigation_next = "j",
8383+ navigation_prev = "k",
8484+ paste = "<CR>",
8585+ yank = "yy",
8686+ close = { "<Esc>", "<C-c>", "q" }, -- TODO: issues might arise passing non-table single value for this
8787+ }
8888+8989+ -- merge default and options keymap tables
9090+ local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {})
78917992 -- popup buffer navigation binds
8080- vim.keymap.set('n', 'j', helpers.next_numbered_item,
9393+ vim.keymap.set("n", k.navigation_next, helpers.next_numbered_item,
8194 { noremap = true, silent = true, buffer = bufnr })
8282- vim.keymap.set('n', 'k', helpers.prev_numbered_item,
9595+ vim.keymap.set("n", k.navigation_prev, helpers.prev_numbered_item,
8396 { noremap = true, silent = true, buffer = bufnr })
84978585- -- bind paste behavior to enter
8686- vim.keymap.set('n', '<CR>', function()
9898+ -- bind paste behavior
9999+ vim.keymap.set("n", k.paste, function()
87100 local cursor = vim.api.nvim_win_get_cursor(win_id)[1]
88101 -- use the mapping to find the original yank
89102 local yankIndex = line_yank_map[cursor]
···99112 end
100113 end, { buffer = bufnr })
101114102102- -- bind yank behavior to y
103103- vim.keymap.set('n', 'yy', function()
115115+ -- bind yank behavior
116116+ vim.keymap.set("n", k.yank, function()
104117 local cursor = vim.api.nvim_win_get_cursor(win_id)[1]
105118 local yankIndex = line_yank_map[cursor]
106119 if yankIndex then
···112125 end, { buffer = bufnr })
113126114127 -- close popup keybinds
115115- local close_maps = { "<Esc>", "<C-c>", "q" }
116116- for _, map in ipairs(close_maps) do
117117- vim.keymap.set('n', map, function()
128128+ for _, map in ipairs(k.close) do
129129+ vim.keymap.set("n", map, function()
118130 vim.api.nvim_win_close(win_id, true)
119131 end, map_opts)
120132 end