ggandor / leap-spooky.nvim

👻 Actions at a distance
The Unlicense
277 stars 7 forks source link

paste_on_remote_yank is not working, and please add an option to enable it for everything #9

Closed danielo515 closed 1 year ago

danielo515 commented 1 year ago

Hello. Thanks for experimenting with this idea for a plugin. My main use case 99% of the times is to bring some remote piece of code to the place I have the cursor, but I always have to do too many keystrokes because after yank, I have to manually paste, which is almost as much work as jumping there using normal motion, yank, c-o to get back and then paste. Will be cool to be able to enable paste_on_remote_yank for everything. And, I never got it working, not sure how it is supposed to be used, if you can explain I will be grateful.

farzadmf commented 1 year ago

+1 on this, I was trying it for 30 minutes, wondering why it's not working

al-ce commented 1 year ago

paste_on_remote_yank works fine for me on 748b261 with this setup and default leap bindings.

    config = function()
      require("leap-spooky").setup({
        paste_on_remote_yank = true,
      })
    end,

What's in your configs?

farzadmf commented 1 year ago

I'm on the same commit, using lazy.nvim, and this is what I have:

{
  'ggandor/leap-spooky.nvim',
  event = 'BufReadPost',
  dependencies = { 'leap.nvim' },
  opts = {
    paste_on_remote_yank = true,
  },
}
al-ce commented 1 year ago

Using your config worked for me as well. What's your leap config and what mappings are you using for spooky motions, and what Nvim version?

farzadmf commented 1 year ago

My nvim version is 0.8.3

My leap config is also very basic (I haven't set up its default mappings, and I want to use it in the context of spooky)

{
  'ggandor/leap.nvim',
  config = function()
    vim.api.nvim_set_hl(0, 'LeapBackdrop', { link = 'Comment' }) -- grey out search area
  end,
}

As for the mappings, I'm trying, for example, doing yrr, then the leap search (2 char, marker, jump). The line is indeed yanked, but it isn't pasted

danielo515 commented 1 year ago

This is my also very basic (IMO) config:

return {
  "ggandor/leap-spooky.nvim",
  requires = "ggandor/leap.nvim",
  config = function()
    require("leap-spooky").setup {
      affixes = {
        -- These will generate mappings for all native text objects, like:
        -- (ir|ar|iR|aR|im|am|iM|aM){obj}.
        -- E.g `darw` for delete a remote word
        -- Special line objects will also be added, by repeating the affixes.
        -- E.g. `yrr<leap>` and `ymm<leap>` will yank a line in the current
        -- window.
        -- You can also use 'rest' & 'move' as mnemonics.
        remote = { window = "r", cross_window = "R" },
        -- magnetic means you are going to move to the position where you are yanking
        magnetic = { window = "m", cross_window = "M" },
      },
      -- If this option is set to true, the yanked text will automatically be pasted
      -- at the cursor position if the unnamed register is in use.
      paste_on_remote_yank = true,
    }
  end,
}
farzadmf commented 1 year ago

Yeah, I think our setups are the same (if I'm not mistaken, the values you have for affixes are the defaults, and that's why I didn't add them, so I think, basically we have the same configuration. So confused as to why it works for you and not me 🤔

ggandor commented 1 year ago

@farzadmf Have you tried without lazy.nvim, calling setup manually?

taketwo commented 1 year ago

This feature used to work for me, but stopped at some point in the last couple of weeks. I've been making heavy changes in my config over this time (including migration to lazy.nvim). So after reading this thread I thought this may be due to lazy.nvim indeed. Turns out, the problem is the default register used for yanking. For some reason, Spooky pastes only if the target register is ":

https://github.com/ggandor/leap-spooky.nvim/blob/748b2614e859704d8004e86be97401c9f3e28e80/lua/leap-spooky.lua#L127-L128

As a part of my migration, I adopted this option from LazyVim:

https://github.com/LazyVim/LazyVim/blob/befa6c67a4387b0db4f8421d463f5d03f91dc829/lua/lazyvim/config/options.lua#L9

This changed my default yanking register to system clipboard (+) and thus broke Spooky paste.

ggandor commented 1 year ago

@taketwo Thanks, good catch!

For some reason, Spooky pastes only if the target register is "

That is because you never want to allow pasting right away if you use a non-default register - you usually use a named register to accumulate multiple selections, or store yanked stuff to be used later, after certain in-between operations. The thing I missed is that v.clipboard can actually change the value of the default register.

farzadmf commented 1 year ago

Thank you @ggandor for fixing this, I guess I had a similar setting somewhere because I am using system clipboard as well

taketwo commented 1 year ago

@ggandor Thanks for the explanation and the quick fix! (and the plugin itself, of course)

danielo515 commented 1 year ago

Yeah, I think our setups are the same (if I'm not mistaken, the values you have for affixes are the defaults, and that's why I didn't add them, so I think, basically we have the same configuration. So confused as to why it works for you and not me 🤔

Who says it works for me? I'm commenting here because it does not work for me either.

farzadmf commented 1 year ago

Who says it works for me? I'm commenting here because it does not work for me either.

Oops, sorry, I mixed up the usernames, and I thought you're the one that has it working.

But I think the recent change actually fixed the issue, and seems to be working for me

danielo515 commented 1 year ago

I can confirm that, after updating to 0bb68f0 it works for me. Thank you very much! Now I will be able to duplicate code much much faster.