AckslD / nvim-neoclip.lua

Clipboard manager neovim plugin with telescope integration
931 stars 19 forks source link

History Not Always Remembered - Solved #113

Closed bertradio closed 5 months ago

bertradio commented 6 months ago

I am trying to use Neoclip.nvim to retain the contents of the clipboard. It works well remembering within a nvim session. But it does not always remember the history even though my settings are:

  history = 1000,
  enable_persistent_history = true,
  length_limit = 1048576,
  continuous_sync = false,

Sometimes when I re-load nvim it has the clipboards from the past session or two. But often it has nothing. The same thing happens whether continuous_sync is true or false.

Am I misunderstanding what it is supposed to do?

AckslD commented 6 months ago

Hi @bertradio! I think you're understanding the feature correctly but I'm not sure why it's not working. Does this happen when you have one session at the time or when there's more than one in parallel?

bertradio commented 6 months ago

When there is a single session. Am I correct that neoclip should remember everything until I reach the 1000 limit?

bertradio commented 6 months ago

Here is my config.



-- Created: 12/06/23

-- local functions for filtering out of lines that are all whitespace
local function is_whitespace(line)
  return vim.fn.match(line, [[^\s*$]]) ~= -1
end
local function all(tbl, check)
  for _, entry in ipairs(tbl) do
    if not check(entry) then
      return false
    end
  end
  return true
end

return {
  'AckslD/nvim-neoclip.lua',
  dependencies = {
    { 'kkharji/sqlite.lua', module = 'sqlite' },
    'nvim-telescope/telescope.nvim',
  },
  config = function()
    require('neoclip').setup({
      -- the following lines set up so clips are stored from session to session
      history = 1000,
      enable_persistent_history = true,
      length_limit = 1048576,
      continuous_sync = false,
      db_path = vim.fn.stdpath('data') .. '/databases/neoclip.sqlite3',
      -- don't store entries that are all whitespace - see fns above
      filter = function(data)
        return not all(data.event.regcontents, is_whitespace)
      end,
      --stylua: ignore
      keys = {
        telescope = {
          i = {
            delete       = "<c-d>", -- delete an entry
            edit         = "<c-e>", -- edit an entry
            paste        = "<c-p>",
            paste_behind = "<c-k>",
            replay       = "<c-q>", -- replay a macro
            select       = "<cr>",
            custom       = {},
          },
          n = {
            --- It is possible to map to more than one key.
            -- paste = { 'p', '<c-p>' },
            delete       = "d",
            edit         = "e",
            paste        = "p",
            paste_behind = "P",
            replay       = "q",
            select       = "<cr>",
            custom       = {},
          },
        },
      },
    })
  end,
}```
bertradio commented 6 months ago

I'm using the nightly:

NVIM v0.10.0-dev-2048+g367e52cc7 Build type: Release LuaJIT 2.1.1703358377

bertradio commented 6 months ago

I did some more testing, using the DBviewer to see what was happening in the sqlite3 db. It turns out that neoclip is adding the entries correctly. But sometimes when I run Telescope neoclip all the entries are deleted. Is that the right command?

bertradio commented 6 months ago

I found the problem. I use lazy.nvim. I require the neoclip extension when I load telescope. If I lazy load neoclip this resolves the issue.

AckslD commented 5 months ago

I see, I wonder if anything can be done on neoclip to avoid this? So you had neoclip loaded when telescope is and now you load neoclip on startup instead? That you probably anyway want to record any yanks before telescope is loaded.

bertradio commented 5 months ago

I think it has to do with the fact that the order of loading modules in lazy.nvim is not consistent. So I needed to make sure that telescope was loaded before neoclip. I did this by lazy loading neoclip. Frankly I'm not sure what's going on. But now it works so I'm moving on to other things.