···55## What it Does
6677YankBank stores the N recent yanks into the unnamed register ("), then populates a popup window with these recent yanks, allowing for quick access to recent yank history.
88-Upon opening the popup menu, the current contents of the unnamedplus (+) register are also added to the menu (if they are different than the current contents of the unnamed register).
88+Upon opening the popup menu, the current contents of the unnamedplus (+) register are also added to the menu (if they are different from the current contents of the unnamed register).
991010Choosing an entry from the menu (by hitting enter) will paste it into the currently open buffer at the cursor position.
11111212### Screenshots
1313-1414-
15131614
1715···5452| keymaps.yank | string | `"yy"` |
5553| keymaps.close | table of strings | `{ "<Esc>", "<C-c>", "q" }` |
5654| num_behavior | string defining jump behavior "prefix" or "jump" | `"prefix"` |
5555+| focus_gain_poll | boolean | `nil` |
5756| registers | table container for register overrides | `{ }` |
5857| registers.yank_register | default register to yank from popup to | `"+"` |
595860596161-If no separator is desired, pass in an empty string for sep:
6060+#### Example Configuration
6161+6262```lua
6363 config = function()
6464 require('yankbank').setup({
6565- max_entries = 12,
6565+ max_entries = 9,
6666 sep = "",
6767+ num_behavior = "prefix",
6868+ focus_gain_poll = true,
6769 keymaps = {
6870 navigation_next = "j",
6971 navigation_prev = "k",
7072 },
7171- num_behavior = "prefix",
7373+ registers = {
7474+ yank_register = "+",
7575+ },
7276 })
7377 end,
7478```
75798080+If no separator is desired, pass in an empty string for `sep`
8181+7682The 'num_behavior' option defines in-popup navigation behavior when hitting number keys.
7783- `num_behavior = "prefix"` works similar to traditional vim navigation with '3j' moving down 3 entries in the bank.
7884- `num_behavior = "jump"` jumps to entry matching the pressed number key (i.e. '3' jumps to entry 3)
7985 - Note: If 'max_entries' is a two-digit number, there will be a delay upon pressing numbers that prefix a valid entry.
80868787+8888+The 'focus_gain_poll' option allows for enabling an additional autocommand that watches for focus gains (refocusing Neovim window), and checks for changes in the unnamedplus ('+') register, adding to yankbank when new contents are found. This allows for automatically adding text copied from other sources (like a browser) to the yankbank without the bank opening trigger. Off by default, but I highly recommend enabling it (`focus_gain_poll = true`)
81898290## Usage
8391···94102## Potential Improvements
9510396104- Persistence between sessions (through either sqlite database or just a file)
9797-- Polling on unnamedplus register to populate bank in more intuitive manner (could be enabled as option)
98105- nvim-cmp integration
99106- fzf integration
100100-- Setup options configuring which registers are included
101107102108## Alternatives
103109
+28-6
lua/yankbank/clipboard.lua
···2020 end
2121end
22222323--- autocommand to listen for yank events
2424-function M.setup_yank_autocmd(yanks, reg_types, max_entries)
2323+-- set up plugin autocommands
2424+-- TODO: make augroup
2525+function M.setup_yank_autocmd(yanks, reg_types, opts)
2626+ -- autocommand to listen for yank events
2527 vim.api.nvim_create_autocmd("TextYankPost", {
2628 callback = function()
2729 -- TODO: this function can be expanded to incorporate other registers
···3436 local rn = vim.v.event.regname
3537 local reg_type = vim.fn.getregtype('"')
36383737- -- check changes wwere made to default register
3939+ -- check if changes were made to default register
3840 if vim.v.event.regname == "" then
3939- local yanked_text = vim.fn.getreg(rn)
4141+ local yank = vim.fn.getreg(rn)
40424143 -- NOTE: this only blocks adding to list if something else is in plus register
4242- if string.len(yanked_text) <= 1 then
4444+ if string.len(yank) <= 1 then
4345 return
4446 end
45474646- M.add_yank(yanks, reg_types, yanked_text, reg_type, max_entries)
4848+ M.add_yank(yanks, reg_types, yank, reg_type, opts.max_entries)
4749 end
4850 end,
4951 })
5252+5353+ -- poll registers when vim is focused (check for new clipboard activity)
5454+ if opts.focus_gain_poll and opts.focus_gain_poll == true then
5555+ vim.api.nvim_create_autocmd("FocusGained", {
5656+ callback = function()
5757+ -- get register information
5858+ local reg_type = vim.fn.getregtype("+")
5959+ local yank = vim.fn.getreg("+")
6060+6161+ -- NOTE: do not add yanks of 1 or 0 characters
6262+ if string.len(yank) <= 1 then
6363+ return
6464+ end
6565+6666+ M.add_yank(yanks, reg_types, yank, reg_type, opts.max_entries)
6767+ end,
6868+ })
6969+ end
7070+7171+ -- TODO: focus lost hook?
5072end
51735274return M
···104104 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {})
105105106106 -- merge default and options keymap tables
107107- opts.registers = vim.tbl_deep_extend("force", default_registers, opts.registers or {})
107107+ opts.registers =
108108+ vim.tbl_deep_extend("force", default_registers, opts.registers or {})
108109109110 -- check table for number behavior option (prefix or jump, default to prefix)
110111 opts.num_behavior = opts.num_behavior or "prefix"