local userregs = require("vim.userregs") -- Register name: "|" -- This register represents the full contents of the current buffer. -- Yank into it → saves the buffer. -- Put from it → replaces the buffer contents. local regname = "|" --- Reads the full contents of the current buffer as a list of lines. --- This is returned in the format expected by 'userregfunc'. --- @return table a 'put' dictionary with `lines`, `type`, and `additional_data` local function read_current_buffer() local bufnr = vim.api.nvim_get_current_buf() local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false) return { lines = lines, type = "V", -- linewise register additional_data = {}, } end --- Replaces the entire contents of the current buffer with the given content. --- Used when yanking into the "|" register. --- @param _ string -- register name (ignored here) --- @param content table -- dictionary with `lines` from yankreg_T local function write_current_buffer(_, content) local bufnr = vim.api.nvim_get_current_buf() vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, content.lines or {}) end -- Register the "|" register with the userregs framework userregs.register_handler(regname, { put = function(_) return read_current_buffer() end, yank = write_current_buffer, })