MagicDuck / grug-far.nvim

Find And Replace plugin for neovim
MIT License
677 stars 18 forks source link

feature: make it easier to paste lines into the ui #238

Closed mikavilpas closed 1 week ago

mikavilpas commented 2 weeks ago

Hi again! I have a habit of copying lines and pasting them with yy and p. In the grug-far ui, it seems that pasting a line into the Replace section will actually paste it below it, causing a bit of hassle undoing the changes. Here's a demo:

https://github.com/user-attachments/assets/d84010c5-3cd9-4a21-87db-fc2b8faaa131

In this demo, I copy the Search section and want to paste it, which causes the text to go into the Files Filter section. When I do it later in the clip, I use y$ to leave out the trailing newline (I guess) - then it works.

Would it be possible to improve this a bit? I try to do it smarter, but I am clearly not big brained enough 😄

MagicDuck commented 1 week ago

hi @mikavilpas ,

So I've struggled with this issue in when I was working on it quite a bit, and also fiddled with it today, but I was not able to find a perfect solution 😢 .

Observations:

  1. When pasting with p, p means "paste below this line" so what is happening is technically correct. I could not find any combination of extmark gravity that would change that.
  2. When pasting with P, P means "paste above this line" and that works because the input extmark gravity is left, only you get a newline after your line
  3. Pasting with vp or Vp <--- this is now fixed by linked PR
  4. copy with Y (you need to move to the start of the input, for example with 0) and pasting with p or P works, same as your example.

So in summary use approach from observation 3 or 4 above! Best we can do atm unless somebody else comes up with something better... Also, with the fix in observation (3), it technically behaves vim-like...

mikavilpas commented 1 week ago

It's much better now! Thanks!

I wonder if it's possible for me to map p to vP in grug-far buffers only? If this "grug level solution" works then it would solve all my issues 😄

MagicDuck commented 1 week ago

@mikavilpas I had another idea of how to address this today 😛 It's slightly hacky in it's implementation but it seems to work beautifully. Check latest, p, P and o should just work ™️ ! When pasting with extra newline into an empty input it should smartly remove the newline.

mikavilpas commented 1 week ago

It's really nice now 👍🏻

MagicDuck commented 1 week ago

great! Thanks for confirming! I'll close the issue now but feel free to reopen if you see any problems 😄