gbprod / yanky.nvim

Improved Yank and Put functionalities for Neovim
Do What The F*ck You Want To Public License
850 stars 21 forks source link

feature request: 'smart pasting' and/or 'pre_paste_hook' option. #192

Open qtyra opened 1 month ago

qtyra commented 1 month ago

I couldn't find a better place to suggest this since this plugin aims to replace the default bindings, creating a separate plugin would be a hassle. Consider this simple file ('*' represents the cursor position):

text1
text2
text3

text4
text5
text6

text7
text8
*ext9

AFAIK, there's no easy way to move the last paragraph to the top or vice versa with the correct position of empty lines. Here are some solutions I've considered:

Please note:

So i thought this plugin could implement one or both of these solutions:

  1. Handle these special cases without changing any register content and include options to enable or disable this behavior. The algorithm seems straightforward to me, a similar procedure would apply for words, just replacing lines by spaces:

    1. Check if the text to be pasted contains a empty line at the end/start.
    2. Check if we are at the start or end of the buffer.
    3. Put and remove an empty line after/before the paragraph.
  2. Add a simple pre_paste_hook option, customizable with a function that receives the text to be pasted and the type of pasting as input.

Let me know what you think!

gbprod commented 1 month ago

Hi!

Thanks for this feedback.

There is already something like a pre_paste_hook, it's called wrappers (it's something like "middlewares"). I never took the time to document this but this is what I use to create Special put mappings.

You can see here how to register mappings with wrapper and here how to create a wrapper.

Let me know if this feature allows you to create your hook ;)