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

Modes behavior #37

Open
darkangel-ua opened this issue Jan 1, 2022 · 4 comments
Open

Modes behavior #37

darkangel-ua opened this issue Jan 1, 2022 · 4 comments

Comments

@darkangel-ua
Copy link

Hi!

First of all - thanks for such a great plugin!
I have some issues/misunderstandings:

  • when pasting in normal mode cursor doesn't move to the end of the pasted content like happens with regular 'p'
  • when trying to paste from telescope variant in insert mode I'm loosing insert mode after pasting and cursor appears somewhere in the middle of pasted content
  • when trying to paste from telescope variant in visual mode I'm loosing visual mode selection, and then paste in normal mode happens

Is this just me or it's designed like this?

@AckslD
Copy link
Owner

AckslD commented Jan 2, 2022

Hi @darkangel-ua! Thanks for reporting this. When trying it out myself it seems when pasting from telescopes insert mode the cursor ends up one character before the end but when pasting from normal mode it ends up at the end (only for single-line yanks). Is this the same as you experience? When pasting starting from a visual selection I can indeed see that it is lost.

I'm not really sure how one would fix this or even if the issue is with telescope or neoclip.

@YosefBayoude
Copy link

YosefBayoude commented Oct 25, 2024

When it comes to losing visual selection, I managed to find a workaround. I do it do it this way, when I assign it to my binding.

require("neoclip").setup({
	keys = {
		telescope = {
			i = {
				custom = {
					["<cr>"] = function(opts)
						local handlers = require("neoclip.handlers")
						if isVisualMode then
							vim.api.nvim_feedkeys("gv", "xn", false) -- reselect previous selection
						end
						handlers.paste(opts.entry, "p")
						isVisualMode = false
					end,
				},
			},
		},
	},
})

Basically, I do this by reselecting the previous selection.

@AckslD
Copy link
Owner

AckslD commented Dec 22, 2024

Thanks for sharing @YosefBayoude, where is isVisualMode set actually?

@YosefBayoude
Copy link

When calling the mapping. Here is the complete config:

return {
  "AckslD/nvim-neoclip.lua",
  dependencies = {
    { "kkharji/sqlite.lua", module = "sqlite" }, -- required for persistent history
    { "nvim-telescope/telescope.nvim" },
  },
  config = function()
    local isVisualMode = false
    require("neoclip").setup({
      enable_persistent_history = true,
      keys = {
        telescope = {
          i = {
            custom = {
              ["<cr>"] = function(opts)
                local handlers = require("neoclip.handlers")
                if isVisualMode then
                  vim.api.nvim_feedkeys("gv", "xn", false) -- reselect previous selection
                end
                handlers.paste(opts.entry, "p")
                isVisualMode = false
              end,
            },
          },
        },
      },
    })
    vim.keymap.set({ "v" }, "<leader>p", function()
      isVisualMode = true
      vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<esc>", true, false, true), "xn", false)
      vim.cmd("Telescope neoclip")
    end, { desc = "Clipboard history" })
    vim.keymap.set({ "n" }, "<leader>p", function() vim.cmd("Telescope neoclip") end, { desc = "Clipboard history" })
  end,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants