Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay with vim.opt.clipboard = "unnamedplus" #176

Open
xzbdmw opened this issue May 16, 2024 · 1 comment
Open

Delay with vim.opt.clipboard = "unnamedplus" #176

xzbdmw opened this issue May 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@xzbdmw
Copy link

xzbdmw commented May 16, 2024

local root = vim.fn.fnamemodify("./.repro", ":p")

_G.Time = function(start, msg)
    msg = msg or ""
    local duration = 0.000001 * (vim.loop.hrtime() - start)
    -- __AUTO_GENERATED_PRINT_VAR_START__
    print(msg .. [==[duration:]==], vim.inspect(duration)) -- __AUTO_GENERATED_PRINT_VAR_END__
end
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "--single-branch",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
    -- do not remove the colorscheme!
    "folke/tokyonight.nvim",
    -- add any other pugins here
    {
        "gbprod/yanky.nvim",
        -- enabled = false,
        keys = {
            { "y", "<Plug>(YankyYank)", mode = { "n", "x" } },

            { "<leader>p", "<Plug>(YankyPreviousEntry)" },
            { "<leader>n", "<Plug>(YankyNextEntry)" },

            {
                "p",
                function()
                    YANK = vim.uv.hrtime()

                    return "<Plug>(YankyPutAfter)"
                end,
                expr = true,
            },
            { "P", "<Plug>(YankyPutBefore)" },

            { "gp", "<Plug>(YankyGPutAfter)", mode = { "n", "x" } },
            { "gP", "<Plug>(YankyGPutBefore)", mode = { "n", "x" } },

            -- visual mode paste
            { "p", "<Plug>(YankyPutBefore)", { desc = "Paste without copying replaced text" }, mode = { "x" } },
            { "<D-c>", "<Plug>(YankyYank)", mode = { "n", "v", "i" } },

            -- force paste the same line
            {
                "<leader>P",
                function()
                    YANK = vim.uv.hrtime()
                    return "<Plug>(YankyPutAfterCharwiseJoined)"
                end,
                mode = { "n", "x" },
                expr = true,
            },

            -- text object
            {
                "[p",
                function()
                    require("yanky.textobj").last_put()
                end,
                mode = { "x", "o" },
            },
        },
        lazy = false,
        opts = {
            ring = {
                history_length = 10,
                storage = "shada",
                storage_path = vim.fn.stdpath("data") .. "/databases/yanky.db", -- Only for sqlite storage
                sync_with_numbered_registers = true,
                cancel_event = "update",
                ignore_registers = { "_" },
                update_register_on_cycle = false,
            },
            picker = {
                select = {
                    action = nil, -- nil to use default put action
                },
                telescope = {
                    use_default_mappings = true, -- if default mappings should be used
                    mappings = nil, -- nil to use default mappings or no mappings (see `use_default_mappings`)
                },
            },
            system_clipboard = {
                sync_with_ring = false,
            },
            highlight = {
                on_put = true,
                on_yank = true,
                timer = 400,
            },
            preserve_cursor_position = {
                enabled = true,
            },
            textobj = {
                enabled = true,
            },
        },
    },
}
vim.opt.clipboard = "unnamedplus" -- Sync with system clipboard
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

-- add anything else here
-- vim.opt.termguicolors = true
-- do not remove the colorscheme!
vim.cmd([[colorscheme tokyonight]])
vim.api.nvim_create_autocmd("TextChanged", {
    callback = function()
        Time(YANK)
    end,
})
  1. touch ~/.config/nvim/repro.lua
  2. nvim -u ~/.config/nvim/repro.lua ~/.config/nvim/repro.lua
  3. yy
  4. p
  5. see the delay is 60ms(macos 14.2 m1 pro), for (YankyPutAfterCharwiseJoined) delay is 140ms.
  6. I test the code and everytime call setreg there is a 20ms cost, if I disable this plugin ,using
 vim.keymap.set("n", "p", function()
    YANK = vim.uv.hrtime()
    return "p"
end, { expr = true })

, duration is 13ms

@gbprod
Copy link
Owner

gbprod commented May 22, 2024

Intersting issue, I have to make some tests.

@gbprod gbprod added the bug Something isn't working label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants