ojroques / nvim-osc52

A Neovim plugin to copy text through SSH with OSC52
BSD 2-Clause "Simplified" License
341 stars 12 forks source link

Why is the first yank after opening NVIM 0 characters? #20

Open mkdir700 opened 1 year ago

mkdir700 commented 1 year ago

Why is the first yank after opening NVIM 0 bytes?

The video demonstrated that the first copy had 0 characters, while the second copy had 175 characters.

https://github.com/ojroques/nvim-osc52/assets/56359329/6e7a714b-2acc-4726-9111-5255d34c1481

thank you, I love this plugin.

ojroques commented 1 year ago

Hello, Could you share your config and your neovim version ?

mkdir700 commented 1 year ago

I fully used the configuration in README.MD.

I added a hotkey lvim.builtin.which_key.vmappings["y"], which is available after the first launch, while the y key is not.

{
    "ojroques/nvim-osc52",
    config = function()
        lvim.builtin.which_key.vmappings["y"] = { require("osc52").copy_visual, "Copy to clipboard(Remote)" }
        local function copy()
            if vim.v.event.operator == "y" and vim.v.event.regname == "+" then
                require("osc52").copy_register("+")
            end
        end

        vim.api.nvim_create_autocmd("TextYankPost", { callback = copy })
    end,
}
    local function copy(lines, _)
        require("osc52").copy(table.concat(lines, "\n"))
    end

    local function paste()
        return { vim.fn.split(vim.fn.getreg(""), "\n"), vim.fn.getregtype("") }
    end

    vim.g.clipboard = {
        name = "osc52",
        copy = { ["+"] = copy, ["*"] = copy },
        paste = { ["+"] = paste, ["*"] = paste },
    }
mkdir700 commented 1 year ago

My preliminary judgment is that it is related to the following configuration. When I comment out the following code, it can be used normally, but there will be a "Register "+" is empty" warning when pasting.

local function copy()
    if vim.v.event.operator == "y" and vim.v.event.regname == "+" then
        require("osc52").copy_register("+")
    end
end

vim.api.nvim_create_autocmd("TextYankPost", { callback = copy })
ojroques commented 1 year ago

You have two options, try to choose only one of the two:

  1. Either you keep that part:

    "ojroques/nvim-osc52",
    config = function()
        lvim.builtin.which_key.vmappings["y"] = { require("osc52").copy_visual, "Copy to clipboard(Remote)" }
        local function copy()
            if vim.v.event.operator == "y" and vim.v.event.regname == "+" then
                require("osc52").copy_register("+")
            end
        end
    
        vim.api.nvim_create_autocmd("TextYankPost", { callback = copy })
    end,

    If I understood correctly what you're trying to achieve, y in visual mode will copy the text as well as "+y in normal mode. Change the '+' to '' in the above code so that y will copy to clipboard in normal mode.

  2. Or you keep that part:

    local function copy(lines, _)
        require("osc52").copy(table.concat(lines, "\n"))
    end
    
    local function paste()
        return { vim.fn.split(vim.fn.getreg(""), "\n"), vim.fn.getregtype("") }
    end
    
    vim.g.clipboard = {
        name = "osc52",
        copy = { ["+"] = copy, ["*"] = copy },
        paste = { ["+"] = paste, ["*"] = paste },
    }

    Then in normal and visual mode "+y will copy to clipboard using the plugin and it's Neovim itself that will call the plugin.

mkdir700 commented 1 year ago

Thank you for your reply, but it doesn't work for me.

There are three pictures about register data at different times.

  1. The first time is the register when the editor is just opened.
image
  1. after the first press of yy.
image
  1. after pressing yy again. "ojroques/nvim-osc52", is the content I copied.
image

In addition, I also found that I don't need to fully press yy. Just pressing y once to enter operation mode and then returning to normal mode, the copy function works normally again.