AckslD / nvim-neoclip.lua

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

continuous_sync makes :global command really slow #121

Open arnevm123 opened 2 months ago

arnevm123 commented 2 months ago

When trying to execute a :g (:global) command with continuous_sync enabled this makes the command noticeable slower.

How to reproduce this: Enable continuous_sync, open a random file and try a global command. Example of this would be :g/^$/d to remove all empty lines in a file (a file with 20-30 empty lines already has a noticeable delay on my machine). Toggle the continuous sync on and off to see the difference in speed.

Minimal config to test this:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable", -- latest stable release
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)
-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

require("lazy").setup({
    {
        "AckslD/nvim-neoclip.lua",
        dependencies = {
            { "kkharji/sqlite.lua", module = "sqlite" },
            { "nvim-telescope/telescope.nvim" },
        },
        config = function()
            require("neoclip").setup({
                enable_persistent_history = true,
                -- set to false to have fast global commands again
                continuous_sync = true,
                db_path = vim.fn.stdpath("data") .. "/neoclip/neoclip.sqlite3",
            })
        end,
        lazy = false,
    },
})

Not sure if this would be an easy fix, but I have a workaround: Only push the database on focus lost:

autocmd("FocusLost", {
    group = augroup("NeoClipFocus", {}),
    pattern = "*",
    callback = function()
        require("neoclip").db_push()
    end,
})

FocusGained does not work when using autoread, so I sync whenever I trigger the telescope menu:

:lua require('neoclip').db_pull()<CR>:Telescope neoclip<CR>
arnevm123 commented 1 month ago

Update:

This is a better workaround:

vim.api.nvim_create_autocmd("FocusLost", {
    group = vim.api.nvim_create_augroup("NeoClipFocusLost", {}),
    pattern = "*",
    callback = function()
        require("neoclip").db_push()
    end,
})

vim.api.nvim_create_autocmd("FocusGained", {
    group = vim.api.nvim_create_augroup("NeoClipFocusGained", {}),
    pattern = "*",
    callback = function()
        require("nio").run(function()
            require("nio").sleep(200)
            require("neoclip").db_pull()
        end)
    end,
})
AckslD commented 1 month ago

Hi @arnevm123, this is really great! I have been meaning to reply to this but haven't had time yet