···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 | `"+"` |
5959-| persist_type | string defining persistence type "memory", "sql", or "file" | `"memory"` |
5858+| persist_type | string defining persistence type "memory" or "sqlite" | `"memory"` |
6059| persist_path | string defining path for persistence file/db file | `"~/.local/share/nvim/lazy/yankbank-nvim"` (if installed with lazy) |
616062616363-If no separator is desired, pass in an empty string for sep:
6262+#### Example Configuration
6363+6464```lua
6565 config = function()
6666 require('yankbank').setup({
6767- max_entries = 12,
6767+ max_entries = 9,
6868 sep = "",
6969+ num_behavior = "prefix",
7070+ focus_gain_poll = true,
6971 keymaps = {
7072 navigation_next = "j",
7173 navigation_prev = "k",
7274 },
7375 num_behavior = "prefix",
7474- persist_type = "memory",
7676+ persist_type = "sqlite",
7777+ registers = {
7878+ yank_register = "+",
7979+ },
7580 })
7681 end,
7782```
78837979-8484+If no separator is desired, pass in an empty string for `sep`
80858186The 'num_behavior' option defines in-popup navigation behavior when hitting number keys.
8287- `num_behavior = "prefix"` works similar to traditional vim navigation with '3j' moving down 3 entries in the bank.
···8489 - Note: If 'max_entries' is a two-digit number, there will be a delay upon pressing numbers that prefix a valid entry.
85908691#### Persistence
8787-If persistence between sessions is desired, there is a choice between a sqlite database and a file.
8888-Both file and sqlite will (by default) create a persistent store for recent yanks in the plugin root directory.
8989-File-based persistence requires no added dependencies, but to utilize sqlite, `"kkharji/sqlite.lua"` must be added as a dependency in your config:
9292+If persistence between sessions is desired, sqlite.lua will be used to create a persistent store for recent yanks in the plugin root directory.
9393+To utilize sqlite persistence, `"kkharji/sqlite.lua"` must be added as a dependency in your config, and `persist_type` must be set to `"sqlite"`:
90949195```lua
9296-- lazy
···9599 dependencies = "kkharji/sqlite.lua",
96100 config = function()
97101 require('yankbank').setup({
102102+ -- other options...
98103 persist_type = "sqlite"
9999- persist_path = "/tmp/yankbank.db",
100104 })
101105 end,
102106}
103107```
104108109109+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`)
110110+105111## Usage
106112107113The 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.
···118124- Polling on unnamedplus register to populate bank in more intuitive manner (could be enabled as option)
119125- nvim-cmp integration
120126- fzf integration
121121-- Setup options configuring which registers are included
127127+- telescope integration
122128123129## Alternatives
124130
+152
doc/yankbank-nvim.txt
···11+*yankbank-nvim.txt* For Neovim >= 0.7.0 Last change: 2024 June 14
22+33+==============================================================================
44+Table of Contents *yankbank-nvim-table-of-contents*
55+66+1. YankBank |yankbank-nvim-yankbank|
77+ - What it Does |yankbank-nvim-yankbank-what-it-does|
88+ - Installation and Setup |yankbank-nvim-yankbank-installation-and-setup|
99+ - Usage |yankbank-nvim-yankbank-usage|
1010+ - Potential Improvements |yankbank-nvim-yankbank-potential-improvements|
1111+ - Alternatives |yankbank-nvim-yankbank-alternatives|
1212+2. Links |yankbank-nvim-links|
1313+1414+==============================================================================
1515+1. YankBank *yankbank-nvim-yankbank*
1616+1717+A Neovim plugin for keeping track of more recent yanks and deletions and
1818+exposing them in a quick access menu.
1919+2020+2121+WHAT IT DOES *yankbank-nvim-yankbank-what-it-does*
2222+2323+YankBank stores the N recent yanks into the unnamed register (“), then
2424+populates a popup window with these recent yanks, allowing for quick access to
2525+recent yank history. Upon opening the popup menu, the current contents of the
2626+unnamedplus (+) register are also added to the menu (if they are different from
2727+the current contents of the unnamed register).
2828+2929+Choosing an entry from the menu (by hitting enter) will paste it into the
3030+currently open buffer at the cursor position.
3131+3232+3333+SCREENSHOTS ~
3434+3535+The menu is specific to the current session, and will only contain the contents
3636+of the current unnamedplus register upon opening in a completely new session.
3737+It will be populated further for each yank or deletion in that session.
3838+3939+4040+INSTALLATION AND SETUP *yankbank-nvim-yankbank-installation-and-setup*
4141+4242+Lazy:
4343+4444+>lua
4545+ {
4646+ "ptdewey/yankbank-nvim",
4747+ config = function()
4848+ require('yankbank').setup()
4949+ end,
5050+ }
5151+<
5252+5353+Packer:
5454+5555+>lua
5656+ use {
5757+ 'ptdewey/yankbank-nvim',
5858+ config = function()
5959+ require('yankbank').setup()
6060+ end,
6161+ }
6262+<
6363+6464+6565+SETUP OPTIONS ~
6666+6767+The setup function also supports taking in a table of options: | Option | Type
6868+| Default |
6969+|————-|——————————————–|—————-|
7070+| max_entries | integer number of entries to show in popup | `10` | | sep |
7171+string separator to show between table entries | `"-----"` | | keymaps | table
7272+containing keymap overrides | `{}` | | keymaps.navigation_next | string | `"j"`
7373+| | keymaps.navigation_prev | string | `"k"` | | keymaps.paste | string |
7474+`"<CR>"` | | keymaps.yank | string | `"yy"` | | keymaps.close | table of
7575+strings | `{ "<Esc>", "<C-c>", "q" }` | | num_behavior | string defining jump
7676+behavior "prefix" or "jump" | `"prefix"` | | focus_gain_poll | boolean | `nil`
7777+| | registers | table container for register overrides | `{ }` | |
7878+registers.yank_register | default register to yank from popup to | `"+"` |
7979+8080+8181+EXAMPLE CONFIGURATION
8282+8383+>lua
8484+ config = function()
8585+ require('yankbank').setup({
8686+ max_entries = 9,
8787+ sep = "",
8888+ num_behavior = "prefix",
8989+ focus_gain_poll = true,
9090+ keymaps = {
9191+ navigation_next = "j",
9292+ navigation_prev = "k",
9393+ },
9494+ registers = {
9595+ yank_register = "+",
9696+ },
9797+ })
9898+ end,
9999+<
100100+101101+If no separator is desired, pass in an empty string for `sep`
102102+103103+The 'num_behavior' option defines in-popup navigation behavior when hitting
104104+number keys. - `num_behavior = "prefix"` works similar to traditional vim
105105+navigation with '3j' moving down 3 entries in the bank. - `num_behavior =
106106+"jump"` jumps to entry matching the pressed number key (i.e. '3' jumps to
107107+entry 3) - Note: If 'max_entries' is a two-digit number, there will be a delay
108108+upon pressing numbers that prefix a valid entry.
109109+110110+The 'focus_gain_poll' option allows for enabling an additional autocommand that
111111+watches for focus gains (refocusing Neovim window), and checks for changes in
112112+the unnamedplus ('+') register, adding to yankbank when new contents are found.
113113+This allows for automatically adding text copied from other sources (like a
114114+browser) to the yankbank without the bank opening trigger. Off by default, but
115115+I highly recommend enabling it (`focus_gain_poll = true`)
116116+117117+118118+USAGE *yankbank-nvim-yankbank-usage*
119119+120120+The popup menu can be opened with the command:`:YankBank`, an entry is pasted
121121+at the current cursor position by hitting enter, and the menu can be closed by
122122+hitting escape, ctrl-c, or q. An entry from the menu can also be yanked into
123123+the unnamedplus register by hitting yy.
124124+125125+I would personally also recommend setting a keybind to open the menu.
126126+127127+>lua
128128+ -- map to '<leader>y'
129129+ vim.keymap.set("n", "<leader>y", "<cmd>YankBank<CR>", { noremap = true })
130130+<
131131+132132+133133+POTENTIAL IMPROVEMENTS *yankbank-nvim-yankbank-potential-improvements*
134134+135135+- Persistence between sessions (through either sqlite database or just a file)
136136+- nvim-cmp integration
137137+- fzf integration
138138+139139+140140+ALTERNATIVES *yankbank-nvim-yankbank-alternatives*
141141+142142+- nvim-neoclip <https://github.com/AckslD/nvim-neoclip.lua>
143143+- yanky.nvim <https://github.com/gbprod/yanky.nvim>
144144+145145+==============================================================================
146146+2. Links *yankbank-nvim-links*
147147+148148+1. *YankBank popup window zoomed*: assets/screenshot-2.png
149149+150150+Generated by panvimdoc <https://github.com/kdheepak/panvimdoc>
151151+152152+vim:tw=78:ts=8:noet:ft=help:norl:
+31-8
lua/yankbank/clipboard.lua
···1313 -- avoid adding empty strings
1414 -- TODO: could block adding single characters here
1515 if text == "" or text == " " or text == "\n" then
1616+ -- if text == "" and text == " " and text == "\n" then -- NOTE: which is correct between and/or here?
1617 return
1718 end
18191920 -- do not update with duplicate values
2020- -- BUG: there seems to be some issues here when trying to add on pipup open
2121 for _, entry in ipairs(yanks) do
2222 if entry == text then
2323 return
···3636 persistence.add_entry(text, reg_type, opts)
3737end
38383939--- TODO: autocmd for focus gained (check system clipboard?)
4040-4139-- autocommand to listen for yank events
4240---@param yanks table
4341---@param reg_types table
···4745 callback = function()
4846 -- get register information
4947 local rn = vim.v.event.regname
5050- -- local reg_type = vim.fn.getregtype("+")
51485249 -- check changes wwere made to default register
5353- if vim.v.event.regname == "" or vim.v.event.regname == "+" then
5050+ if rn == "" or rn == "+" then
5451 local reg_type = vim.fn.getregtype(rn)
5555- local yanked_text = vim.fn.getreg(rn)
5656- if #yanked_text <= 1 then
5252+ local yank_text = vim.fn.getreg(rn)
5353+5454+ if not yank_text or type(yank_text) ~= "string" then
5755 return
5856 end
5959- M.add_yank(yanks, reg_types, yanked_text, reg_type, opts)
5757+5858+ if #yank_text <= 1 then
5959+ return
6060+ end
6161+ M.add_yank(yanks, reg_types, yank_text, reg_type, opts.max_entries)
6062 end
6163 end,
6264 })
6565+6666+ -- poll registers when vim is focused (check for new clipboard activity)
6767+ if opts.focus_gain_poll == true then
6868+ vim.api.nvim_create_autocmd("FocusGained", {
6969+ callback = function()
7070+ -- get register information
7171+ local reg_type = vim.fn.getregtype("+")
7272+ local yank_text = vim.fn.getreg("+")
7373+7474+ if not yank_text or type(yank_text) ~= "string" then
7575+ return
7676+ end
7777+7878+ if string.len(yank_text) <= 1 then
7979+ return
8080+ end
8181+8282+ M.add_yank(yanks, reg_types, yank_text, reg_type, opts.max_entries)
8383+ end,
8484+ })
8585+ end
6386end
64876588return M
+15-8
lua/yankbank/init.lua
···99local yanks = {}
1010local reg_types = {}
11111212--- YANKS = {}
1313--- REG_TYPES = {}
1414-1515-local plugin_path = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/") or "./"
1616-1712-- default plugin options
1813local default_opts = {
1914 max_entries = 10,
2015 sep = "-----",
1616+ focus_gain_poll = false,
1717+ num_behavior = "prefix",
1818+ registers = {
1919+ yank_register = "+",
2020+ },
2121 persist_type = "memory",
2222- persist_path = plugin_path .. "bank.txt",
2222+ keymaps = {},
2323}
24242525+local plugin_path = debug.getinfo(1).source:sub(2):match("(.*/).*/.*/") or "./"
2626+2527--- wrapper function for main plugin functionality
2628---@param opts table
2729--- TODO: read from persistent database if sql persist is set (allow multi-session sync)
2830local function show_yank_bank(opts)
2929- -- create and fill buffer
3131+ -- Parse command arguments directly if args are provided as a string
3232+ opts = opts or default_opts
3333+3434+ -- initialize buffer and populate bank
3035 local bufnr, display_lines, line_yank_map = menu.create_and_fill_buffer(yanks, reg_types, opts)
31363237 -- handle empty bank case
···3439 return
3540 end
36414242+ -- open window and set keybinds
3743 local win_id = menu.open_window(bufnr, display_lines)
3844 menu.set_keymaps(win_id, bufnr, yanks, reg_types, line_yank_map, opts)
3945end
···4248---@param opts table?
4349function M.setup(opts)
4450 -- merge opts with default options table
4545- opts = vim.tbl_deep_extend("force", default_opts, opts or {})
5151+ -- opts = vim.tbl_deep_extend("force", default_opts, opts or {})
5252+ opts = opts or default_opts
46534754 -- enable persistence based on opts (needs to be called before autocmd setup)
4855 yanks, reg_types = persistence.setup(opts)
+2-1
lua/yankbank/menu.lua
···112112 local k = vim.tbl_deep_extend("force", default_keymaps, opts.keymaps or {})
113113114114 -- merge default and options keymap tables
115115- opts.registers = vim.tbl_deep_extend("force", default_registers, opts.registers or {})
115115+ opts.registers =
116116+ vim.tbl_deep_extend("force", default_registers, opts.registers or {})
116117117118 -- check table for number behavior option (prefix or jump, default to prefix)
118119 opts.num_behavior = opts.num_behavior or "prefix"
+1
lua/yankbank/persistence/sql.lua
···6969function M.setup(opts)
7070 max_entries = opts.max_entries
71717272+ -- TODO: move database into plugin directory instead to allow easier uninstall
7273 if vim.fn.isdirectory(dbdir) == 0 then
7374 vim.fn.mkdir(dbdir, "p")
7475 end